From 27a81ffc867bbbd198c81276d405bd729e27e645 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 9 Mar 2021 15:34:48 -0500 Subject: [PATCH 001/257] add initial version of a plugin loader interface (for pair styles) --- src/input.cpp | 10 ++++++ src/input.h | 1 + src/lammpsplugin.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++ src/lammpsplugin.h | 44 +++++++++++++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 src/lammpsplugin.cpp create mode 100644 src/lammpsplugin.h diff --git a/src/input.cpp b/src/input.cpp index df5cf0efbe..57ce64815d 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -29,6 +29,7 @@ #include "group.h" #include "improper.h" #include "kspace.h" +#include "lammpsplugin.h" #include "memory.h" #include "min.h" #include "modify.h" @@ -714,6 +715,7 @@ int Input::execute_command() else if (!strcmp(command,"include")) include(); else if (!strcmp(command,"jump")) jump(); else if (!strcmp(command,"label")) label(); + else if (!strcmp(command,"load_plugin")) load_plugin(); else if (!strcmp(command,"log")) log(); else if (!strcmp(command,"next")) next_command(); else if (!strcmp(command,"partition")) partition(); @@ -1029,6 +1031,14 @@ void Input::label() /* ---------------------------------------------------------------------- */ +void Input::load_plugin() +{ + if (narg != 1) error->all(FLERR,"Illegal load_plugin command"); + lammpsplugin_load(arg[0],lmp); +} + +/* ---------------------------------------------------------------------- */ + void Input::log() { if ((narg < 1) || (narg > 2)) error->all(FLERR,"Illegal log command"); diff --git a/src/input.h b/src/input.h index a86b10a686..3b7b6d79c7 100644 --- a/src/input.h +++ b/src/input.h @@ -79,6 +79,7 @@ class Input : protected Pointers { void include(); void jump(); void label(); + void load_plugin(); void log(); void next_command(); void partition(); diff --git a/src/lammpsplugin.cpp b/src/lammpsplugin.cpp new file mode 100644 index 0000000000..d3d409de41 --- /dev/null +++ b/src/lammpsplugin.cpp @@ -0,0 +1,76 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://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 "lammpsplugin.h" + +#include "error.h" +#include "force.h" +#include "lammps.h" +#include "modify.h" + + +#ifdef _WIN32 +#include +#else +#include +#endif + +namespace LAMMPS_NS +{ + + void lammpsplugin_load(const char *file, void *ptr) + { + LAMMPS *lmp = (LAMMPS *)ptr; +#if defined(WIN32) + utils::logmsg(lmp,"Loading of plugins not supported on Windows yet\n"); +#else + void *dso = dlopen(file,RTLD_NOW); + if (dso == nullptr) { + utils::logmesg(lmp,fmt::format("Loading of plugin from file {} failed: " + "{}", file, utils::getsyserror())); + return; + } + + void *initfunc = dlsym(dso,"lammpsplugin_init"); + if (initfunc == nullptr) { + dlclose(dso); + utils::logmesg(lmp,fmt::format("Symbol lookup failure in file {}",file)); + return; + } + ((lammpsplugin_initfunc)(initfunc))(ptr); +#endif + } + + void lammpsplugin_register(lammpsplugin_t *plugin, void *ptr) + { + LAMMPS *lmp = (LAMMPS *)ptr; + + if (plugin == nullptr) return; + if (plugin->version) + utils::logmesg(lmp,fmt::format("Loading: {}\n compiled for LAMMPS " + "version {} loaded into LAMMPS " + "version {}\n", plugin->info, + plugin->version, lmp->version)); + std::string pstyle = plugin->style; + if (pstyle == "pair") { + (*(lmp->force->pair_map))[plugin->name] = + (LAMMPS_NS::Force::PairCreator)plugin->creator; + } else { + utils::logmesg(lmp,fmt::format("Loading plugin for {} styles not " + "yet implemented\n", pstyle)); + } + } +} + + + diff --git a/src/lammpsplugin.h b/src/lammpsplugin.h new file mode 100644 index 0000000000..9784c456ee --- /dev/null +++ b/src/lammpsplugin.h @@ -0,0 +1,44 @@ +/* -*- 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_LAMMPSPLUGIN_H +#define LMP_LAMMPSPLUGIN_H + +#ifdef __cplusplus +extern "C" { +#endif + + typedef void *(lammpsplugin_factory)(void *); + typedef void (*lammpsplugin_initfunc)(void *); + + typedef struct { + const char *version; + const char *style; + const char *name; + const char *info; + lammpsplugin_factory *creator; + } lammpsplugin_t; + + void lammpsplugin_init(void *); + +#ifdef __cplusplus +} +#endif + +namespace LAMMPS_NS +{ + extern void lammpsplugin_load(const char *, void *); + extern void lammpsplugin_register(lammpsplugin_t *, void *); +} + +#endif From f0381b48ca95068b6c4ee222240607c4bf14f036 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 9 Mar 2021 15:50:27 -0500 Subject: [PATCH 002/257] add example for loading a pair style --- examples/plugins/Makefile | 17 ++ examples/plugins/morse2plugin.cpp | 29 +++ examples/plugins/pair_morse2.cpp | 359 ++++++++++++++++++++++++++++++ examples/plugins/pair_morse2.h | 70 ++++++ 4 files changed, 475 insertions(+) create mode 100644 examples/plugins/Makefile create mode 100644 examples/plugins/morse2plugin.cpp create mode 100644 examples/plugins/pair_morse2.cpp create mode 100644 examples/plugins/pair_morse2.h diff --git a/examples/plugins/Makefile b/examples/plugins/Makefile new file mode 100644 index 0000000000..0c4365dfd8 --- /dev/null +++ b/examples/plugins/Makefile @@ -0,0 +1,17 @@ +CXX=mpicxx +CXXFLAGS=-I../../src -Wall -O3 -fPIC +LD=$(CXX) -shared -rdynamic + +morse2plugin.so: morse2plugin.o pair_morse2.o + $(LD) -o $@ $^ + +.cpp.o: + $(CXX) -o $@ $(CXXFLAGS) -c $< + +pair_morse2.o: pair_morse2.cpp pair_morse2.h +morse2plugin.o: morse2plugin.cpp pair_morse2.h + +clean: + rm -f *~ *.so *.o log.lammps + + diff --git a/examples/plugins/morse2plugin.cpp b/examples/plugins/morse2plugin.cpp new file mode 100644 index 0000000000..bb21f3da95 --- /dev/null +++ b/examples/plugins/morse2plugin.cpp @@ -0,0 +1,29 @@ + +#include "lammpsplugin.h" + +#include "lammps.h" +#include "version.h" + +#include + +#include "pair_morse2.h" + +using namespace LAMMPS_NS; + +static Pair *morse2creator(LAMMPS *lmp) +{ + return new PairMorse2(lmp); +} + +static lammpsplugin_t plugin; +void lammpsplugin_init(void *lmp) +{ + memset(&plugin,0,sizeof(lammpsplugin_t)); + plugin.version = LAMMPS_VERSION; + plugin.style = "pair"; + plugin.name = "morse2"; + plugin.info = "Morse2 variant pair style v1.0 by Axel Kohlmeyer"; + plugin.creator = (lammpsplugin_factory *) &morse2creator; + + lammpsplugin_register(&plugin, (LAMMPS *)lmp); +} diff --git a/examples/plugins/pair_morse2.cpp b/examples/plugins/pair_morse2.cpp new file mode 100644 index 0000000000..a235ad297c --- /dev/null +++ b/examples/plugins/pair_morse2.cpp @@ -0,0 +1,359 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://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_morse2.h" + +#include +#include +#include "atom.h" +#include "comm.h" +#include "force.h" +#include "neigh_list.h" +#include "memory.h" +#include "error.h" + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +PairMorse2::PairMorse2(LAMMPS *lmp) : Pair(lmp) +{ + writedata = 1; +} + +/* ---------------------------------------------------------------------- */ + +PairMorse2::~PairMorse2() +{ + if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); + + memory->destroy(cut); + memory->destroy(d0); + memory->destroy(alpha); + memory->destroy(r0); + memory->destroy(morse1); + memory->destroy(offset); + } +} + +/* ---------------------------------------------------------------------- */ + +void PairMorse2::compute(int eflag, int vflag) +{ + int i,j,ii,jj,inum,jnum,itype,jtype; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,r,dr,dexp,factor_lj; + int *ilist,*jlist,*numneigh,**firstneigh; + + evdwl = 0.0; + ev_init(eflag,vflag); + + double **x = atom->x; + double **f = atom->f; + int *type = atom->type; + int nlocal = atom->nlocal; + double *special_lj = force->special_lj; + int newton_pair = force->newton_pair; + + inum = list->inum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + // loop over neighbors of my atoms + + for (ii = 0; ii < inum; ii++) { + i = ilist[ii]; + xtmp = x[i][0]; + ytmp = x[i][1]; + ztmp = x[i][2]; + itype = type[i]; + jlist = firstneigh[i]; + jnum = numneigh[i]; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + factor_lj = special_lj[sbmask(j)]; + j &= NEIGHMASK; + + delx = xtmp - x[j][0]; + dely = ytmp - x[j][1]; + delz = ztmp - x[j][2]; + rsq = delx*delx + dely*dely + delz*delz; + jtype = type[j]; + + if (rsq < cutsq[itype][jtype]) { + r = sqrt(rsq); + dr = r - r0[itype][jtype]; + dexp = exp(-alpha[itype][jtype] * dr); + fpair = factor_lj * morse1[itype][jtype] * (dexp*dexp - dexp) / r; + + f[i][0] += delx*fpair; + f[i][1] += dely*fpair; + f[i][2] += delz*fpair; + if (newton_pair || j < nlocal) { + f[j][0] -= delx*fpair; + f[j][1] -= dely*fpair; + f[j][2] -= delz*fpair; + } + + if (eflag) { + evdwl = d0[itype][jtype] * (dexp*dexp - 2.0*dexp) - + offset[itype][jtype]; + evdwl *= factor_lj; + } + + if (evflag) ev_tally(i,j,nlocal,newton_pair, + evdwl,0.0,fpair,delx,dely,delz); + } + } + } + + if (vflag_fdotr) virial_fdotr_compute(); +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +void PairMorse2::allocate() +{ + allocated = 1; + int n = atom->ntypes; + + memory->create(setflag,n+1,n+1,"pair:setflag"); + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j++) + setflag[i][j] = 0; + + memory->create(cutsq,n+1,n+1,"pair:cutsq"); + + memory->create(cut,n+1,n+1,"pair:cut"); + memory->create(d0,n+1,n+1,"pair:d0"); + memory->create(alpha,n+1,n+1,"pair:alpha"); + memory->create(r0,n+1,n+1,"pair:r0"); + memory->create(morse1,n+1,n+1,"pair:morse1"); + memory->create(offset,n+1,n+1,"pair:offset"); +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +void PairMorse2::settings(int narg, char **arg) +{ + if (narg != 1) error->all(FLERR,"Illegal pair_style command"); + + cut_global = utils::numeric(FLERR,arg[0],false,lmp); + + // reset cutoffs that have been explicitly set + + if (allocated) { + int i,j; + for (i = 1; i <= atom->ntypes; i++) + for (j = i; j <= atom->ntypes; j++) + if (setflag[i][j]) cut[i][j] = cut_global; + } +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more type pairs +------------------------------------------------------------------------- */ + +void PairMorse2::coeff(int narg, char **arg) +{ + if (narg < 5 || narg > 6) + error->all(FLERR,"Incorrect args for pair coefficients"); + if (!allocated) allocate(); + + int ilo,ihi,jlo,jhi; + utils::bounds(FLERR,arg[0],1,atom->ntypes,ilo,ihi,error); + utils::bounds(FLERR,arg[1],1,atom->ntypes,jlo,jhi,error); + + double d0_one = utils::numeric(FLERR,arg[2],false,lmp); + double alpha_one = utils::numeric(FLERR,arg[3],false,lmp); + double r0_one = utils::numeric(FLERR,arg[4],false,lmp); + + double cut_one = cut_global; + if (narg == 6) cut_one = utils::numeric(FLERR,arg[5],false,lmp); + + int count = 0; + for (int i = ilo; i <= ihi; i++) { + for (int j = MAX(jlo,i); j <= jhi; j++) { + d0[i][j] = d0_one; + alpha[i][j] = alpha_one; + r0[i][j] = r0_one; + cut[i][j] = cut_one; + setflag[i][j] = 1; + count++; + } + } + + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); +} + + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +double PairMorse2::init_one(int i, int j) +{ + if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set"); + + morse1[i][j] = 2.0*d0[i][j]*alpha[i][j]; + + if (offset_flag) { + double alpha_dr = -alpha[i][j] * (cut[i][j] - r0[i][j]); + offset[i][j] = d0[i][j] * (exp(2.0*alpha_dr) - 2.0*exp(alpha_dr)); + } else offset[i][j] = 0.0; + + d0[j][i] = d0[i][j]; + alpha[j][i] = alpha[i][j]; + r0[j][i] = r0[i][j]; + morse1[j][i] = morse1[i][j]; + offset[j][i] = offset[i][j]; + + return cut[i][j]; +} + +/* ---------------------------------------------------------------------- + proc 0 writes to restart file +------------------------------------------------------------------------- */ + +void PairMorse2::write_restart(FILE *fp) +{ + write_restart_settings(fp); + + int i,j; + for (i = 1; i <= atom->ntypes; i++) + for (j = i; j <= atom->ntypes; j++) { + fwrite(&setflag[i][j],sizeof(int),1,fp); + if (setflag[i][j]) { + fwrite(&d0[i][j],sizeof(double),1,fp); + fwrite(&alpha[i][j],sizeof(double),1,fp); + fwrite(&r0[i][j],sizeof(double),1,fp); + fwrite(&cut[i][j],sizeof(double),1,fp); + } + } +} + +/* ---------------------------------------------------------------------- + proc 0 reads from restart file, bcasts +------------------------------------------------------------------------- */ + +void PairMorse2::read_restart(FILE *fp) +{ + read_restart_settings(fp); + + allocate(); + + int i,j; + int me = comm->me; + for (i = 1; i <= atom->ntypes; i++) + for (j = i; j <= atom->ntypes; j++) { + if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,nullptr,error); + MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); + if (setflag[i][j]) { + if (me == 0) { + utils::sfread(FLERR,&d0[i][j],sizeof(double),1,fp,nullptr,error); + utils::sfread(FLERR,&alpha[i][j],sizeof(double),1,fp,nullptr,error); + utils::sfread(FLERR,&r0[i][j],sizeof(double),1,fp,nullptr,error); + utils::sfread(FLERR,&cut[i][j],sizeof(double),1,fp,nullptr,error); + } + MPI_Bcast(&d0[i][j],1,MPI_DOUBLE,0,world); + MPI_Bcast(&alpha[i][j],1,MPI_DOUBLE,0,world); + MPI_Bcast(&r0[i][j],1,MPI_DOUBLE,0,world); + MPI_Bcast(&cut[i][j],1,MPI_DOUBLE,0,world); + } + } +} + +/* ---------------------------------------------------------------------- + proc 0 writes to restart file +------------------------------------------------------------------------- */ + +void PairMorse2::write_restart_settings(FILE *fp) +{ + fwrite(&cut_global,sizeof(double),1,fp); + fwrite(&offset_flag,sizeof(int),1,fp); + fwrite(&mix_flag,sizeof(int),1,fp); +} + +/* ---------------------------------------------------------------------- + proc 0 reads from restart file, bcasts +------------------------------------------------------------------------- */ + +void PairMorse2::read_restart_settings(FILE *fp) +{ + if (comm->me == 0) { + utils::sfread(FLERR,&cut_global,sizeof(double),1,fp,nullptr,error); + utils::sfread(FLERR,&offset_flag,sizeof(int),1,fp,nullptr,error); + utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,nullptr,error); + } + MPI_Bcast(&cut_global,1,MPI_DOUBLE,0,world); + MPI_Bcast(&offset_flag,1,MPI_INT,0,world); + MPI_Bcast(&mix_flag,1,MPI_INT,0,world); +} + +/* ---------------------------------------------------------------------- + proc 0 writes to data file +------------------------------------------------------------------------- */ + +void PairMorse2::write_data(FILE *fp) +{ + for (int i = 1; i <= atom->ntypes; i++) + fprintf(fp,"%d %g %g %g\n",i,d0[i][i],alpha[i][i],r0[i][i]); +} + +/* ---------------------------------------------------------------------- + proc 0 writes all pairs to data file +------------------------------------------------------------------------- */ + +void PairMorse2::write_data_all(FILE *fp) +{ + for (int i = 1; i <= atom->ntypes; i++) + for (int j = i; j <= atom->ntypes; j++) + fprintf(fp,"%d %d %g %g %g %g\n", + i,j,d0[i][j],alpha[i][j],r0[i][j],cut[i][j]); +} + +/* ---------------------------------------------------------------------- */ + +double PairMorse2::single(int /*i*/, int /*j*/, int itype, int jtype, double rsq, + double /*factor_coul*/, double factor_lj, + double &fforce) +{ + double r,dr,dexp,phi; + + r = sqrt(rsq); + dr = r - r0[itype][jtype]; + dexp = exp(-alpha[itype][jtype] * dr); + fforce = factor_lj * morse1[itype][jtype] * (dexp*dexp - dexp) / r; + + phi = d0[itype][jtype] * (dexp*dexp - 2.0*dexp) - offset[itype][jtype]; + return factor_lj*phi; +} + +/* ---------------------------------------------------------------------- */ + +void *PairMorse2::extract(const char *str, int &dim) +{ + dim = 2; + if (strcmp(str,"d0") == 0) return (void *) d0; + if (strcmp(str,"r0") == 0) return (void *) r0; + if (strcmp(str,"alpha") == 0) return (void *) alpha; + return nullptr; +} diff --git a/examples/plugins/pair_morse2.h b/examples/plugins/pair_morse2.h new file mode 100644 index 0000000000..c20f381c63 --- /dev/null +++ b/examples/plugins/pair_morse2.h @@ -0,0 +1,70 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifndef LMP_PAIR_MORSE2_H +#define LMP_PAIR_MORSE2_H + +#include "pair.h" + +namespace LAMMPS_NS { + +class PairMorse2 : public Pair { + public: + PairMorse2(class LAMMPS *); + virtual ~PairMorse2(); + virtual void compute(int, int); + + void settings(int, char **); + void coeff(int, char **); + double init_one(int, int); + void write_restart(FILE *); + void read_restart(FILE *); + void write_restart_settings(FILE *); + void read_restart_settings(FILE *); + void write_data(FILE *); + void write_data_all(FILE *); + double single(int, int, int, int, double, double, double, double &); + void *extract(const char *, int &); + + protected: + double cut_global; + double **cut; + double **d0,**alpha,**r0; + double **morse1; + double **offset; + + virtual void allocate(); +}; + +} + +#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: Incorrect args for pair coefficients + +Self-explanatory. Check the input script or data file. + +E: All pair coeffs are not set + +All pair coefficients must be set in the data file or by the +pair_coeff command before running a simulation. + +*/ From fb39ceaaeb3fbfa6ed9c84a8974bf4fb466e5fe2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 9 Mar 2021 16:00:14 -0500 Subject: [PATCH 003/257] fix whitespace and typo --- src/lammpsplugin.cpp | 7 ++----- src/lammpsplugin.h | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lammpsplugin.cpp b/src/lammpsplugin.cpp index d3d409de41..744203cd5e 100644 --- a/src/lammpsplugin.cpp +++ b/src/lammpsplugin.cpp @@ -27,12 +27,12 @@ namespace LAMMPS_NS { - + void lammpsplugin_load(const char *file, void *ptr) { LAMMPS *lmp = (LAMMPS *)ptr; #if defined(WIN32) - utils::logmsg(lmp,"Loading of plugins not supported on Windows yet\n"); + utils::logmesg(lmp,"Loading of plugins not supported on Windows yet\n"); #else void *dso = dlopen(file,RTLD_NOW); if (dso == nullptr) { @@ -71,6 +71,3 @@ namespace LAMMPS_NS } } } - - - diff --git a/src/lammpsplugin.h b/src/lammpsplugin.h index 9784c456ee..13076cc86f 100644 --- a/src/lammpsplugin.h +++ b/src/lammpsplugin.h @@ -18,7 +18,7 @@ extern "C" { #endif - typedef void *(lammpsplugin_factory)(void *); + typedef void *(lammpsplugin_factory)(void *); typedef void (*lammpsplugin_initfunc)(void *); typedef struct { From f68a7094ad5fe72c8e6caa18ce6276d76d4cdda1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 9 Mar 2021 18:44:51 -0500 Subject: [PATCH 004/257] include /omp variant into plugin example --- examples/plugins/Makefile | 9 +- examples/plugins/morse2plugin.cpp | 13 ++- examples/plugins/pair_morse2_omp.cpp | 160 +++++++++++++++++++++++++++ examples/plugins/pair_morse2_omp.h | 41 +++++++ 4 files changed, 218 insertions(+), 5 deletions(-) create mode 100644 examples/plugins/pair_morse2_omp.cpp create mode 100644 examples/plugins/pair_morse2_omp.h diff --git a/examples/plugins/Makefile b/examples/plugins/Makefile index 0c4365dfd8..2f563f924e 100644 --- a/examples/plugins/Makefile +++ b/examples/plugins/Makefile @@ -1,15 +1,16 @@ CXX=mpicxx -CXXFLAGS=-I../../src -Wall -O3 -fPIC -LD=$(CXX) -shared -rdynamic +CXXFLAGS=-I../../src -Wall -O3 -fPIC -I../../src/USER-OMP -fopenmp +LD=$(CXX) -shared -rdynamic -fopenmp -morse2plugin.so: morse2plugin.o pair_morse2.o +morse2plugin.so: morse2plugin.o pair_morse2.o pair_morse2_omp.o $(LD) -o $@ $^ .cpp.o: $(CXX) -o $@ $(CXXFLAGS) -c $< pair_morse2.o: pair_morse2.cpp pair_morse2.h -morse2plugin.o: morse2plugin.cpp pair_morse2.h +pair_morse2_omp.o: pair_morse2_omp.cpp pair_morse2_omp.h pair_morse2.h +morse2plugin.o: morse2plugin.cpp pair_morse2.h pair_morse2_omp.h clean: rm -f *~ *.so *.o log.lammps diff --git a/examples/plugins/morse2plugin.cpp b/examples/plugins/morse2plugin.cpp index bb21f3da95..fbb0882a92 100644 --- a/examples/plugins/morse2plugin.cpp +++ b/examples/plugins/morse2plugin.cpp @@ -7,6 +7,7 @@ #include #include "pair_morse2.h" +#include "pair_morse2_omp.h" using namespace LAMMPS_NS; @@ -15,6 +16,11 @@ static Pair *morse2creator(LAMMPS *lmp) return new PairMorse2(lmp); } +static Pair *morse2ompcreator(LAMMPS *lmp) +{ + return new PairMorse2OMP(lmp); +} + static lammpsplugin_t plugin; void lammpsplugin_init(void *lmp) { @@ -24,6 +30,11 @@ void lammpsplugin_init(void *lmp) plugin.name = "morse2"; plugin.info = "Morse2 variant pair style v1.0 by Axel Kohlmeyer"; plugin.creator = (lammpsplugin_factory *) &morse2creator; - + lammpsplugin_register(&plugin, (LAMMPS *)lmp); + + plugin.style = "pair"; + plugin.name = "morse2/omp"; + plugin.info = "Morse2 variant pair style for OpenMP v1.0 by Axel Kohlmeyer"; + plugin.creator = (lammpsplugin_factory *) &morse2ompcreator; lammpsplugin_register(&plugin, (LAMMPS *)lmp); } diff --git a/examples/plugins/pair_morse2_omp.cpp b/examples/plugins/pair_morse2_omp.cpp new file mode 100644 index 0000000000..14438c764b --- /dev/null +++ b/examples/plugins/pair_morse2_omp.cpp @@ -0,0 +1,160 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + This software is distributed under the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Axel Kohlmeyer (Temple U) +------------------------------------------------------------------------- */ + +#include "pair_morse2_omp.h" + +#include "atom.h" +#include "comm.h" +#include "force.h" +#include "neigh_list.h" +#include "suffix.h" + +#include + +#include "omp_compat.h" +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +PairMorse2OMP::PairMorse2OMP(LAMMPS *lmp) : + PairMorse2(lmp), ThrOMP(lmp, THR_PAIR) +{ + suffix_flag |= Suffix::OMP; + respa_enable = 0; +} + +/* ---------------------------------------------------------------------- */ + +void PairMorse2OMP::compute(int eflag, int vflag) +{ + ev_init(eflag,vflag); + + const int nall = atom->nlocal + atom->nghost; + const int nthreads = comm->nthreads; + const int inum = list->inum; + +#if defined(_OPENMP) +#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(eflag,vflag) +#endif + { + int ifrom, ito, tid; + + loop_setup_thr(ifrom, ito, tid, inum, nthreads); + ThrData *thr = fix->get_thr(tid); + thr->timer(Timer::START); + ev_setup_thr(eflag, vflag, nall, eatom, vatom, nullptr, thr); + + if (evflag) { + if (eflag) { + if (force->newton_pair) eval<1,1,1>(ifrom, ito, thr); + else eval<1,1,0>(ifrom, ito, thr); + } else { + if (force->newton_pair) eval<1,0,1>(ifrom, ito, thr); + else eval<1,0,0>(ifrom, ito, thr); + } + } else { + if (force->newton_pair) eval<0,0,1>(ifrom, ito, thr); + else eval<0,0,0>(ifrom, ito, thr); + } + + thr->timer(Timer::PAIR); + reduce_thr(this, eflag, vflag, thr); + } // end of omp parallel region +} + +template +void PairMorse2OMP::eval(int iifrom, int iito, ThrData * const thr) +{ + int i,j,ii,jj,jnum,itype,jtype; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; + double rsq,r,dr,dexp,factor_lj; + int *ilist,*jlist,*numneigh,**firstneigh; + + evdwl = 0.0; + + const dbl3_t * _noalias const x = (dbl3_t *) atom->x[0]; + dbl3_t * _noalias const f = (dbl3_t *) thr->get_f()[0]; + const int * _noalias const type = atom->type; + const int nlocal = atom->nlocal; + const double * _noalias const special_lj = force->special_lj; + double fxtmp,fytmp,fztmp; + + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + + // loop over neighbors of my atoms + + for (ii = iifrom; ii < iito; ++ii) { + + i = ilist[ii]; + xtmp = x[i].x; + ytmp = x[i].y; + ztmp = x[i].z; + itype = type[i]; + jlist = firstneigh[i]; + jnum = numneigh[i]; + fxtmp=fytmp=fztmp=0.0; + + for (jj = 0; jj < jnum; jj++) { + j = jlist[jj]; + factor_lj = special_lj[sbmask(j)]; + j &= NEIGHMASK; + + delx = xtmp - x[j].x; + dely = ytmp - x[j].y; + delz = ztmp - x[j].z; + rsq = delx*delx + dely*dely + delz*delz; + jtype = type[j]; + + if (rsq < cutsq[itype][jtype]) { + r = sqrt(rsq); + dr = r - r0[itype][jtype]; + dexp = exp(-alpha[itype][jtype] * dr); + fpair = factor_lj * morse1[itype][jtype] * (dexp*dexp - dexp) / r; + + fxtmp += delx*fpair; + fytmp += dely*fpair; + fztmp += delz*fpair; + if (NEWTON_PAIR || j < nlocal) { + f[j].x -= delx*fpair; + f[j].y -= dely*fpair; + f[j].z -= delz*fpair; + } + + if (EFLAG) { + evdwl = d0[itype][jtype] * (dexp*dexp - 2.0*dexp) - + offset[itype][jtype]; + evdwl *= factor_lj; + } + + if (EVFLAG) ev_tally_thr(this,i,j,nlocal,NEWTON_PAIR, + evdwl,0.0,fpair,delx,dely,delz,thr); + } + } + f[i].x += fxtmp; + f[i].y += fytmp; + f[i].z += fztmp; + } +} + +/* ---------------------------------------------------------------------- */ + +double PairMorse2OMP::memory_usage() +{ + double bytes = memory_usage_thr(); + bytes += PairMorse2::memory_usage(); + + return bytes; +} diff --git a/examples/plugins/pair_morse2_omp.h b/examples/plugins/pair_morse2_omp.h new file mode 100644 index 0000000000..c5ed7b5765 --- /dev/null +++ b/examples/plugins/pair_morse2_omp.h @@ -0,0 +1,41 @@ +/* -*- 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. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Axel Kohlmeyer (Temple U) +------------------------------------------------------------------------- */ + +#ifndef LMP_PAIR_MORSE2_OMP_H +#define LMP_PAIR_MORSE2_OMP_H + +#include "pair_morse2.h" +#include "thr_omp.h" + +namespace LAMMPS_NS { + +class PairMorse2OMP : public PairMorse2, public ThrOMP { + + public: + PairMorse2OMP(class LAMMPS *); + + virtual void compute(int, int); + virtual double memory_usage(); + + private: + template + void eval(int ifrom, int ito, ThrData * const thr); +}; + +} + +#endif From 592490be4ed469afc3b752edd5a684a80f195d10 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 10 Mar 2021 09:50:28 -0500 Subject: [PATCH 005/257] add unload/list commands --- src/input.cpp | 36 +++++++++++++++++++++++++--------- src/input.h | 2 +- src/lammpsplugin.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++- src/lammpsplugin.h | 24 ++++++++++++++++------- 4 files changed, 90 insertions(+), 18 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index 57ce64815d..07e3c417f6 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -715,10 +715,10 @@ int Input::execute_command() else if (!strcmp(command,"include")) include(); else if (!strcmp(command,"jump")) jump(); else if (!strcmp(command,"label")) label(); - else if (!strcmp(command,"load_plugin")) load_plugin(); else if (!strcmp(command,"log")) log(); else if (!strcmp(command,"next")) next_command(); else if (!strcmp(command,"partition")) partition(); + else if (!strcmp(command,"plugin")) plugin(); else if (!strcmp(command,"print")) print(); else if (!strcmp(command,"python")) python(); else if (!strcmp(command,"quit")) quit(); @@ -1031,14 +1031,6 @@ void Input::label() /* ---------------------------------------------------------------------- */ -void Input::load_plugin() -{ - if (narg != 1) error->all(FLERR,"Illegal load_plugin command"); - lammpsplugin_load(arg[0],lmp); -} - -/* ---------------------------------------------------------------------- */ - void Input::log() { if ((narg < 1) || (narg > 2)) error->all(FLERR,"Illegal log command"); @@ -1107,6 +1099,32 @@ void Input::partition() /* ---------------------------------------------------------------------- */ +void Input::plugin() +{ + if (narg < 1) error->all(FLERR,"Illegal plugin command"); + std::string cmd = arg[0]; + if (cmd == "load") { + if (narg < 2) error->all(FLERR,"Illegal plugin load command"); + for (int i=1; i < narg; ++i) + lammpsplugin_load(arg[i],lmp); + } else if (cmd == "unload") { + if (narg != 3) error->all(FLERR,"Illegal plugin unload command"); + lammpsplugin_unload(arg[1],arg[2],lmp); + } else if (cmd == "list") { + if (comm->me == 0) { + int num = lammpsplugin_get_num_plugins(); + utils::logmesg(lmp,"Currently loaded plugins\n"); + for (int i=0; i < num; ++i) { + auto entry = lammpsplugin_info(i); + utils::logmesg(lmp,fmt::format("{:4}: {} style plugin {}\n", + i+1,entry->style,entry->name)); + } + } + } else error->all(FLERR,"Illegal plugin command"); +} + +/* ---------------------------------------------------------------------- */ + void Input::print() { if (narg < 1) error->all(FLERR,"Illegal print command"); diff --git a/src/input.h b/src/input.h index 3b7b6d79c7..809a7a5f94 100644 --- a/src/input.h +++ b/src/input.h @@ -79,10 +79,10 @@ class Input : protected Pointers { void include(); void jump(); void label(); - void load_plugin(); void log(); void next_command(); void partition(); + void plugin(); void print(); void python(); void quit(); diff --git a/src/lammpsplugin.cpp b/src/lammpsplugin.cpp index 744203cd5e..3086b829c0 100644 --- a/src/lammpsplugin.cpp +++ b/src/lammpsplugin.cpp @@ -18,6 +18,7 @@ #include "lammps.h" #include "modify.h" +#include #ifdef _WIN32 #include @@ -27,6 +28,7 @@ namespace LAMMPS_NS { + static std::vector pluginlist; void lammpsplugin_load(const char *file, void *ptr) { @@ -34,7 +36,7 @@ namespace LAMMPS_NS #if defined(WIN32) utils::logmesg(lmp,"Loading of plugins not supported on Windows yet\n"); #else - void *dso = dlopen(file,RTLD_NOW); + void *dso = dlopen(file,RTLD_NOW|RTLD_GLOBAL); if (dso == nullptr) { utils::logmesg(lmp,fmt::format("Loading of plugin from file {} failed: " "{}", file, utils::getsyserror())); @@ -48,6 +50,7 @@ namespace LAMMPS_NS return; } ((lammpsplugin_initfunc)(initfunc))(ptr); +// dlclose(dso); #endif } @@ -61,6 +64,12 @@ namespace LAMMPS_NS "version {} loaded into LAMMPS " "version {}\n", plugin->info, plugin->version, lmp->version)); + lammpsplugin_entry_t entry; + entry.style = plugin->style; + entry.name = plugin->name; + entry.handle = nullptr; + pluginlist.push_back(entry); + std::string pstyle = plugin->style; if (pstyle == "pair") { (*(lmp->force->pair_map))[plugin->name] = @@ -68,6 +77,41 @@ namespace LAMMPS_NS } else { utils::logmesg(lmp,fmt::format("Loading plugin for {} styles not " "yet implemented\n", pstyle)); + pluginlist.pop_back(); + } + } + + int lammpsplugin_get_num_plugins() + { + return pluginlist.size(); + } + + const lammpsplugin_entry_t *lammpsplugin_info(int idx) + { + if ((idx < 0) || idx >= pluginlist.size()) return nullptr; + + return &pluginlist[idx]; + } + + int lammpsplugin_find(const char *style, const char *name) + { + for (int i=0; i < pluginlist.size(); ++i) { + if ((strcmp(style,pluginlist[i].style) == 0) + && (strcmp(name,pluginlist[i].name) == 0)) + return i; + } + return -1; + } + + void lammpsplugin_unload(const char *style, const char *name, void *ptr) + { + LAMMPS *lmp = (LAMMPS *)ptr; + std::string pstyle = style; + if (pstyle == "pair") { + auto found = lmp->force->pair_map->find(name); + if (found != lmp->force->pair_map->end()) { + lmp->force->pair_map->erase(found); + } } } } diff --git a/src/lammpsplugin.h b/src/lammpsplugin.h index 13076cc86f..36c442aa5e 100644 --- a/src/lammpsplugin.h +++ b/src/lammpsplugin.h @@ -14,9 +14,9 @@ #ifndef LMP_LAMMPSPLUGIN_H #define LMP_LAMMPSPLUGIN_H -#ifdef __cplusplus +// C style API and data structures required for dynamic loading + extern "C" { -#endif typedef void *(lammpsplugin_factory)(void *); typedef void (*lammpsplugin_initfunc)(void *); @@ -29,16 +29,26 @@ extern "C" { lammpsplugin_factory *creator; } lammpsplugin_t; - void lammpsplugin_init(void *); + typedef struct { + const char *style; + const char *name; + const void *handle; + } lammpsplugin_entry_t; -#ifdef __cplusplus + // prototype for initializer function required + // to load a plugin; uses C bindings + + void lammpsplugin_init(void *); } -#endif namespace LAMMPS_NS { - extern void lammpsplugin_load(const char *, void *); - extern void lammpsplugin_register(lammpsplugin_t *, void *); + extern void lammpsplugin_load(const char *, void *); + extern void lammpsplugin_register(lammpsplugin_t *, void *); + extern int lammpsplugin_get_num_plugins(); + extern const lammpsplugin_entry_t *lammpsplugin_info(int); + extern int lammpsplugin_find(const char *, const char *); + extern void lammpsplugin_unload(const char *, const char *, void *); } #endif From a548ea3bca516006a5ba2d1151ad89e57dc01e95 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 10 Mar 2021 13:40:10 -0500 Subject: [PATCH 006/257] Add more tests for dump atom/gz --- unittest/formats/test_dump_atom_gz.cpp | 177 ++++++++++++++++++++++++- unittest/testing/utils.h | 3 + 2 files changed, 177 insertions(+), 3 deletions(-) diff --git a/unittest/formats/test_dump_atom_gz.cpp b/unittest/formats/test_dump_atom_gz.cpp index c8f2eb500c..614910fcf2 100644 --- a/unittest/formats/test_dump_atom_gz.cpp +++ b/unittest/formats/test_dump_atom_gz.cpp @@ -52,14 +52,25 @@ public: void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, std::string dump_modify_options, int ntimesteps) + { + generate_text_and_compressed_dump(text_file, compressed_file, compression_style, + dump_modify_options, dump_modify_options, ntimesteps); + } + + void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, + std::string compression_style, + std::string text_options, std::string compressed_options, int ntimesteps) { if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); + if (!text_options.empty()) { + command(fmt::format("dump_modify id0 {}", text_options)); + } + + if (!compressed_options.empty()) { + command(fmt::format("dump_modify id1 {}", compressed_options)); } command(fmt::format("run {}", ntimesteps)); @@ -106,6 +117,124 @@ TEST_F(DumpAtomGZTest, compressed_run0) delete_file(converted_file); } +TEST_F(DumpAtomGZTest, compressed_multi_file_run1) +{ + if (!GZIP_BINARY) GTEST_SKIP(); + + auto text_file = "dump_gz_text_multi_file_run1_*.melt"; + auto compressed_file = "dump_gz_compressed_multi_file_run1_*.melt.gz"; + auto text_file_0 = "dump_gz_text_multi_file_run1_0.melt"; + auto text_file_1 = "dump_gz_text_multi_file_run1_1.melt"; + auto compressed_file_0 = "dump_gz_compressed_multi_file_run1_0.melt.gz"; + auto compressed_file_1 = "dump_gz_compressed_multi_file_run1_1.melt.gz"; + + generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq("dump_gz_compressed_multi_file_run1_0.melt")); + ASSERT_THAT(converted_file_1, Eq("dump_gz_compressed_multi_file_run1_1.melt")); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpAtomGZTest, compressed_multi_file_with_pad_run1) +{ + if (!GZIP_BINARY) GTEST_SKIP(); + + auto text_file = "dump_gz_text_multi_file_pad_run1_*.melt"; + auto compressed_file = "dump_gz_compressed_multi_file_pad_run1_*.melt.gz"; + auto text_file_0 = "dump_gz_text_multi_file_pad_run1_000.melt"; + auto text_file_1 = "dump_gz_text_multi_file_pad_run1_001.melt"; + auto compressed_file_0 = "dump_gz_compressed_multi_file_pad_run1_000.melt.gz"; + auto compressed_file_1 = "dump_gz_compressed_multi_file_pad_run1_001.melt.gz"; + + generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq("dump_gz_compressed_multi_file_pad_run1_000.melt")); + ASSERT_THAT(converted_file_1, Eq("dump_gz_compressed_multi_file_pad_run1_001.melt")); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpAtomGZTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!GZIP_BINARY) GTEST_SKIP(); + + auto text_file = "dump_gz_text_multi_file_run1_*.melt"; + auto compressed_file = "dump_gz_compressed_multi_file_run1_*.melt.gz"; + auto text_file_0 = "dump_gz_text_multi_file_run1_0.melt"; + auto text_file_1 = "dump_gz_text_multi_file_run1_1.melt"; + auto text_file_2 = "dump_gz_text_multi_file_run1_2.melt"; + auto compressed_file_0 = "dump_gz_compressed_multi_file_run1_0.melt.gz"; + auto compressed_file_1 = "dump_gz_compressed_multi_file_run1_1.melt.gz"; + auto compressed_file_2 = "dump_gz_compressed_multi_file_run1_2.melt.gz"; + + generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq("dump_gz_compressed_multi_file_run1_1.melt")); + ASSERT_THAT(converted_file_2, Eq("dump_gz_compressed_multi_file_run1_2.melt")); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + TEST_F(DumpAtomGZTest, compressed_with_units_run0) { if (!GZIP_BINARY) GTEST_SKIP(); @@ -252,6 +381,48 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_with_image_run0) delete_file(converted_file); } +TEST_F(DumpAtomGZTest, compressed_modify_bad_param) +{ + command("dump id1 all atom/gz 1 dump_gz_text_modify_bad_param_run0_*.melt.gz"); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpAtomGZTest, compressed_modify_multi_bad_param) +{ + command("dump id1 all atom/gz 1 dump_gz_text_modify_bad_param_run0_*.melt.gz"); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpAtomGZTest, compressed_modify_clevel_run0) +{ + if (!GZIP_BINARY) GTEST_SKIP(); + + auto text_file = "dump_gz_text_modify_clevel_run0.melt"; + auto compressed_file = "dump_gz_compressed_modify_clevel_run0.melt.gz"; + + generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file, Eq("dump_gz_compressed_modify_clevel_run0.melt")); + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + int main(int argc, char **argv) { MPI_Init(&argc, &argv); diff --git a/unittest/testing/utils.h b/unittest/testing/utils.h index 39a11a3e12..c76b37872a 100644 --- a/unittest/testing/utils.h +++ b/unittest/testing/utils.h @@ -70,6 +70,9 @@ static bool file_exists(const std::string &filename) } #define ASSERT_FILE_EXISTS(NAME) ASSERT_TRUE(file_exists(NAME)) +#define ASSERT_FILE_NOT_EXISTS(NAME) ASSERT_FALSE(file_exists(NAME)) #define ASSERT_FILE_EQUAL(FILE_A, FILE_B) ASSERT_TRUE(equal_lines(FILE_A, FILE_B)) + + #endif From aa625eaf656ec6ab5b54779c9f9d01add4ae11a5 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 10 Mar 2021 15:48:20 -0500 Subject: [PATCH 007/257] Unify dump atom/gz and atom/zstd tests --- unittest/formats/CMakeLists.txt | 17 +- ...m_gz.cpp => test_dump_atom_compressed.cpp} | 245 +++++++++------ unittest/formats/test_dump_atom_zstd.cpp | 284 ------------------ 3 files changed, 154 insertions(+), 392 deletions(-) rename unittest/formats/{test_dump_atom_gz.cpp => test_dump_atom_compressed.cpp} (58%) delete mode 100644 unittest/formats/test_dump_atom_zstd.cpp diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index 7b96cf2d32..7b19bfde46 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -40,11 +40,11 @@ set_tests_properties(DumpAtom PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS if(PKG_COMPRESS) find_program(GZIP_BINARY NAMES gzip REQUIRED) - add_executable(test_dump_atom_gz test_dump_atom_gz.cpp) - target_link_libraries(test_dump_atom_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpAtomGZ COMMAND test_dump_atom_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") + add_executable(test_dump_atom_compressed test_dump_atom_compressed.cpp) + target_link_libraries(test_dump_atom_compressed PRIVATE lammps GTest::GMock GTest::GTest) + + add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") add_executable(test_dump_custom_gz test_dump_custom_gz.cpp) target_link_libraries(test_dump_custom_gz PRIVATE lammps GTest::GMock GTest::GTest) @@ -75,11 +75,8 @@ if(PKG_COMPRESS) find_program(ZSTD_BINARY NAMES zstd) if(Zstd_FOUND AND ZSTD_BINARY) - add_executable(test_dump_atom_zstd test_dump_atom_zstd.cpp) - target_link_libraries(test_dump_atom_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpAtomZstd COMMAND test_dump_atom_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpAtomZstd COMMAND test_dump_atom_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") add_executable(test_dump_custom_zstd test_dump_custom_zstd.cpp) target_link_libraries(test_dump_custom_zstd PRIVATE lammps GTest::GMock GTest::GTest) diff --git a/unittest/formats/test_dump_atom_gz.cpp b/unittest/formats/test_dump_atom_compressed.cpp similarity index 58% rename from unittest/formats/test_dump_atom_gz.cpp rename to unittest/formats/test_dump_atom_compressed.cpp index 614910fcf2..2f3f609744 100644 --- a/unittest/formats/test_dump_atom_gz.cpp +++ b/unittest/formats/test_dump_atom_compressed.cpp @@ -21,14 +21,36 @@ #include -char *GZIP_BINARY = nullptr; +const char * COMPRESS_SUFFIX = nullptr; +const char * COMPRESS_EXTENSION = nullptr; +char * COMPRESS_BINARY = nullptr; using ::testing::Eq; -class DumpAtomGZTest : public MeltTest { +class DumpAtomCompressTest : public MeltTest { +protected: std::string dump_style = "atom"; + std::string compression_style = ""; public: + void SetUp() override + { + MeltTest::SetUp(); + compression_style = fmt::format("{}/{}", dump_style, COMPRESS_SUFFIX); + } + + std::string text_dump_filename(std::string ident) { + return fmt::format("dump_{}_text_{}", COMPRESS_SUFFIX, ident); + } + + std::string compressed_dump_filename(std::string ident) { + return fmt::format("dump_{}_compressed_{}.{}", COMPRESS_SUFFIX, ident, COMPRESS_EXTENSION); + } + + std::string converted_dump_filename(std::string ident) { + return fmt::format("dump_{}_compressed_{}", COMPRESS_SUFFIX, ident); + } + void enable_triclinic() { if (!verbose) ::testing::internal::CaptureStdout(); @@ -50,15 +72,13 @@ public: } void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string dump_modify_options, int ntimesteps) { - generate_text_and_compressed_dump(text_file, compressed_file, compression_style, + generate_text_and_compressed_dump(text_file, compressed_file, dump_modify_options, dump_modify_options, ntimesteps); } void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string text_options, std::string compressed_options, int ntimesteps) { if (!verbose) ::testing::internal::CaptureStdout(); @@ -82,7 +102,7 @@ public: if (!verbose) ::testing::internal::CaptureStdout(); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); + fmt::format("{} -d -c {} > {}", COMPRESS_BINARY, compressed_file, converted_file); system(cmdline.c_str()); if (!verbose) ::testing::internal::GetCapturedStdout(); return converted_file; @@ -90,17 +110,17 @@ public: }; //------------------------------------------------------------------------------------------------- -// GZ compressed files +// compressed files //------------------------------------------------------------------------------------------------- -TEST_F(DumpAtomGZTest, compressed_run0) +TEST_F(DumpAtomCompressTest, compressed_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_run0.melt"; - auto compressed_file = "dump_gz_compressed_run0.melt.gz"; + auto text_file = text_dump_filename("run0.melt"); + auto compressed_file = compressed_dump_filename("run0.melt"); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", 0); TearDown(); @@ -109,7 +129,7 @@ TEST_F(DumpAtomGZTest, compressed_run0) auto converted_file = convert_compressed_to_text(compressed_file); - ASSERT_THAT(converted_file, Eq("dump_gz_compressed_run0.melt")); + ASSERT_THAT(converted_file, Eq(converted_dump_filename("run0.melt"))); ASSERT_FILE_EXISTS(converted_file); ASSERT_FILE_EQUAL(text_file, converted_file); delete_file(text_file); @@ -117,31 +137,29 @@ TEST_F(DumpAtomGZTest, compressed_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_multi_file_run1) +TEST_F(DumpAtomCompressTest, compressed_multi_file_run1) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_multi_file_run1_*.melt"; - auto compressed_file = "dump_gz_compressed_multi_file_run1_*.melt.gz"; - auto text_file_0 = "dump_gz_text_multi_file_run1_0.melt"; - auto text_file_1 = "dump_gz_text_multi_file_run1_1.melt"; - auto compressed_file_0 = "dump_gz_compressed_multi_file_run1_0.melt.gz"; - auto compressed_file_1 = "dump_gz_compressed_multi_file_run1_1.melt.gz"; + auto base_name = "multi_file_run1_*.melt"; + auto base_name_0 = "multi_file_run1_0.melt"; + auto base_name_1 = "multi_file_run1_1.melt"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", 1); + generate_text_and_compressed_dump(text_file, compressed_file, "", 1); TearDown(); - ASSERT_FILE_EXISTS(text_file_0); - ASSERT_FILE_EXISTS(text_file_1); - ASSERT_FILE_EXISTS(compressed_file_0); - ASSERT_FILE_EXISTS(compressed_file_1); - auto converted_file_0 = convert_compressed_to_text(compressed_file_0); auto converted_file_1 = convert_compressed_to_text(compressed_file_1); - ASSERT_THAT(converted_file_0, Eq("dump_gz_compressed_multi_file_run1_0.melt")); - ASSERT_THAT(converted_file_1, Eq("dump_gz_compressed_multi_file_run1_1.melt")); + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); ASSERT_FILE_EXISTS(converted_file_0); ASSERT_FILE_EXISTS(converted_file_1); ASSERT_FILE_EQUAL(text_file_0, converted_file_0); @@ -155,18 +173,21 @@ TEST_F(DumpAtomGZTest, compressed_multi_file_run1) delete_file(converted_file_1); } -TEST_F(DumpAtomGZTest, compressed_multi_file_with_pad_run1) +TEST_F(DumpAtomCompressTest, compressed_multi_file_with_pad_run1) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_multi_file_pad_run1_*.melt"; - auto compressed_file = "dump_gz_compressed_multi_file_pad_run1_*.melt.gz"; - auto text_file_0 = "dump_gz_text_multi_file_pad_run1_000.melt"; - auto text_file_1 = "dump_gz_text_multi_file_pad_run1_001.melt"; - auto compressed_file_0 = "dump_gz_compressed_multi_file_pad_run1_000.melt.gz"; - auto compressed_file_1 = "dump_gz_compressed_multi_file_pad_run1_001.melt.gz"; + auto base_name = "multi_file_pad_run1_*.melt"; + auto base_name_0 = "multi_file_pad_run1_000.melt"; + auto base_name_1 = "multi_file_pad_run1_001.melt"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "pad 3", 1); + generate_text_and_compressed_dump(text_file, compressed_file, "pad 3", 1); TearDown(); @@ -178,8 +199,8 @@ TEST_F(DumpAtomGZTest, compressed_multi_file_with_pad_run1) auto converted_file_0 = convert_compressed_to_text(compressed_file_0); auto converted_file_1 = convert_compressed_to_text(compressed_file_1); - ASSERT_THAT(converted_file_0, Eq("dump_gz_compressed_multi_file_pad_run1_000.melt")); - ASSERT_THAT(converted_file_1, Eq("dump_gz_compressed_multi_file_pad_run1_001.melt")); + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); ASSERT_FILE_EXISTS(converted_file_0); ASSERT_FILE_EXISTS(converted_file_1); ASSERT_FILE_EQUAL(text_file_0, converted_file_0); @@ -193,20 +214,24 @@ TEST_F(DumpAtomGZTest, compressed_multi_file_with_pad_run1) delete_file(converted_file_1); } -TEST_F(DumpAtomGZTest, compressed_multi_file_with_maxfiles_run1) +TEST_F(DumpAtomCompressTest, compressed_multi_file_with_maxfiles_run1) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_multi_file_run1_*.melt"; - auto compressed_file = "dump_gz_compressed_multi_file_run1_*.melt.gz"; - auto text_file_0 = "dump_gz_text_multi_file_run1_0.melt"; - auto text_file_1 = "dump_gz_text_multi_file_run1_1.melt"; - auto text_file_2 = "dump_gz_text_multi_file_run1_2.melt"; - auto compressed_file_0 = "dump_gz_compressed_multi_file_run1_0.melt.gz"; - auto compressed_file_1 = "dump_gz_compressed_multi_file_run1_1.melt.gz"; - auto compressed_file_2 = "dump_gz_compressed_multi_file_run1_2.melt.gz"; + auto base_name = "multi_file_maxfiles_run1_*.melt"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "maxfiles 2", 2); + generate_text_and_compressed_dump(text_file, compressed_file, "maxfiles 2", 2); TearDown(); @@ -220,8 +245,8 @@ TEST_F(DumpAtomGZTest, compressed_multi_file_with_maxfiles_run1) auto converted_file_1 = convert_compressed_to_text(compressed_file_1); auto converted_file_2 = convert_compressed_to_text(compressed_file_2); - ASSERT_THAT(converted_file_1, Eq("dump_gz_compressed_multi_file_run1_1.melt")); - ASSERT_THAT(converted_file_2, Eq("dump_gz_compressed_multi_file_run1_2.melt")); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); ASSERT_FILE_EXISTS(converted_file_1); ASSERT_FILE_EXISTS(converted_file_2); ASSERT_FILE_EQUAL(text_file_1, converted_file_1); @@ -235,14 +260,15 @@ TEST_F(DumpAtomGZTest, compressed_multi_file_with_maxfiles_run1) delete_file(converted_file_2); } -TEST_F(DumpAtomGZTest, compressed_with_units_run0) +TEST_F(DumpAtomCompressTest, compressed_with_units_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_with_units_run0.melt"; - auto compressed_file = "dump_gz_compressed_with_units_run0.melt.gz"; + auto base_name = "with_units_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", + generate_text_and_compressed_dump(text_file, compressed_file, "scale no units yes", 0); TearDown(); @@ -259,15 +285,15 @@ TEST_F(DumpAtomGZTest, compressed_with_units_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_with_time_run0) +TEST_F(DumpAtomCompressTest, compressed_with_time_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_with_time_run0.melt"; - auto compressed_file = "dump_gz_compressed_with_time_run0.melt.gz"; + auto base_name = "with_time_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", - 0); + generate_text_and_compressed_dump(text_file, compressed_file, "scale no time yes", 0); TearDown(); @@ -283,15 +309,16 @@ TEST_F(DumpAtomGZTest, compressed_with_time_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_triclinic_run0) +TEST_F(DumpAtomCompressTest, compressed_triclinic_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_tri_run0.melt"; - auto compressed_file = "dump_gz_compressed_tri_run0.melt.gz"; + auto base_name = "tri_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", 0); TearDown(); @@ -307,16 +334,16 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_triclinic_with_units_run0) +TEST_F(DumpAtomCompressTest, compressed_triclinic_with_units_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_tri_with_units_run0.melt"; - auto compressed_file = "dump_gz_compressed_tri_with_units_run0.melt.gz"; + auto base_name = "tri_with_units_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", - 0); + generate_text_and_compressed_dump(text_file, compressed_file, "scale no units yes", 0); TearDown(); @@ -332,16 +359,16 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_with_units_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_triclinic_with_time_run0) +TEST_F(DumpAtomCompressTest, compressed_triclinic_with_time_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_tri_with_time_run0.melt"; - auto compressed_file = "dump_gz_compressed_tri_with_time_run0.melt.gz"; + auto base_name = "tri_with_time_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", - 0); + generate_text_and_compressed_dump(text_file, compressed_file, "scale no time yes", 0); TearDown(); @@ -357,15 +384,16 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_with_time_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_triclinic_with_image_run0) +TEST_F(DumpAtomCompressTest, compressed_triclinic_with_image_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_tri_with_image_run0.melt"; - auto compressed_file = "dump_gz_compressed_tri_with_image_run0.melt.gz"; + auto base_name = "tri_with_image_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "image yes", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "image yes", 0); TearDown(); @@ -381,32 +409,37 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_with_image_run0) delete_file(converted_file); } -TEST_F(DumpAtomGZTest, compressed_modify_bad_param) +TEST_F(DumpAtomCompressTest, compressed_modify_bad_param) { - command("dump id1 all atom/gz 1 dump_gz_text_modify_bad_param_run0_*.melt.gz"); + if (compression_style != "atom/gz") GTEST_SKIP(); + + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt"))); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); ); } -TEST_F(DumpAtomGZTest, compressed_modify_multi_bad_param) +TEST_F(DumpAtomCompressTest, compressed_modify_multi_bad_param) { - command("dump id1 all atom/gz 1 dump_gz_text_modify_bad_param_run0_*.melt.gz"); + if (compression_style != "atom/gz") GTEST_SKIP(); + + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt"))); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); ); } -TEST_F(DumpAtomGZTest, compressed_modify_clevel_run0) +TEST_F(DumpAtomCompressTest, compressed_modify_clevel_run0) { - if (!GZIP_BINARY) GTEST_SKIP(); + if (!COMPRESS_BINARY) GTEST_SKIP(); - auto text_file = "dump_gz_text_modify_clevel_run0.melt"; - auto compressed_file = "dump_gz_compressed_modify_clevel_run0.melt.gz"; + auto base_name = "modify_clevel_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", "compression_level 3", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "compression_level 3", 0); TearDown(); @@ -415,7 +448,7 @@ TEST_F(DumpAtomGZTest, compressed_modify_clevel_run0) auto converted_file = convert_compressed_to_text(compressed_file); - ASSERT_THAT(converted_file, Eq("dump_gz_compressed_modify_clevel_run0.melt")); + ASSERT_THAT(converted_file, Eq(converted_dump_filename(base_name))); ASSERT_FILE_EXISTS(converted_file); ASSERT_FILE_EQUAL(text_file, converted_file); delete_file(text_file); @@ -428,6 +461,24 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + if(strcmp(argv[1], "gz") == 0) { + COMPRESS_SUFFIX = "gz"; + COMPRESS_EXTENSION = "gz"; + } else if(strcmp(argv[1], "zstd") == 0) { + COMPRESS_SUFFIX = "zstd"; + COMPRESS_EXTENSION = "zst"; + } else { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + COMPRESS_BINARY = getenv("COMPRESS_BINARY"); + // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = utils::split_words(var); @@ -438,8 +489,6 @@ int main(int argc, char **argv) } } - GZIP_BINARY = getenv("GZIP_BINARY"); - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; int rv = RUN_ALL_TESTS(); diff --git a/unittest/formats/test_dump_atom_zstd.cpp b/unittest/formats/test_dump_atom_zstd.cpp deleted file mode 100644 index 41c2fd3c79..0000000000 --- a/unittest/formats/test_dump_atom_zstd.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include - -char *ZSTD_BINARY = nullptr; - -using ::testing::Eq; - -class DumpAtomZSTDTest : public MeltTest { - std::string dump_style = "atom"; - -public: - void enable_triclinic() - { - if (!verbose) ::testing::internal::CaptureStdout(); - command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -//------------------------------------------------------------------------------------------------- -// ZSTD compressed files -//------------------------------------------------------------------------------------------------- - -TEST_F(DumpAtomZSTDTest, compressed_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_run0.melt"; - auto compressed_file = "dump_zstd_compressed_run0.melt.zst"; - - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "", 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_THAT(converted_file, Eq("dump_zstd_compressed_run0.melt")); - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_with_units_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_with_units_run0.melt"; - auto compressed_file = "dump_zstd_compressed_with_units_run0.melt.zst"; - - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", - 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_with_time_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_with_time_run0.melt"; - auto compressed_file = "dump_zstd_compressed_with_time_run0.melt.zst"; - - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", - 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_triclinic_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_tri_run0.melt"; - auto compressed_file = "dump_zstd_compressed_tri_run0.melt.zst"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "", 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_units_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_tri_with_units_run0.melt"; - auto compressed_file = "dump_zstd_compressed_tri_with_units_run0.melt.zst"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", - 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_time_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_tri_with_time_run0.melt"; - auto compressed_file = "dump_zstd_compressed_tri_with_time_run0.melt.zst"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", - 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_image_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_tri_with_image_run0.melt"; - auto compressed_file = "dump_zstd_compressed_tri_with_image_run0.melt.zst"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "image yes", 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} From 20a546c824ece52221b75513906ef98cb1bdc889 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 10 Mar 2021 16:08:51 -0500 Subject: [PATCH 008/257] Move testcase in its own file --- unittest/formats/compressed_dump_test.h | 104 ++++++++++++++++++ .../formats/test_dump_atom_compressed.cpp | 86 +-------------- 2 files changed, 107 insertions(+), 83 deletions(-) create mode 100644 unittest/formats/compressed_dump_test.h diff --git a/unittest/formats/compressed_dump_test.h b/unittest/formats/compressed_dump_test.h new file mode 100644 index 0000000000..80b8550060 --- /dev/null +++ b/unittest/formats/compressed_dump_test.h @@ -0,0 +1,104 @@ +/* ---------------------------------------------------------------------- + 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 TESTCASE_COMPRESSED_DUMP__H +#define TESTCASE_COMPRESSED_DUMP__H + +#include "../testing/core.h" +#include "../testing/systems/melt.h" +#include + +const char * COMPRESS_SUFFIX = nullptr; +const char * COMPRESS_EXTENSION = nullptr; +char * COMPRESS_BINARY = nullptr; + +class CompressedDumpTest : public MeltTest { +protected: + std::string dump_style; + std::string compression_style; + +public: + CompressedDumpTest(const std::string & dump_style) : MeltTest(), dump_style(dump_style) { + compression_style = fmt::format("{}/{}", dump_style, COMPRESS_SUFFIX); + } + + std::string text_dump_filename(std::string ident) { + return fmt::format("dump_{}_text_{}", COMPRESS_SUFFIX, ident); + } + + std::string compressed_dump_filename(std::string ident) { + return fmt::format("dump_{}_compressed_{}.{}", COMPRESS_SUFFIX, ident, COMPRESS_EXTENSION); + } + + std::string converted_dump_filename(std::string ident) { + return fmt::format("dump_{}_compressed_{}", COMPRESS_SUFFIX, ident); + } + + void enable_triclinic() + { + if (!verbose) ::testing::internal::CaptureStdout(); + command("change_box all triclinic"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) + { + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); + + if (!dump_modify_options.empty()) { + command(fmt::format("dump_modify id {}", dump_modify_options)); + } + + command(fmt::format("run {}", ntimesteps)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, + std::string dump_modify_options, int ntimesteps) + { + generate_text_and_compressed_dump(text_file, compressed_file, + dump_modify_options, dump_modify_options, ntimesteps); + } + + void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, + std::string text_options, std::string compressed_options, int ntimesteps) + { + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); + + if (!text_options.empty()) { + command(fmt::format("dump_modify id0 {}", text_options)); + } + + if (!compressed_options.empty()) { + command(fmt::format("dump_modify id1 {}", compressed_options)); + } + + command(fmt::format("run {}", ntimesteps)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + std::string convert_compressed_to_text(std::string compressed_file) + { + if (!verbose) ::testing::internal::CaptureStdout(); + std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); + std::string cmdline = + fmt::format("{} -d -c {} > {}", COMPRESS_BINARY, compressed_file, converted_file); + system(cmdline.c_str()); + if (!verbose) ::testing::internal::GetCapturedStdout(); + return converted_file; + } +}; + +#endif diff --git a/unittest/formats/test_dump_atom_compressed.cpp b/unittest/formats/test_dump_atom_compressed.cpp index 2f3f609744..e33366801e 100644 --- a/unittest/formats/test_dump_atom_compressed.cpp +++ b/unittest/formats/test_dump_atom_compressed.cpp @@ -11,9 +11,8 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "../testing/core.h" -#include "../testing/systems/melt.h" #include "../testing/utils.h" +#include "compressed_dump_test.h" #include "fmt/format.h" #include "utils.h" #include "gmock/gmock.h" @@ -21,91 +20,12 @@ #include -const char * COMPRESS_SUFFIX = nullptr; -const char * COMPRESS_EXTENSION = nullptr; -char * COMPRESS_BINARY = nullptr; using ::testing::Eq; -class DumpAtomCompressTest : public MeltTest { -protected: - std::string dump_style = "atom"; - std::string compression_style = ""; - +class DumpAtomCompressTest : public CompressedDumpTest { public: - void SetUp() override - { - MeltTest::SetUp(); - compression_style = fmt::format("{}/{}", dump_style, COMPRESS_SUFFIX); - } - - std::string text_dump_filename(std::string ident) { - return fmt::format("dump_{}_text_{}", COMPRESS_SUFFIX, ident); - } - - std::string compressed_dump_filename(std::string ident) { - return fmt::format("dump_{}_compressed_{}.{}", COMPRESS_SUFFIX, ident, COMPRESS_EXTENSION); - } - - std::string converted_dump_filename(std::string ident) { - return fmt::format("dump_{}_compressed_{}", COMPRESS_SUFFIX, ident); - } - - void enable_triclinic() - { - if (!verbose) ::testing::internal::CaptureStdout(); - command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string dump_modify_options, int ntimesteps) - { - generate_text_and_compressed_dump(text_file, compressed_file, - dump_modify_options, dump_modify_options, ntimesteps); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string text_options, std::string compressed_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - - if (!text_options.empty()) { - command(fmt::format("dump_modify id0 {}", text_options)); - } - - if (!compressed_options.empty()) { - command(fmt::format("dump_modify id1 {}", compressed_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", COMPRESS_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; + DumpAtomCompressTest() : CompressedDumpTest("atom") { } }; From 8e1ccb6123e4d1800ad0f4eac27ec22aa1ce870d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 07:26:57 -0500 Subject: [PATCH 009/257] next iteration: rename functions/files, split header, store dso handle --- examples/plugins/morse2plugin.cpp | 12 +++++++----- src/input.cpp | 10 +++++----- src/lammpsplugin.h | 24 ++++++----------------- src/{lammpsplugin.cpp => plugin.cpp} | 27 ++++++++++++-------------- src/plugin.h | 29 ++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 43 deletions(-) rename src/{lammpsplugin.cpp => plugin.cpp} (81%) create mode 100644 src/plugin.h diff --git a/examples/plugins/morse2plugin.cpp b/examples/plugins/morse2plugin.cpp index fbb0882a92..d7290edfb0 100644 --- a/examples/plugins/morse2plugin.cpp +++ b/examples/plugins/morse2plugin.cpp @@ -22,19 +22,21 @@ static Pair *morse2ompcreator(LAMMPS *lmp) } static lammpsplugin_t plugin; -void lammpsplugin_init(void *lmp) +extern "C" void lammpsplugin_init(void *lmp, void *handle, lammpsplugin_regfunc register_plugin) { memset(&plugin,0,sizeof(lammpsplugin_t)); plugin.version = LAMMPS_VERSION; plugin.style = "pair"; plugin.name = "morse2"; - plugin.info = "Morse2 variant pair style v1.0 by Axel Kohlmeyer"; + plugin.info = "Morse2 variant pair style v1.0"; + plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; plugin.creator = (lammpsplugin_factory *) &morse2creator; - lammpsplugin_register(&plugin, (LAMMPS *)lmp); + plugin.handle = handle; + register_plugin(&plugin,lmp); plugin.style = "pair"; plugin.name = "morse2/omp"; - plugin.info = "Morse2 variant pair style for OpenMP v1.0 by Axel Kohlmeyer"; + plugin.info = "Morse2 variant pair style for OpenMP v1.0"; plugin.creator = (lammpsplugin_factory *) &morse2ompcreator; - lammpsplugin_register(&plugin, (LAMMPS *)lmp); + register_plugin(&plugin,lmp); } diff --git a/src/input.cpp b/src/input.cpp index 07e3c417f6..73a73cd369 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -29,13 +29,13 @@ #include "group.h" #include "improper.h" #include "kspace.h" -#include "lammpsplugin.h" #include "memory.h" #include "min.h" #include "modify.h" #include "neighbor.h" #include "output.h" #include "pair.h" +#include "plugin.h" #include "special.h" #include "style_command.h" #include "thermo.h" @@ -1106,16 +1106,16 @@ void Input::plugin() if (cmd == "load") { if (narg < 2) error->all(FLERR,"Illegal plugin load command"); for (int i=1; i < narg; ++i) - lammpsplugin_load(arg[i],lmp); + plugin_load(arg[i],lmp); } else if (cmd == "unload") { if (narg != 3) error->all(FLERR,"Illegal plugin unload command"); - lammpsplugin_unload(arg[1],arg[2],lmp); + plugin_unload(arg[1],arg[2],lmp); } else if (cmd == "list") { if (comm->me == 0) { - int num = lammpsplugin_get_num_plugins(); + int num = plugin_get_num_plugins(); utils::logmesg(lmp,"Currently loaded plugins\n"); for (int i=0; i < num; ++i) { - auto entry = lammpsplugin_info(i); + auto entry = plugin_info(i); utils::logmesg(lmp,fmt::format("{:4}: {} style plugin {}\n", i+1,entry->style,entry->name)); } diff --git a/src/lammpsplugin.h b/src/lammpsplugin.h index 36c442aa5e..6cdf67e09b 100644 --- a/src/lammpsplugin.h +++ b/src/lammpsplugin.h @@ -14,41 +14,29 @@ #ifndef LMP_LAMMPSPLUGIN_H #define LMP_LAMMPSPLUGIN_H -// C style API and data structures required for dynamic loading +// C style API and data structure required for dynamic loading extern "C" { typedef void *(lammpsplugin_factory)(void *); - typedef void (*lammpsplugin_initfunc)(void *); typedef struct { const char *version; const char *style; const char *name; const char *info; + const char *author; lammpsplugin_factory *creator; + void *handle; } lammpsplugin_t; - typedef struct { - const char *style; - const char *name; - const void *handle; - } lammpsplugin_entry_t; + typedef void (*lammpsplugin_regfunc)(lammpsplugin_t *, void *); + typedef void (*lammpsplugin_initfunc)(void *, void *, lammpsplugin_regfunc); // prototype for initializer function required // to load a plugin; uses C bindings - void lammpsplugin_init(void *); -} - -namespace LAMMPS_NS -{ - extern void lammpsplugin_load(const char *, void *); - extern void lammpsplugin_register(lammpsplugin_t *, void *); - extern int lammpsplugin_get_num_plugins(); - extern const lammpsplugin_entry_t *lammpsplugin_info(int); - extern int lammpsplugin_find(const char *, const char *); - extern void lammpsplugin_unload(const char *, const char *, void *); + void lammpsplugin_init(void *, void *, lammpsplugin_regfunc); } #endif diff --git a/src/lammpsplugin.cpp b/src/plugin.cpp similarity index 81% rename from src/lammpsplugin.cpp rename to src/plugin.cpp index 3086b829c0..f81c453afb 100644 --- a/src/lammpsplugin.cpp +++ b/src/plugin.cpp @@ -11,7 +11,7 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include "lammpsplugin.h" +#include "plugin.h" #include "error.h" #include "force.h" @@ -28,9 +28,9 @@ namespace LAMMPS_NS { - static std::vector pluginlist; + static std::vector pluginlist; - void lammpsplugin_load(const char *file, void *ptr) + void plugin_load(const char *file, void *ptr) { LAMMPS *lmp = (LAMMPS *)ptr; #if defined(WIN32) @@ -46,15 +46,15 @@ namespace LAMMPS_NS void *initfunc = dlsym(dso,"lammpsplugin_init"); if (initfunc == nullptr) { dlclose(dso); - utils::logmesg(lmp,fmt::format("Symbol lookup failure in file {}",file)); + utils::logmesg(lmp,fmt::format("Symbol lookup failure in file {}\n",file)); return; } - ((lammpsplugin_initfunc)(initfunc))(ptr); + ((lammpsplugin_initfunc)(initfunc))(ptr,dso,&plugin_register); // dlclose(dso); #endif } - void lammpsplugin_register(lammpsplugin_t *plugin, void *ptr) + void plugin_register(lammpsplugin_t *plugin, void *ptr) { LAMMPS *lmp = (LAMMPS *)ptr; @@ -64,11 +64,8 @@ namespace LAMMPS_NS "version {} loaded into LAMMPS " "version {}\n", plugin->info, plugin->version, lmp->version)); - lammpsplugin_entry_t entry; - entry.style = plugin->style; - entry.name = plugin->name; - entry.handle = nullptr; - pluginlist.push_back(entry); + + pluginlist.push_back(*plugin); std::string pstyle = plugin->style; if (pstyle == "pair") { @@ -81,19 +78,19 @@ namespace LAMMPS_NS } } - int lammpsplugin_get_num_plugins() + int plugin_get_num_plugins() { return pluginlist.size(); } - const lammpsplugin_entry_t *lammpsplugin_info(int idx) + const lammpsplugin_t *plugin_info(int idx) { if ((idx < 0) || idx >= pluginlist.size()) return nullptr; return &pluginlist[idx]; } - int lammpsplugin_find(const char *style, const char *name) + int plugin_find(const char *style, const char *name) { for (int i=0; i < pluginlist.size(); ++i) { if ((strcmp(style,pluginlist[i].style) == 0) @@ -103,7 +100,7 @@ namespace LAMMPS_NS return -1; } - void lammpsplugin_unload(const char *style, const char *name, void *ptr) + void plugin_unload(const char *style, const char *name, void *ptr) { LAMMPS *lmp = (LAMMPS *)ptr; std::string pstyle = style; diff --git a/src/plugin.h b/src/plugin.h new file mode 100644 index 0000000000..546ab2a644 --- /dev/null +++ b/src/plugin.h @@ -0,0 +1,29 @@ +/* -*- 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_PLUGIN_H +#define LMP_PLUGIN_H + +#include "lammpsplugin.h" + +namespace LAMMPS_NS +{ + void plugin_load(const char *, void *); + void plugin_register(lammpsplugin_t *, void *); + int plugin_get_num_plugins(); + const lammpsplugin_t *plugin_info(int); + int plugin_find(const char *, const char *); + void plugin_unload(const char *, const char *, void *); +} + +#endif From aed8608c7c008f5ae91e6c1a31803d5368df2e45 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 11:59:49 -0500 Subject: [PATCH 010/257] Unify dump cfg/gz and cfg/zstd tests --- unittest/formats/CMakeLists.txt | 16 +-- unittest/formats/compressed_dump_test.h | 19 +-- .../formats/test_dump_atom_compressed.cpp | 23 ++- unittest/formats/test_dump_cfg_compressed.cpp | 132 +++++++++++++++++ unittest/formats/test_dump_cfg_gz.cpp | 133 ------------------ unittest/formats/test_dump_cfg_zstd.cpp | 133 ------------------ 6 files changed, 160 insertions(+), 296 deletions(-) create mode 100644 unittest/formats/test_dump_cfg_compressed.cpp delete mode 100644 unittest/formats/test_dump_cfg_gz.cpp delete mode 100644 unittest/formats/test_dump_cfg_zstd.cpp diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index 7b19bfde46..cd02aed6b0 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -52,11 +52,10 @@ if(PKG_COMPRESS) set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") - add_executable(test_dump_cfg_gz test_dump_cfg_gz.cpp) - target_link_libraries(test_dump_cfg_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") + add_executable(test_dump_cfg_compressed test_dump_cfg_compressed.cpp) + target_link_libraries(test_dump_cfg_compressed PRIVATE lammps GTest::GMock GTest::GTest) + add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") add_executable(test_dump_xyz_gz test_dump_xyz_gz.cpp) target_link_libraries(test_dump_xyz_gz PRIVATE lammps GTest::GMock GTest::GTest) @@ -84,11 +83,8 @@ if(PKG_COMPRESS) set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") - add_executable(test_dump_cfg_zstd test_dump_cfg_zstd.cpp) - target_link_libraries(test_dump_cfg_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") add_executable(test_dump_xyz_zstd test_dump_xyz_zstd.cpp) target_link_libraries(test_dump_xyz_zstd PRIVATE lammps GTest::GMock GTest::GTest) diff --git a/unittest/formats/compressed_dump_test.h b/unittest/formats/compressed_dump_test.h index 80b8550060..c731a3b1b9 100644 --- a/unittest/formats/compressed_dump_test.h +++ b/unittest/formats/compressed_dump_test.h @@ -64,25 +64,28 @@ public: } void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string dump_modify_options, int ntimesteps) + std::string dump_options, std::string dump_modify_options, int ntimesteps) { generate_text_and_compressed_dump(text_file, compressed_file, + dump_options, dump_options, dump_modify_options, dump_modify_options, ntimesteps); } void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string text_options, std::string compressed_options, int ntimesteps) + std::string text_options, std::string compressed_options, + std::string text_modify_options, std::string compressed_modify_options, + int ntimesteps) { if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); + command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, text_options)); + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, compressed_options)); - if (!text_options.empty()) { - command(fmt::format("dump_modify id0 {}", text_options)); + if (!text_modify_options.empty()) { + command(fmt::format("dump_modify id0 {}", text_modify_options)); } - if (!compressed_options.empty()) { - command(fmt::format("dump_modify id1 {}", compressed_options)); + if (!compressed_modify_options.empty()) { + command(fmt::format("dump_modify id1 {}", compressed_modify_options)); } command(fmt::format("run {}", ntimesteps)); diff --git a/unittest/formats/test_dump_atom_compressed.cpp b/unittest/formats/test_dump_atom_compressed.cpp index e33366801e..3360872f9e 100644 --- a/unittest/formats/test_dump_atom_compressed.cpp +++ b/unittest/formats/test_dump_atom_compressed.cpp @@ -40,7 +40,7 @@ TEST_F(DumpAtomCompressTest, compressed_run0) auto text_file = text_dump_filename("run0.melt"); auto compressed_file = compressed_dump_filename("run0.melt"); - generate_text_and_compressed_dump(text_file, compressed_file, "", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 0); TearDown(); @@ -71,7 +71,7 @@ TEST_F(DumpAtomCompressTest, compressed_multi_file_run1) auto compressed_file_0 = compressed_dump_filename(base_name_0); auto compressed_file_1 = compressed_dump_filename(base_name_1); - generate_text_and_compressed_dump(text_file, compressed_file, "", 1); + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 1); TearDown(); @@ -107,7 +107,7 @@ TEST_F(DumpAtomCompressTest, compressed_multi_file_with_pad_run1) auto compressed_file_0 = compressed_dump_filename(base_name_0); auto compressed_file_1 = compressed_dump_filename(base_name_1); - generate_text_and_compressed_dump(text_file, compressed_file, "pad 3", 1); + generate_text_and_compressed_dump(text_file, compressed_file, "", "pad 3", 1); TearDown(); @@ -151,7 +151,7 @@ TEST_F(DumpAtomCompressTest, compressed_multi_file_with_maxfiles_run1) auto compressed_file_1 = compressed_dump_filename(base_name_1); auto compressed_file_2 = compressed_dump_filename(base_name_2); - generate_text_and_compressed_dump(text_file, compressed_file, "maxfiles 2", 2); + generate_text_and_compressed_dump(text_file, compressed_file, "", "maxfiles 2", 2); TearDown(); @@ -188,8 +188,7 @@ TEST_F(DumpAtomCompressTest, compressed_with_units_run0) auto text_file = text_dump_filename(base_name); auto compressed_file = compressed_dump_filename(base_name); - generate_text_and_compressed_dump(text_file, compressed_file, "scale no units yes", - 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "scale no units yes", 0); TearDown(); @@ -213,7 +212,7 @@ TEST_F(DumpAtomCompressTest, compressed_with_time_run0) auto text_file = text_dump_filename(base_name); auto compressed_file = compressed_dump_filename(base_name); - generate_text_and_compressed_dump(text_file, compressed_file, "scale no time yes", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "scale no time yes", 0); TearDown(); @@ -238,7 +237,7 @@ TEST_F(DumpAtomCompressTest, compressed_triclinic_run0) auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 0); TearDown(); @@ -263,7 +262,7 @@ TEST_F(DumpAtomCompressTest, compressed_triclinic_with_units_run0) auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "scale no units yes", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "scale no units yes", 0); TearDown(); @@ -288,7 +287,7 @@ TEST_F(DumpAtomCompressTest, compressed_triclinic_with_time_run0) auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "scale no time yes", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "scale no time yes", 0); TearDown(); @@ -313,7 +312,7 @@ TEST_F(DumpAtomCompressTest, compressed_triclinic_with_image_run0) auto compressed_file = compressed_dump_filename(base_name); enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "image yes", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "image yes", 0); TearDown(); @@ -359,7 +358,7 @@ TEST_F(DumpAtomCompressTest, compressed_modify_clevel_run0) auto text_file = text_dump_filename(base_name); auto compressed_file = compressed_dump_filename(base_name); - generate_text_and_compressed_dump(text_file, compressed_file, "", "compression_level 3", 0); + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "compression_level 3", 0); TearDown(); diff --git a/unittest/formats/test_dump_cfg_compressed.cpp b/unittest/formats/test_dump_cfg_compressed.cpp new file mode 100644 index 0000000000..d06eabe57b --- /dev/null +++ b/unittest/formats/test_dump_cfg_compressed.cpp @@ -0,0 +1,132 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://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 "../testing/utils.h" +#include "compressed_dump_test.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + + +using ::testing::Eq; + +class DumpCfgCompressTest : public CompressedDumpTest { +public: + DumpCfgCompressTest() : CompressedDumpTest("cfg") { + } +}; + +//------------------------------------------------------------------------------------------------- +// compressed files +//------------------------------------------------------------------------------------------------- + +TEST_F(DumpCfgCompressTest, compressed_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "run*.melt.cfg"; + auto text_files = text_dump_filename(base_name); + auto compressed_files = compressed_dump_filename(base_name); + + auto base_name_0 = "run0.melt.cfg"; + auto text_file_0 = text_dump_filename(base_name_0); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + delete_file(compressed_file_0); + delete_file(converted_file_0); +} + +TEST_F(DumpCfgCompressTest, compressed_unwrap_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "unwrap_run*.melt.cfg"; + auto text_files = text_dump_filename(base_name); + auto compressed_files = compressed_dump_filename(base_name); + + auto base_name_0 = "unwrap_run0.melt.cfg"; + auto text_file_0 = text_dump_filename(base_name_0); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + delete_file(compressed_file_0); + delete_file(converted_file_0); +} + +int main(int argc, char **argv) +{ + MPI_Init(&argc, &argv); + ::testing::InitGoogleMock(&argc, argv); + + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + if(strcmp(argv[1], "gz") == 0) { + COMPRESS_SUFFIX = "gz"; + COMPRESS_EXTENSION = "gz"; + } else if(strcmp(argv[1], "zstd") == 0) { + COMPRESS_SUFFIX = "zstd"; + COMPRESS_EXTENSION = "zst"; + } else { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + COMPRESS_BINARY = getenv("COMPRESS_BINARY"); + + // handle arguments passed via environment variable + if (const char *var = getenv("TEST_ARGS")) { + std::vector env = utils::split_words(var); + for (auto arg : env) { + if (arg == "-v") { + verbose = true; + } + } + } + + if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; + + int rv = RUN_ALL_TESTS(); + MPI_Finalize(); + return rv; +} diff --git a/unittest/formats/test_dump_cfg_gz.cpp b/unittest/formats/test_dump_cfg_gz.cpp deleted file mode 100644 index ced307dc0a..0000000000 --- a/unittest/formats/test_dump_cfg_gz.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *GZIP_BINARY = nullptr; - -using ::testing::Eq; - -class DumpCfgGZTest : public MeltTest { - std::string dump_style = "cfg"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpCfgGZTest, compressed_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_files = "dump_cfg_gz_text_run*.melt.cfg"; - auto compressed_files = "dump_cfg_gz_compressed_run*.melt.cfg.gz"; - auto text_file = "dump_cfg_gz_text_run0.melt.cfg"; - auto compressed_file = "dump_cfg_gz_compressed_run0.melt.cfg.gz"; - auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_files, compressed_files, "cfg/gz", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpCfgGZTest, compressed_unwrap_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_files = "dump_cfg_unwrap_gz_text_run*.melt.cfg"; - auto compressed_files = "dump_cfg_unwrap_gz_compressed_run*.melt.cfg.gz"; - auto text_file = "dump_cfg_unwrap_gz_text_run0.melt.cfg"; - auto compressed_file = "dump_cfg_unwrap_gz_compressed_run0.melt.cfg.gz"; - auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_files, compressed_files, "cfg/gz", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - GZIP_BINARY = getenv("GZIP_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_cfg_zstd.cpp b/unittest/formats/test_dump_cfg_zstd.cpp deleted file mode 100644 index c13a3d5eaf..0000000000 --- a/unittest/formats/test_dump_cfg_zstd.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *ZSTD_BINARY = nullptr; - -using ::testing::Eq; - -class DumpCfgZstdTest : public MeltTest { - std::string dump_style = "cfg"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpCfgZstdTest, compressed_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_files = "dump_cfg_zstd_text_run*.melt.cfg"; - auto compressed_files = "dump_cfg_zstd_compressed_run*.melt.cfg.zst"; - auto text_file = "dump_cfg_zstd_text_run0.melt.cfg"; - auto compressed_file = "dump_cfg_zstd_compressed_run0.melt.cfg.zst"; - auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_files, compressed_files, "cfg/zstd", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpCfgZstdTest, compressed_unwrap_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_files = "dump_cfg_unwrap_zstd_text_run*.melt.cfg"; - auto compressed_files = "dump_cfg_unwrap_zstd_compressed_run*.melt.cfg.zst"; - auto text_file = "dump_cfg_unwrap_zstd_text_run0.melt.cfg"; - auto compressed_file = "dump_cfg_unwrap_zstd_compressed_run0.melt.cfg.zst"; - auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_files, compressed_files, "cfg/zstd", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} From 116ffd62dec936da768d31410c6db873fa3f354d Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 12:11:23 -0500 Subject: [PATCH 011/257] Unify dump custom/gz and custom/zstd tests --- unittest/formats/CMakeLists.txt | 24 ++- .../formats/test_dump_custom_compressed.cpp | 122 ++++++++++++++ unittest/formats/test_dump_custom_gz.cpp | 154 ------------------ unittest/formats/test_dump_custom_zstd.cpp | 154 ------------------ 4 files changed, 133 insertions(+), 321 deletions(-) create mode 100644 unittest/formats/test_dump_custom_compressed.cpp delete mode 100644 unittest/formats/test_dump_custom_gz.cpp delete mode 100644 unittest/formats/test_dump_custom_zstd.cpp diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index cd02aed6b0..7932c037fa 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -43,17 +43,18 @@ if(PKG_COMPRESS) add_executable(test_dump_atom_compressed test_dump_atom_compressed.cpp) target_link_libraries(test_dump_atom_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") - - add_executable(test_dump_custom_gz test_dump_custom_gz.cpp) - target_link_libraries(test_dump_custom_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpCustomGZ COMMAND test_dump_custom_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") + add_executable(test_dump_custom_compressed test_dump_custom_compressed.cpp) + target_link_libraries(test_dump_custom_compressed PRIVATE lammps GTest::GMock GTest::GTest) add_executable(test_dump_cfg_compressed test_dump_cfg_compressed.cpp) target_link_libraries(test_dump_cfg_compressed PRIVATE lammps GTest::GMock GTest::GTest) + + add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") + + add_test(NAME DumpCustomGZ COMMAND test_dump_custom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") + add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") @@ -77,11 +78,8 @@ if(PKG_COMPRESS) add_test(NAME DumpAtomZstd COMMAND test_dump_atom_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") - add_executable(test_dump_custom_zstd test_dump_custom_zstd.cpp) - target_link_libraries(test_dump_custom_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpCustomZstd COMMAND test_dump_custom_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpCustomZstd COMMAND test_dump_custom_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") diff --git a/unittest/formats/test_dump_custom_compressed.cpp b/unittest/formats/test_dump_custom_compressed.cpp new file mode 100644 index 0000000000..0afad264fb --- /dev/null +++ b/unittest/formats/test_dump_custom_compressed.cpp @@ -0,0 +1,122 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://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 "../testing/utils.h" +#include "compressed_dump_test.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + + +using ::testing::Eq; + +class DumpCustomCompressTest : public CompressedDumpTest { +public: + DumpCustomCompressTest() : CompressedDumpTest("custom") { + } +}; + +TEST_F(DumpCustomCompressTest, compressed_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "custom_run1.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "units yes", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + +TEST_F(DumpCustomCompressTest, compressed_triclinic_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "custom_tri_run1.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz"; + + enable_triclinic(); + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "units yes", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + +int main(int argc, char **argv) +{ + MPI_Init(&argc, &argv); + ::testing::InitGoogleMock(&argc, argv); + + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + if(strcmp(argv[1], "gz") == 0) { + COMPRESS_SUFFIX = "gz"; + COMPRESS_EXTENSION = "gz"; + } else if(strcmp(argv[1], "zstd") == 0) { + COMPRESS_SUFFIX = "zstd"; + COMPRESS_EXTENSION = "zst"; + } else { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + COMPRESS_BINARY = getenv("COMPRESS_BINARY"); + + // handle arguments passed via environment variable + if (const char *var = getenv("TEST_ARGS")) { + std::vector env = utils::split_words(var); + for (auto arg : env) { + if (arg == "-v") { + verbose = true; + } + } + } + + if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; + + int rv = RUN_ALL_TESTS(); + MPI_Finalize(); + return rv; +} diff --git a/unittest/formats/test_dump_custom_gz.cpp b/unittest/formats/test_dump_custom_gz.cpp deleted file mode 100644 index 67c9b535aa..0000000000 --- a/unittest/formats/test_dump_custom_gz.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -using ::testing::Eq; - -char *GZIP_BINARY = nullptr; - -class DumpCustomGZTest : public MeltTest { - std::string dump_style = "custom"; - -public: - void enable_triclinic() - { - if (!verbose) ::testing::internal::CaptureStdout(); - command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, - int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpCustomGZTest, compressed_run1) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_file = "dump_custom_gz_text_run1.melt"; - auto compressed_file = "dump_custom_gz_compressed_run1.melt.gz"; - auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes", - 1); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpCustomGZTest, compressed_triclinic_run1) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_file = "dump_custom_gz_tri_text_run1.melt"; - auto compressed_file = "dump_custom_gz_tri_compressed_run1.melt.gz"; - auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz"; - - enable_triclinic(); - - generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes", - 1); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - GZIP_BINARY = getenv("GZIP_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_custom_zstd.cpp b/unittest/formats/test_dump_custom_zstd.cpp deleted file mode 100644 index 40328d5592..0000000000 --- a/unittest/formats/test_dump_custom_zstd.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -using ::testing::Eq; - -char *ZSTD_BINARY = nullptr; - -class DumpCustomZstdTest : public MeltTest { - std::string dump_style = "custom"; - -public: - void enable_triclinic() - { - if (!verbose) ::testing::internal::CaptureStdout(); - command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, - int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpCustomZstdTest, compressed_run1) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_custom_zstd_text_run1.melt"; - auto compressed_file = "dump_custom_zstd_compressed_run1.melt.zst"; - auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields, - "units yes", 1); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpCustomZstdTest, compressed_triclinic_run1) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_custom_zstd_tri_text_run1.melt"; - auto compressed_file = "dump_custom_zstd_tri_compressed_run1.melt.zst"; - auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz"; - - enable_triclinic(); - - generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields, - "units yes", 1); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} From fca6d6bf8f6cda4226471bc0d9625a528a06bf4b Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 12:20:25 -0500 Subject: [PATCH 012/257] Unify dump local/gz and local/zstd tests --- unittest/formats/CMakeLists.txt | 21 ++-- .../formats/test_dump_local_compressed.cpp | 102 ++++++++++++++++ unittest/formats/test_dump_local_gz.cpp | 111 ------------------ unittest/formats/test_dump_local_zstd.cpp | 111 ------------------ 4 files changed, 111 insertions(+), 234 deletions(-) create mode 100644 unittest/formats/test_dump_local_compressed.cpp delete mode 100644 unittest/formats/test_dump_local_gz.cpp delete mode 100644 unittest/formats/test_dump_local_zstd.cpp diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index 7932c037fa..731e387fc2 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -49,6 +49,9 @@ if(PKG_COMPRESS) add_executable(test_dump_cfg_compressed test_dump_cfg_compressed.cpp) target_link_libraries(test_dump_cfg_compressed PRIVATE lammps GTest::GMock GTest::GTest) + add_executable(test_dump_local_compressed test_dump_local_compressed.cpp) + target_link_libraries(test_dump_local_compressed PRIVATE lammps GTest::GMock GTest::GTest) + add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") @@ -58,18 +61,15 @@ if(PKG_COMPRESS) add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") + add_test(NAME DumpLocalGZ COMMAND test_dump_local_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") + add_executable(test_dump_xyz_gz test_dump_xyz_gz.cpp) target_link_libraries(test_dump_xyz_gz PRIVATE lammps GTest::GMock GTest::GTest) add_test(NAME DumpXYZGZ COMMAND test_dump_xyz_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") - add_executable(test_dump_local_gz test_dump_local_gz.cpp) - target_link_libraries(test_dump_local_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpLocalGZ COMMAND test_dump_local_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") - find_package(PkgConfig REQUIRED) pkg_check_modules(Zstd IMPORTED_TARGET libzstd>=1.4) find_program(ZSTD_BINARY NAMES zstd) @@ -84,17 +84,14 @@ if(PKG_COMPRESS) add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpLocalZstd COMMAND test_dump_local_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") + add_executable(test_dump_xyz_zstd test_dump_xyz_zstd.cpp) target_link_libraries(test_dump_xyz_zstd PRIVATE lammps GTest::GMock GTest::GTest) add_test(NAME DumpXYZZstd COMMAND test_dump_xyz_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") - - add_executable(test_dump_local_zstd test_dump_local_zstd.cpp) - target_link_libraries(test_dump_local_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpLocalZstd COMMAND test_dump_local_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") endif() endif() diff --git a/unittest/formats/test_dump_local_compressed.cpp b/unittest/formats/test_dump_local_compressed.cpp new file mode 100644 index 0000000000..048053fb9a --- /dev/null +++ b/unittest/formats/test_dump_local_compressed.cpp @@ -0,0 +1,102 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://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 "../testing/utils.h" +#include "compressed_dump_test.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + + +using ::testing::Eq; + +class DumpLocalCompressTest : public CompressedDumpTest { +public: + DumpLocalCompressTest() : CompressedDumpTest("local") { + } +}; + +TEST_F(DumpLocalCompressTest, compressed_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + command("compute comp all pair/local dist eng"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + auto base_name = "run*.melt.local"; + auto base_name_0 = "run0.melt.local"; + auto text_files = text_dump_filename(base_name); + auto compressed_files = compressed_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto fields = "index c_comp[1]"; + + generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + delete_file(compressed_file_0); + delete_file(converted_file_0); +} + +int main(int argc, char **argv) +{ + MPI_Init(&argc, &argv); + ::testing::InitGoogleMock(&argc, argv); + + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + if(strcmp(argv[1], "gz") == 0) { + COMPRESS_SUFFIX = "gz"; + COMPRESS_EXTENSION = "gz"; + } else if(strcmp(argv[1], "zstd") == 0) { + COMPRESS_SUFFIX = "zstd"; + COMPRESS_EXTENSION = "zst"; + } else { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + COMPRESS_BINARY = getenv("COMPRESS_BINARY"); + + // handle arguments passed via environment variable + if (const char *var = getenv("TEST_ARGS")) { + std::vector env = utils::split_words(var); + for (auto arg : env) { + if (arg == "-v") { + verbose = true; + } + } + } + + if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; + + int rv = RUN_ALL_TESTS(); + MPI_Finalize(); + return rv; +} diff --git a/unittest/formats/test_dump_local_gz.cpp b/unittest/formats/test_dump_local_gz.cpp deleted file mode 100644 index 6ae25ae33d..0000000000 --- a/unittest/formats/test_dump_local_gz.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *GZIP_BINARY = nullptr; - -using ::testing::Eq; - -class DumpLocalGZTest : public MeltTest { - std::string dump_style = "local"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpLocalGZTest, compressed_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - if (!verbose) ::testing::internal::CaptureStdout(); - command("compute comp all pair/local dist eng"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - - auto text_files = "dump_local_gz_text_run*.melt.local"; - auto compressed_files = "dump_local_gz_compressed_run*.melt.local.gz"; - auto text_file = "dump_local_gz_text_run0.melt.local"; - auto compressed_file = "dump_local_gz_compressed_run0.melt.local.gz"; - auto fields = "index c_comp[1]"; - - generate_text_and_compressed_dump(text_files, compressed_files, "local/gz", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - GZIP_BINARY = getenv("GZIP_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_local_zstd.cpp b/unittest/formats/test_dump_local_zstd.cpp deleted file mode 100644 index 4a15baf4ca..0000000000 --- a/unittest/formats/test_dump_local_zstd.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *ZSTD_BINARY = nullptr; - -using ::testing::Eq; - -class DumpLocalGZTest : public MeltTest { - std::string dump_style = "local"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpLocalGZTest, compressed_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - if (!verbose) ::testing::internal::CaptureStdout(); - command("compute comp all pair/local dist eng"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - - auto text_files = "dump_local_zstd_text_run*.melt.local"; - auto compressed_files = "dump_local_zstd_compressed_run*.melt.local.zst"; - auto text_file = "dump_local_zstd_text_run0.melt.local"; - auto compressed_file = "dump_local_zstd_compressed_run0.melt.local.zst"; - auto fields = "index c_comp[1]"; - - generate_text_and_compressed_dump(text_files, compressed_files, "local/zstd", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} From 3ebc7823b0b52615d89408256c3b5ae4d100b557 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 12:28:56 -0500 Subject: [PATCH 013/257] Unify dump xyz/gz and xyz/zstd tests --- unittest/formats/CMakeLists.txt | 17 ++- unittest/formats/test_dump_xyz_compressed.cpp | 97 ++++++++++++++++ unittest/formats/test_dump_xyz_gz.cpp | 106 ------------------ unittest/formats/test_dump_xyz_zstd.cpp | 106 ------------------ 4 files changed, 104 insertions(+), 222 deletions(-) create mode 100644 unittest/formats/test_dump_xyz_compressed.cpp delete mode 100644 unittest/formats/test_dump_xyz_gz.cpp delete mode 100644 unittest/formats/test_dump_xyz_zstd.cpp diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index 731e387fc2..63c7759005 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -52,6 +52,9 @@ if(PKG_COMPRESS) add_executable(test_dump_local_compressed test_dump_local_compressed.cpp) target_link_libraries(test_dump_local_compressed PRIVATE lammps GTest::GMock GTest::GTest) + add_executable(test_dump_xyz_compressed test_dump_xyz_compressed.cpp) + target_link_libraries(test_dump_xyz_compressed PRIVATE lammps GTest::GMock GTest::GTest) + add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") @@ -64,11 +67,8 @@ if(PKG_COMPRESS) add_test(NAME DumpLocalGZ COMMAND test_dump_local_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") - add_executable(test_dump_xyz_gz test_dump_xyz_gz.cpp) - target_link_libraries(test_dump_xyz_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpXYZGZ COMMAND test_dump_xyz_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") + add_test(NAME DumpXYZGZ COMMAND test_dump_xyz_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") find_package(PkgConfig REQUIRED) pkg_check_modules(Zstd IMPORTED_TARGET libzstd>=1.4) @@ -87,11 +87,8 @@ if(PKG_COMPRESS) add_test(NAME DumpLocalZstd COMMAND test_dump_local_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") - add_executable(test_dump_xyz_zstd test_dump_xyz_zstd.cpp) - target_link_libraries(test_dump_xyz_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpXYZZstd COMMAND test_dump_xyz_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpXYZZstd COMMAND test_dump_xyz_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") endif() endif() diff --git a/unittest/formats/test_dump_xyz_compressed.cpp b/unittest/formats/test_dump_xyz_compressed.cpp new file mode 100644 index 0000000000..8f82ccebe2 --- /dev/null +++ b/unittest/formats/test_dump_xyz_compressed.cpp @@ -0,0 +1,97 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://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 "../testing/utils.h" +#include "compressed_dump_test.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + + +using ::testing::Eq; + +class DumpXYZCompressTest : public CompressedDumpTest { +public: + DumpXYZCompressTest() : CompressedDumpTest("xyz") { + } +}; + +TEST_F(DumpXYZCompressTest, compressed_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "run*.melt.xyz"; + auto base_name_0 = "run0.melt.xyz"; + auto text_files = text_dump_filename(base_name); + auto compressed_files = compressed_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + + generate_text_and_compressed_dump(text_files, compressed_files, "", "", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + delete_file(compressed_file_0); + delete_file(converted_file_0); +} + +int main(int argc, char **argv) +{ + MPI_Init(&argc, &argv); + ::testing::InitGoogleMock(&argc, argv); + + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + if(strcmp(argv[1], "gz") == 0) { + COMPRESS_SUFFIX = "gz"; + COMPRESS_EXTENSION = "gz"; + } else if(strcmp(argv[1], "zstd") == 0) { + COMPRESS_SUFFIX = "zstd"; + COMPRESS_EXTENSION = "zst"; + } else { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + COMPRESS_BINARY = getenv("COMPRESS_BINARY"); + + // handle arguments passed via environment variable + if (const char *var = getenv("TEST_ARGS")) { + std::vector env = utils::split_words(var); + for (auto arg : env) { + if (arg == "-v") { + verbose = true; + } + } + } + + if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; + + int rv = RUN_ALL_TESTS(); + MPI_Finalize(); + return rv; +} diff --git a/unittest/formats/test_dump_xyz_gz.cpp b/unittest/formats/test_dump_xyz_gz.cpp deleted file mode 100644 index aef54b4820..0000000000 --- a/unittest/formats/test_dump_xyz_gz.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *GZIP_BINARY = nullptr; - -using ::testing::Eq; - -class DumpXYZGZTest : public MeltTest { - std::string dump_style = "xyz"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpXYZGZTest, compressed_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_files = "dump_xyz_gz_text_run*.melt.xyz"; - auto compressed_files = "dump_xyz_gz_compressed_run*.melt.xyz.gz"; - auto text_file = "dump_xyz_gz_text_run0.melt.xyz"; - auto compressed_file = "dump_xyz_gz_compressed_run0.melt.xyz.gz"; - - generate_text_and_compressed_dump(text_files, compressed_files, "xyz/gz", "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - GZIP_BINARY = getenv("GZIP_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_xyz_zstd.cpp b/unittest/formats/test_dump_xyz_zstd.cpp deleted file mode 100644 index ce0b4ed143..0000000000 --- a/unittest/formats/test_dump_xyz_zstd.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://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 "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *ZSTD_BINARY = nullptr; - -using ::testing::Eq; - -class DumpXYZGZTest : public MeltTest { - std::string dump_style = "xyz"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpXYZGZTest, compressed_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_files = "dump_xyz_zstd_text_run*.melt.xyz"; - auto compressed_files = "dump_xyz_zstd_compressed_run*.melt.xyz.zst"; - auto text_file = "dump_xyz_zstd_text_run0.melt.xyz"; - auto compressed_file = "dump_xyz_zstd_compressed_run0.melt.xyz.zst"; - - generate_text_and_compressed_dump(text_files, compressed_files, "xyz/zstd", "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} From c5cb294506c478ea0f01c431a162626d4dff5fc3 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 12:42:19 -0500 Subject: [PATCH 014/257] Add other compression tests to xyz tests --- unittest/formats/test_dump_xyz_compressed.cpp | 170 ++++++++++++++++++ 1 file changed, 170 insertions(+) diff --git a/unittest/formats/test_dump_xyz_compressed.cpp b/unittest/formats/test_dump_xyz_compressed.cpp index 8f82ccebe2..b0ab846ba3 100644 --- a/unittest/formats/test_dump_xyz_compressed.cpp +++ b/unittest/formats/test_dump_xyz_compressed.cpp @@ -56,6 +56,176 @@ TEST_F(DumpXYZCompressTest, compressed_run0) delete_file(converted_file_0); } +TEST_F(DumpXYZCompressTest, compressed_multi_file_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_run1_*.melt.xyz"; + auto base_name_0 = "multi_file_run1_0.melt.xyz"; + auto base_name_1 = "multi_file_run1_1.melt.xyz"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 1); + + TearDown(); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpXYZCompressTest, compressed_multi_file_with_pad_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_pad_run1_*.melt.xyz"; + auto base_name_0 = "multi_file_pad_run1_000.melt.xyz"; + auto base_name_1 = "multi_file_pad_run1_001.melt.xyz"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpXYZCompressTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_maxfiles_run1_*.melt.xyz"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt.xyz"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt.xyz"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt.xyz"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + +TEST_F(DumpXYZCompressTest, compressed_modify_bad_param) +{ + if (compression_style != "xyz/gz") GTEST_SKIP(); + + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.xyz"))); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpXYZCompressTest, compressed_modify_multi_bad_param) +{ + if (compression_style != "xyz/gz") GTEST_SKIP(); + + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.xyz"))); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpXYZCompressTest, compressed_modify_clevel_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "modify_clevel_run0.melt.xyz"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file, Eq(converted_dump_filename(base_name))); + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + int main(int argc, char **argv) { MPI_Init(&argc, &argv); From 7e3d1923ab181b1d6bf8114d608b6db824c7bf0e Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 13:02:18 -0500 Subject: [PATCH 015/257] Add more compression tests for dump cfg --- unittest/formats/test_dump_cfg_compressed.cpp | 179 ++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/unittest/formats/test_dump_cfg_compressed.cpp b/unittest/formats/test_dump_cfg_compressed.cpp index d06eabe57b..b1eaaeee38 100644 --- a/unittest/formats/test_dump_cfg_compressed.cpp +++ b/unittest/formats/test_dump_cfg_compressed.cpp @@ -91,6 +91,185 @@ TEST_F(DumpCfgCompressTest, compressed_unwrap_run0) delete_file(converted_file_0); } +TEST_F(DumpCfgCompressTest, compressed_multi_file_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_run1_*.melt.cfg"; + auto base_name_0 = "multi_file_run1_0.melt.cfg"; + auto base_name_1 = "multi_file_run1_1.melt.cfg"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + + TearDown(); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpCfgCompressTest, compressed_multi_file_with_pad_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_pad_run1_*.melt.cfg"; + auto base_name_0 = "multi_file_pad_run1_000.melt.cfg"; + auto base_name_1 = "multi_file_pad_run1_001.melt.cfg"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpCfgCompressTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_maxfiles_run1_*.melt.cfg"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt.cfg"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt.cfg"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt.cfg"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + +TEST_F(DumpCfgCompressTest, compressed_modify_bad_param) +{ + if (compression_style != "cfg/gz") GTEST_SKIP(); + + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.cfg"), fields)); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpCfgCompressTest, compressed_modify_multi_bad_param) +{ + if (compression_style != "cfg/gz") GTEST_SKIP(); + + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.cfg"), fields)); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpCfgCompressTest, compressed_modify_clevel_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "modify_clevel_run*.melt.cfg"; + auto base_name_0 = "modify_clevel_run0.melt.cfg"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + delete_file(compressed_file_0); + delete_file(converted_file_0); +} + int main(int argc, char **argv) { MPI_Init(&argc, &argv); From f53fcf05456768ea1720fbfb05b19d6d5a5705f2 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 13:12:43 -0500 Subject: [PATCH 016/257] Add more compression tests for dump custom --- .../formats/test_dump_atom_compressed.cpp | 4 + unittest/formats/test_dump_cfg_compressed.cpp | 4 + .../formats/test_dump_custom_compressed.cpp | 176 ++++++++++++++++++ unittest/formats/test_dump_xyz_compressed.cpp | 4 + 4 files changed, 188 insertions(+) diff --git a/unittest/formats/test_dump_atom_compressed.cpp b/unittest/formats/test_dump_atom_compressed.cpp index 3360872f9e..c0d1f3bdb6 100644 --- a/unittest/formats/test_dump_atom_compressed.cpp +++ b/unittest/formats/test_dump_atom_compressed.cpp @@ -332,7 +332,9 @@ TEST_F(DumpAtomCompressTest, compressed_modify_bad_param) { if (compression_style != "atom/gz") GTEST_SKIP(); + if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt"))); + if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -343,7 +345,9 @@ TEST_F(DumpAtomCompressTest, compressed_modify_multi_bad_param) { if (compression_style != "atom/gz") GTEST_SKIP(); + if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt"))); + if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); diff --git a/unittest/formats/test_dump_cfg_compressed.cpp b/unittest/formats/test_dump_cfg_compressed.cpp index b1eaaeee38..66ab6921d5 100644 --- a/unittest/formats/test_dump_cfg_compressed.cpp +++ b/unittest/formats/test_dump_cfg_compressed.cpp @@ -222,7 +222,9 @@ TEST_F(DumpCfgCompressTest, compressed_modify_bad_param) if (compression_style != "cfg/gz") GTEST_SKIP(); auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.cfg"), fields)); + if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -234,7 +236,9 @@ TEST_F(DumpCfgCompressTest, compressed_modify_multi_bad_param) if (compression_style != "cfg/gz") GTEST_SKIP(); auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.cfg"), fields)); + if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); diff --git a/unittest/formats/test_dump_custom_compressed.cpp b/unittest/formats/test_dump_custom_compressed.cpp index 0afad264fb..8118442dbd 100644 --- a/unittest/formats/test_dump_custom_compressed.cpp +++ b/unittest/formats/test_dump_custom_compressed.cpp @@ -81,6 +81,182 @@ TEST_F(DumpCustomCompressTest, compressed_triclinic_run1) delete_file(converted_file); } +TEST_F(DumpCustomCompressTest, compressed_multi_file_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_run1_*.melt.custom"; + auto base_name_0 = "multi_file_run1_0.melt.custom"; + auto base_name_1 = "multi_file_run1_1.melt.custom"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + + TearDown(); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpCustomCompressTest, compressed_multi_file_with_pad_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_pad_run1_*.melt.custom"; + auto base_name_0 = "multi_file_pad_run1_000.melt.custom"; + auto base_name_1 = "multi_file_pad_run1_001.melt.custom"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpCustomCompressTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_maxfiles_run1_*.melt.custom"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt.custom"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt.custom"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt.custom"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + +TEST_F(DumpCustomCompressTest, compressed_modify_bad_param) +{ + if (compression_style != "custom/gz") GTEST_SKIP(); + + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.custom"), fields)); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpCustomCompressTest, compressed_modify_multi_bad_param) +{ + if (compression_style != "custom/gz") GTEST_SKIP(); + + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.custom"), fields)); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpCustomCompressTest, compressed_modify_clevel_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "modify_clevel_run0.melt.custom"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file, Eq(converted_dump_filename(base_name))); + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + int main(int argc, char **argv) { MPI_Init(&argc, &argv); diff --git a/unittest/formats/test_dump_xyz_compressed.cpp b/unittest/formats/test_dump_xyz_compressed.cpp index b0ab846ba3..9a61c746a0 100644 --- a/unittest/formats/test_dump_xyz_compressed.cpp +++ b/unittest/formats/test_dump_xyz_compressed.cpp @@ -183,7 +183,9 @@ TEST_F(DumpXYZCompressTest, compressed_modify_bad_param) { if (compression_style != "xyz/gz") GTEST_SKIP(); + if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.xyz"))); + if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -194,7 +196,9 @@ TEST_F(DumpXYZCompressTest, compressed_modify_multi_bad_param) { if (compression_style != "xyz/gz") GTEST_SKIP(); + if (!verbose) ::testing::internal::CaptureStdout(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.xyz"))); + if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); From 14da94d1893601894f39b86e252ead0eb2f3ec6a Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 13:27:54 -0500 Subject: [PATCH 017/257] Add more compression tests for dump local --- .../formats/test_dump_local_compressed.cpp | 194 +++++++++++++++++- 1 file changed, 190 insertions(+), 4 deletions(-) diff --git a/unittest/formats/test_dump_local_compressed.cpp b/unittest/formats/test_dump_local_compressed.cpp index 048053fb9a..b3c96b6edc 100644 --- a/unittest/formats/test_dump_local_compressed.cpp +++ b/unittest/formats/test_dump_local_compressed.cpp @@ -27,16 +27,20 @@ class DumpLocalCompressTest : public CompressedDumpTest { public: DumpLocalCompressTest() : CompressedDumpTest("local") { } + + void SetUp() override { + CompressedDumpTest::SetUp(); + + if (!verbose) ::testing::internal::CaptureStdout(); + command("compute comp all pair/local dist eng"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } }; TEST_F(DumpLocalCompressTest, compressed_run0) { if (!COMPRESS_BINARY) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); - command("compute comp all pair/local dist eng"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - auto base_name = "run*.melt.local"; auto base_name_0 = "run0.melt.local"; auto text_files = text_dump_filename(base_name); @@ -61,6 +65,188 @@ TEST_F(DumpLocalCompressTest, compressed_run0) delete_file(converted_file_0); } +TEST_F(DumpLocalCompressTest, compressed_multi_file_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_run1_*.melt.local"; + auto base_name_0 = "multi_file_run1_0.melt.local"; + auto base_name_1 = "multi_file_run1_1.melt.local"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto fields = "index c_comp[1]"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + + TearDown(); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpLocalCompressTest, compressed_multi_file_with_pad_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_pad_run1_*.melt.local"; + auto base_name_0 = "multi_file_pad_run1_000.melt.local"; + auto base_name_1 = "multi_file_pad_run1_001.melt.local"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto fields = "index c_comp[1]"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpLocalCompressTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_maxfiles_run1_*.melt.local"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt.local"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt.local"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt.local"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); + auto fields = "index c_comp[1]"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + +TEST_F(DumpLocalCompressTest, compressed_modify_bad_param) +{ + if (compression_style != "local/gz") GTEST_SKIP(); + + auto fields = "index c_comp[1]"; + + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.local"), fields)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpLocalCompressTest, compressed_modify_multi_bad_param) +{ + if (compression_style != "local/gz") GTEST_SKIP(); + + auto fields = "index c_comp[1]"; + + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.local"), fields)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpLocalCompressTest, compressed_modify_clevel_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "modify_clevel_run0.melt.local"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + auto fields = "index c_comp[1]"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file, Eq(converted_dump_filename(base_name))); + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + int main(int argc, char **argv) { MPI_Init(&argc, &argv); From ffda7fcc04f926821ccd87dbe7cd7a51ad5f13a7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 14:02:21 -0500 Subject: [PATCH 018/257] simpler interfaces --- examples/plugins/morse2plugin.cpp | 32 ++++++++++++++++--------------- src/lammpsplugin.h | 4 ++-- src/plugin.cpp | 27 +++++++++++++++++++------- src/plugin.h | 5 +++-- 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/examples/plugins/morse2plugin.cpp b/examples/plugins/morse2plugin.cpp index d7290edfb0..cfb6689cae 100644 --- a/examples/plugins/morse2plugin.cpp +++ b/examples/plugins/morse2plugin.cpp @@ -22,21 +22,23 @@ static Pair *morse2ompcreator(LAMMPS *lmp) } static lammpsplugin_t plugin; -extern "C" void lammpsplugin_init(void *lmp, void *handle, lammpsplugin_regfunc register_plugin) +extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) { - memset(&plugin,0,sizeof(lammpsplugin_t)); - plugin.version = LAMMPS_VERSION; - plugin.style = "pair"; - plugin.name = "morse2"; - plugin.info = "Morse2 variant pair style v1.0"; - plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; - plugin.creator = (lammpsplugin_factory *) &morse2creator; - plugin.handle = handle; - register_plugin(&plugin,lmp); + // register plain morse2 pair style + lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc; + memset(&plugin,0,sizeof(lammpsplugin_t)); + plugin.version = LAMMPS_VERSION; + plugin.style = "pair"; + plugin.name = "morse2"; + plugin.info = "Morse2 variant pair style v1.0"; + plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; + plugin.creator = (lammpsplugin_factory *) &morse2creator; + plugin.handle = handle; + register_plugin(&plugin,lmp); - plugin.style = "pair"; - plugin.name = "morse2/omp"; - plugin.info = "Morse2 variant pair style for OpenMP v1.0"; - plugin.creator = (lammpsplugin_factory *) &morse2ompcreator; - register_plugin(&plugin,lmp); + // also register morse2/omp pair style. only need to update changed fields + plugin.name = "morse2/omp"; + plugin.info = "Morse2 variant pair style for OpenMP v1.0"; + plugin.creator = (lammpsplugin_factory *) &morse2ompcreator; + register_plugin(&plugin,lmp); } diff --git a/src/lammpsplugin.h b/src/lammpsplugin.h index 6cdf67e09b..34a0b60811 100644 --- a/src/lammpsplugin.h +++ b/src/lammpsplugin.h @@ -31,12 +31,12 @@ extern "C" { } lammpsplugin_t; typedef void (*lammpsplugin_regfunc)(lammpsplugin_t *, void *); - typedef void (*lammpsplugin_initfunc)(void *, void *, lammpsplugin_regfunc); + typedef void (*lammpsplugin_initfunc)(void *, void *, void *); // prototype for initializer function required // to load a plugin; uses C bindings - void lammpsplugin_init(void *, void *, lammpsplugin_regfunc); + void lammpsplugin_init(void *, void *, void *); } #endif diff --git a/src/plugin.cpp b/src/plugin.cpp index f81c453afb..e978d90059 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -18,6 +18,7 @@ #include "lammps.h" #include "modify.h" +#include #include #ifdef _WIN32 @@ -28,14 +29,20 @@ namespace LAMMPS_NS { + // store list of plugin information data for loaded styles static std::vector pluginlist; + // map of dso handles + static std::map dso_refcounter; - void plugin_load(const char *file, void *ptr) + // load DSO and call included registration function + void plugin_load(const char *file, LAMMPS *lmp) { - LAMMPS *lmp = (LAMMPS *)ptr; #if defined(WIN32) utils::logmesg(lmp,"Loading of plugins not supported on Windows yet\n"); #else + + // open DSO from given path + void *dso = dlopen(file,RTLD_NOW|RTLD_GLOBAL); if (dso == nullptr) { utils::logmesg(lmp,fmt::format("Loading of plugin from file {} failed: " @@ -43,17 +50,23 @@ namespace LAMMPS_NS return; } + // look up lammpsplugin_init() function in DSO. must have C bindings. + void *initfunc = dlsym(dso,"lammpsplugin_init"); if (initfunc == nullptr) { dlclose(dso); utils::logmesg(lmp,fmt::format("Symbol lookup failure in file {}\n",file)); return; } - ((lammpsplugin_initfunc)(initfunc))(ptr,dso,&plugin_register); -// dlclose(dso); + + // call initializer function loaded from DSO and pass pointer to LAMMPS instance, + // the DSO handle (for reference counting) and plugin registration function pointer + + ((lammpsplugin_initfunc)(initfunc))((void *)lmp, dso, (void *)&plugin_register); #endif } + // register new style from plugin with LAMMPS void plugin_register(lammpsplugin_t *plugin, void *ptr) { LAMMPS *lmp = (LAMMPS *)ptr; @@ -99,10 +112,10 @@ namespace LAMMPS_NS } return -1; } - - void plugin_unload(const char *style, const char *name, void *ptr) + + // remove plugin from given style table + void plugin_unload(const char *style, const char *name, LAMMPS *lmp) { - LAMMPS *lmp = (LAMMPS *)ptr; std::string pstyle = style; if (pstyle == "pair") { auto found = lmp->force->pair_map->find(name); diff --git a/src/plugin.h b/src/plugin.h index 546ab2a644..051382ac27 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -18,12 +18,13 @@ namespace LAMMPS_NS { - void plugin_load(const char *, void *); + class LAMMPS; + void plugin_load(const char *, LAMMPS *); void plugin_register(lammpsplugin_t *, void *); int plugin_get_num_plugins(); const lammpsplugin_t *plugin_info(int); int plugin_find(const char *, const char *); - void plugin_unload(const char *, const char *, void *); + void plugin_unload(const char *, const char *, LAMMPS *); } #endif From 76d857e42888300efb128d201dbdf7fb0be72945 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 11 Mar 2021 14:21:16 -0500 Subject: [PATCH 019/257] Add more tests for COMPRESS package --- unittest/formats/CMakeLists.txt | 10 +-- unittest/formats/compressed_dump_test.h | 6 +- .../formats/compressed_dump_test_main.cpp | 66 +++++++++++++++++++ unittest/formats/test_dump_atom.cpp | 1 + .../formats/test_dump_atom_compressed.cpp | 52 +++------------ unittest/formats/test_dump_cfg.cpp | 2 + unittest/formats/test_dump_cfg_compressed.cpp | 52 +++------------ unittest/formats/test_dump_custom.cpp | 1 + .../formats/test_dump_custom_compressed.cpp | 52 +++------------ .../formats/test_dump_local_compressed.cpp | 52 +++------------ unittest/formats/test_dump_xyz_compressed.cpp | 52 +++------------ unittest/testing/core.h | 2 +- 12 files changed, 129 insertions(+), 219 deletions(-) create mode 100644 unittest/formats/compressed_dump_test_main.cpp diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index 63c7759005..be0d14c47d 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -40,19 +40,19 @@ set_tests_properties(DumpAtom PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS if(PKG_COMPRESS) find_program(GZIP_BINARY NAMES gzip REQUIRED) - add_executable(test_dump_atom_compressed test_dump_atom_compressed.cpp) + add_executable(test_dump_atom_compressed test_dump_atom_compressed.cpp compressed_dump_test_main.cpp) target_link_libraries(test_dump_atom_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_executable(test_dump_custom_compressed test_dump_custom_compressed.cpp) + add_executable(test_dump_custom_compressed test_dump_custom_compressed.cpp compressed_dump_test_main.cpp) target_link_libraries(test_dump_custom_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_executable(test_dump_cfg_compressed test_dump_cfg_compressed.cpp) + add_executable(test_dump_cfg_compressed test_dump_cfg_compressed.cpp compressed_dump_test_main.cpp) target_link_libraries(test_dump_cfg_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_executable(test_dump_local_compressed test_dump_local_compressed.cpp) + add_executable(test_dump_local_compressed test_dump_local_compressed.cpp compressed_dump_test_main.cpp) target_link_libraries(test_dump_local_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_executable(test_dump_xyz_compressed test_dump_xyz_compressed.cpp) + add_executable(test_dump_xyz_compressed test_dump_xyz_compressed.cpp compressed_dump_test_main.cpp) target_link_libraries(test_dump_xyz_compressed PRIVATE lammps GTest::GMock GTest::GTest) add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/unittest/formats/compressed_dump_test.h b/unittest/formats/compressed_dump_test.h index c731a3b1b9..c8afb2aac3 100644 --- a/unittest/formats/compressed_dump_test.h +++ b/unittest/formats/compressed_dump_test.h @@ -17,9 +17,9 @@ #include "../testing/systems/melt.h" #include -const char * COMPRESS_SUFFIX = nullptr; -const char * COMPRESS_EXTENSION = nullptr; -char * COMPRESS_BINARY = nullptr; +extern const char * COMPRESS_SUFFIX; +extern const char * COMPRESS_EXTENSION; +extern char * COMPRESS_BINARY; class CompressedDumpTest : public MeltTest { protected: diff --git a/unittest/formats/compressed_dump_test_main.cpp b/unittest/formats/compressed_dump_test_main.cpp new file mode 100644 index 0000000000..e1334f1b9b --- /dev/null +++ b/unittest/formats/compressed_dump_test_main.cpp @@ -0,0 +1,66 @@ +/* ---------------------------------------------------------------------- + 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 "compressed_dump_test.h" +#include "../testing/utils.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + +const char * COMPRESS_SUFFIX = nullptr; +const char * COMPRESS_EXTENSION = nullptr; +char * COMPRESS_BINARY = nullptr; +bool verbose = false; + +int main(int argc, char **argv) +{ + MPI_Init(&argc, &argv); + ::testing::InitGoogleMock(&argc, argv); + + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + if(strcmp(argv[1], "gz") == 0) { + COMPRESS_SUFFIX = "gz"; + COMPRESS_EXTENSION = "gz"; + } else if(strcmp(argv[1], "zstd") == 0) { + COMPRESS_SUFFIX = "zstd"; + COMPRESS_EXTENSION = "zst"; + } else { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + COMPRESS_BINARY = getenv("COMPRESS_BINARY"); + + // handle arguments passed via environment variable + if (const char *var = getenv("TEST_ARGS")) { + std::vector env = utils::split_words(var); + for (auto arg : env) { + if (arg == "-v") { + verbose = true; + } + } + } + + if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; + + int rv = RUN_ALL_TESTS(); + MPI_Finalize(); + return rv; +} diff --git a/unittest/formats/test_dump_atom.cpp b/unittest/formats/test_dump_atom.cpp index 2472aabf2d..39cefdccea 100644 --- a/unittest/formats/test_dump_atom.cpp +++ b/unittest/formats/test_dump_atom.cpp @@ -24,6 +24,7 @@ using ::testing::Eq; char *BINARY2TXT_BINARY = nullptr; +bool verbose = false; class DumpAtomTest : public MeltTest { std::string dump_style = "atom"; diff --git a/unittest/formats/test_dump_atom_compressed.cpp b/unittest/formats/test_dump_atom_compressed.cpp index c0d1f3bdb6..ed591184c3 100644 --- a/unittest/formats/test_dump_atom_compressed.cpp +++ b/unittest/formats/test_dump_atom_compressed.cpp @@ -40,7 +40,11 @@ TEST_F(DumpAtomCompressTest, compressed_run0) auto text_file = text_dump_filename("run0.melt"); auto compressed_file = compressed_dump_filename("run0.melt"); - generate_text_and_compressed_dump(text_file, compressed_file, "", "", 0); + if(compression_style == "atom/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "checksum yes", 0); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 0); + } TearDown(); @@ -71,7 +75,11 @@ TEST_F(DumpAtomCompressTest, compressed_multi_file_run1) auto compressed_file_0 = compressed_dump_filename(base_name_0); auto compressed_file_1 = compressed_dump_filename(base_name_1); - generate_text_and_compressed_dump(text_file, compressed_file, "", "", 1); + if(compression_style == "atom/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 1); + } TearDown(); @@ -378,43 +386,3 @@ TEST_F(DumpAtomCompressTest, compressed_modify_clevel_run0) delete_file(compressed_file); delete_file(converted_file); } - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - if (argc < 2) { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - if(strcmp(argv[1], "gz") == 0) { - COMPRESS_SUFFIX = "gz"; - COMPRESS_EXTENSION = "gz"; - } else if(strcmp(argv[1], "zstd") == 0) { - COMPRESS_SUFFIX = "zstd"; - COMPRESS_EXTENSION = "zst"; - } else { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - COMPRESS_BINARY = getenv("COMPRESS_BINARY"); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_cfg.cpp b/unittest/formats/test_dump_cfg.cpp index a7f331a0d0..327a9caca7 100644 --- a/unittest/formats/test_dump_cfg.cpp +++ b/unittest/formats/test_dump_cfg.cpp @@ -21,6 +21,8 @@ using ::testing::Eq; +bool verbose = false; + class DumpCfgTest : public MeltTest { std::string dump_style = "cfg"; diff --git a/unittest/formats/test_dump_cfg_compressed.cpp b/unittest/formats/test_dump_cfg_compressed.cpp index 66ab6921d5..834a71db70 100644 --- a/unittest/formats/test_dump_cfg_compressed.cpp +++ b/unittest/formats/test_dump_cfg_compressed.cpp @@ -46,7 +46,11 @@ TEST_F(DumpCfgCompressTest, compressed_run0) auto compressed_file_0 = compressed_dump_filename(base_name_0); auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + if(compression_style == "cfg/zstd") { + generate_text_and_compressed_dump(text_files, compressed_files, fields, fields, "", "checksum yes", 0); + } else { + generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + } TearDown(); @@ -106,7 +110,11 @@ TEST_F(DumpCfgCompressTest, compressed_multi_file_run1) auto compressed_file_1 = compressed_dump_filename(base_name_1); auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + if(compression_style == "cfg/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + } TearDown(); @@ -273,43 +281,3 @@ TEST_F(DumpCfgCompressTest, compressed_modify_clevel_run0) delete_file(compressed_file_0); delete_file(converted_file_0); } - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - if (argc < 2) { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - if(strcmp(argv[1], "gz") == 0) { - COMPRESS_SUFFIX = "gz"; - COMPRESS_EXTENSION = "gz"; - } else if(strcmp(argv[1], "zstd") == 0) { - COMPRESS_SUFFIX = "zstd"; - COMPRESS_EXTENSION = "zst"; - } else { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - COMPRESS_BINARY = getenv("COMPRESS_BINARY"); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_custom.cpp b/unittest/formats/test_dump_custom.cpp index dee27d9f0d..f2d7935426 100644 --- a/unittest/formats/test_dump_custom.cpp +++ b/unittest/formats/test_dump_custom.cpp @@ -22,6 +22,7 @@ using ::testing::Eq; char *BINARY2TXT_BINARY = nullptr; +bool verbose = false; class DumpCustomTest : public MeltTest { std::string dump_style = "custom"; diff --git a/unittest/formats/test_dump_custom_compressed.cpp b/unittest/formats/test_dump_custom_compressed.cpp index 8118442dbd..fb70206590 100644 --- a/unittest/formats/test_dump_custom_compressed.cpp +++ b/unittest/formats/test_dump_custom_compressed.cpp @@ -38,7 +38,11 @@ TEST_F(DumpCustomCompressTest, compressed_run1) auto compressed_file = compressed_dump_filename(base_name); auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; - generate_text_and_compressed_dump(text_file, compressed_file, fields, "units yes", 1); + if(compression_style == "custom/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "units yes", "units yes checksum yes", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, fields, "units yes", 1); + } TearDown(); @@ -96,7 +100,11 @@ TEST_F(DumpCustomCompressTest, compressed_multi_file_run1) auto compressed_file_1 = compressed_dump_filename(base_name_1); auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; - generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + if(compression_style == "custom/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + } TearDown(); @@ -256,43 +264,3 @@ TEST_F(DumpCustomCompressTest, compressed_modify_clevel_run0) delete_file(compressed_file); delete_file(converted_file); } - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - if (argc < 2) { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - if(strcmp(argv[1], "gz") == 0) { - COMPRESS_SUFFIX = "gz"; - COMPRESS_EXTENSION = "gz"; - } else if(strcmp(argv[1], "zstd") == 0) { - COMPRESS_SUFFIX = "zstd"; - COMPRESS_EXTENSION = "zst"; - } else { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - COMPRESS_BINARY = getenv("COMPRESS_BINARY"); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_local_compressed.cpp b/unittest/formats/test_dump_local_compressed.cpp index b3c96b6edc..20f90984a1 100644 --- a/unittest/formats/test_dump_local_compressed.cpp +++ b/unittest/formats/test_dump_local_compressed.cpp @@ -49,7 +49,11 @@ TEST_F(DumpLocalCompressTest, compressed_run0) auto compressed_file_0 = compressed_dump_filename(base_name_0); auto fields = "index c_comp[1]"; - generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + if(compression_style == "local/zstd") { + generate_text_and_compressed_dump(text_files, compressed_files, fields, fields, "", "checksum yes", 0); + } else { + generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + } TearDown(); @@ -80,7 +84,11 @@ TEST_F(DumpLocalCompressTest, compressed_multi_file_run1) auto compressed_file_1 = compressed_dump_filename(base_name_1); auto fields = "index c_comp[1]"; - generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + if(compression_style == "local/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + } TearDown(); @@ -246,43 +254,3 @@ TEST_F(DumpLocalCompressTest, compressed_modify_clevel_run0) delete_file(compressed_file); delete_file(converted_file); } - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - if (argc < 2) { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - if(strcmp(argv[1], "gz") == 0) { - COMPRESS_SUFFIX = "gz"; - COMPRESS_EXTENSION = "gz"; - } else if(strcmp(argv[1], "zstd") == 0) { - COMPRESS_SUFFIX = "zstd"; - COMPRESS_EXTENSION = "zst"; - } else { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - COMPRESS_BINARY = getenv("COMPRESS_BINARY"); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_xyz_compressed.cpp b/unittest/formats/test_dump_xyz_compressed.cpp index 9a61c746a0..f80201872c 100644 --- a/unittest/formats/test_dump_xyz_compressed.cpp +++ b/unittest/formats/test_dump_xyz_compressed.cpp @@ -40,7 +40,11 @@ TEST_F(DumpXYZCompressTest, compressed_run0) auto text_file_0 = text_dump_filename(base_name_0); auto compressed_file_0 = compressed_dump_filename(base_name_0); - generate_text_and_compressed_dump(text_files, compressed_files, "", "", 0); + if(compression_style == "xyz/zstd") { + generate_text_and_compressed_dump(text_files, compressed_files, "", "", "", "checksum yes", 0); + } else { + generate_text_and_compressed_dump(text_files, compressed_files, "", "", 0); + } TearDown(); @@ -70,7 +74,11 @@ TEST_F(DumpXYZCompressTest, compressed_multi_file_run1) auto compressed_file_0 = compressed_dump_filename(base_name_0); auto compressed_file_1 = compressed_dump_filename(base_name_1); - generate_text_and_compressed_dump(text_file, compressed_file, "", "", 1); + if(compression_style == "xyz/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 1); + } TearDown(); @@ -229,43 +237,3 @@ TEST_F(DumpXYZCompressTest, compressed_modify_clevel_run0) delete_file(compressed_file); delete_file(converted_file); } - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - if (argc < 2) { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - if(strcmp(argv[1], "gz") == 0) { - COMPRESS_SUFFIX = "gz"; - COMPRESS_EXTENSION = "gz"; - } else if(strcmp(argv[1], "zstd") == 0) { - COMPRESS_SUFFIX = "zstd"; - COMPRESS_EXTENSION = "zst"; - } else { - std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; - return 1; - } - - COMPRESS_BINARY = getenv("COMPRESS_BINARY"); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/testing/core.h b/unittest/testing/core.h index 5852f7fd06..6243eb219e 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -39,7 +39,7 @@ using ::testing::MatchesRegex; } // whether to print verbose output (i.e. not capturing LAMMPS screen output). -bool verbose = false; +extern bool verbose; class LAMMPSTest : public ::testing::Test { public: From c78ddb29ddf72dc148e1615c02a6af1c30f0ac9d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 16:57:37 -0500 Subject: [PATCH 020/257] implement reference counting and means to close unused DSO. Must delete pair style when plugin version is in use --- src/input.cpp | 2 +- src/plugin.cpp | 80 ++++++++++++++++++++++++++++++++++++++++---------- src/plugin.h | 3 +- 3 files changed, 68 insertions(+), 17 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index 73a73cd369..6d1564ecb6 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1115,7 +1115,7 @@ void Input::plugin() int num = plugin_get_num_plugins(); utils::logmesg(lmp,"Currently loaded plugins\n"); for (int i=0; i < num; ++i) { - auto entry = plugin_info(i); + auto entry = plugin_get_info(i); utils::logmesg(lmp,fmt::format("{:4}: {} style plugin {}\n", i+1,entry->style,entry->name)); } diff --git a/src/plugin.cpp b/src/plugin.cpp index e978d90059..a3126b8acd 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -17,9 +17,10 @@ #include "force.h" #include "lammps.h" #include "modify.h" +#include "pair.h" #include -#include +#include #ifdef _WIN32 #include @@ -30,7 +31,7 @@ namespace LAMMPS_NS { // store list of plugin information data for loaded styles - static std::vector pluginlist; + static std::list pluginlist; // map of dso handles static std::map dso_refcounter; @@ -72,13 +73,18 @@ namespace LAMMPS_NS LAMMPS *lmp = (LAMMPS *)ptr; if (plugin == nullptr) return; - if (plugin->version) - utils::logmesg(lmp,fmt::format("Loading: {}\n compiled for LAMMPS " - "version {} loaded into LAMMPS " - "version {}\n", plugin->info, + utils::logmesg(lmp,fmt::format("Loading plugin: {} by {}\n", + plugin->info, plugin->author)); + if ((plugin->version) && (strcmp(plugin->version,lmp->version) != 0)) + utils::logmesg(lmp,fmt::format(" compiled for LAMMPS version {} " + "loaded into LAMMPS version {}\n", plugin->version, lmp->version)); - pluginlist.push_back(*plugin); + if (dso_refcounter.find(plugin->handle) != dso_refcounter.end()) { + ++ dso_refcounter[plugin->handle]; + } else { + dso_refcounter[plugin->handle] = 1; + } std::string pstyle = plugin->style; if (pstyle == "pair") { @@ -96,32 +102,76 @@ namespace LAMMPS_NS return pluginlist.size(); } - const lammpsplugin_t *plugin_info(int idx) + const lammpsplugin_t *plugin_get_info(int idx) { - if ((idx < 0) || idx >= pluginlist.size()) return nullptr; - - return &pluginlist[idx]; + int i=0; + for (auto p=pluginlist.begin(); p != pluginlist.end(); ++p) { + if (i == idx) return &(*p); + ++i; + } + return nullptr; } int plugin_find(const char *style, const char *name) { - for (int i=0; i < pluginlist.size(); ++i) { - if ((strcmp(style,pluginlist[i].style) == 0) - && (strcmp(name,pluginlist[i].name) == 0)) + int i=0; + for (auto entry : pluginlist) { + if ((strcmp(style,entry.style) == 0) + && (strcmp(name,entry.name) == 0)) return i; + ++i; } return -1; } - // remove plugin from given style table + void plugin_erase(const char *style, const char *name) + { + fmt::print("Erasing {} style {} from list with {} plugins\n", + style, name, pluginlist.size()); + for (auto p=pluginlist.begin(); p != pluginlist.end(); ++p) { + if ((strcmp(style,p->style) == 0) + && (strcmp(name,p->name) == 0)) { + pluginlist.erase(p); + return; + } + } + } + + // remove plugin from given style table and plugin list. + // close dso handle if this is the last plugin from that dso. void plugin_unload(const char *style, const char *name, LAMMPS *lmp) { + int idx = plugin_find(style,name); + if (idx < 0) + lmp->error->all(FLERR,fmt::format("{} style {} is not loaded from " + "a plugin", style, name)); + auto plugin = plugin_get_info(idx); + void *handle = plugin->handle; + utils::logmesg(lmp,fmt::format("Unloading {} style {}\n",style,name)); + plugin_erase(style,name); + std::string pstyle = style; if (pstyle == "pair") { auto found = lmp->force->pair_map->find(name); if (found != lmp->force->pair_map->end()) { lmp->force->pair_map->erase(found); } + + // must delete pair style instance if in use + if (lmp->force->pair_style) { + if (utils::strmatch(lmp->force->pair_style,"^hybrid")) { + if (lmp->force->pair_match(name,1,1) != nullptr) + lmp->force->create_pair("none",0); + } else { + if (strcmp(lmp->force->pair_style,name) == 0) + lmp->force->create_pair("none",0); + } + } + } + + -- dso_refcounter[handle]; + if (dso_refcounter[handle] == 0) { + dlclose(handle); } } } diff --git a/src/plugin.h b/src/plugin.h index 051382ac27..172b2f0c37 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -22,8 +22,9 @@ namespace LAMMPS_NS void plugin_load(const char *, LAMMPS *); void plugin_register(lammpsplugin_t *, void *); int plugin_get_num_plugins(); - const lammpsplugin_t *plugin_info(int); + const lammpsplugin_t *plugin_get_info(int); int plugin_find(const char *, const char *); + void plugin_erase(const char *, const char *); void plugin_unload(const char *, const char *, LAMMPS *); } From b8ae2f5c6f3a4f4e53e19695733c696eb1e631d1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 17:41:08 -0500 Subject: [PATCH 021/257] add comments, extra checks, have output only on MPI rank 0 --- src/plugin.cpp | 123 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 86 insertions(+), 37 deletions(-) diff --git a/src/plugin.cpp b/src/plugin.cpp index a3126b8acd..1b9db01780 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -13,6 +13,7 @@ #include "plugin.h" +#include "comm.h" #include "error.h" #include "force.h" #include "lammps.h" @@ -38,16 +39,18 @@ namespace LAMMPS_NS // load DSO and call included registration function void plugin_load(const char *file, LAMMPS *lmp) { + int me = lmp->comm->me; #if defined(WIN32) - utils::logmesg(lmp,"Loading of plugins not supported on Windows yet\n"); + lmp->error->all(FLERR,"Loading of plugins on Windows not yet supported\n"); #else - // open DSO from given path + // open DSO file from given path load symbols globally void *dso = dlopen(file,RTLD_NOW|RTLD_GLOBAL); if (dso == nullptr) { - utils::logmesg(lmp,fmt::format("Loading of plugin from file {} failed: " - "{}", file, utils::getsyserror())); + if (me == 0) + utils::logmesg(lmp,fmt::format("Open of plugin file {} failed: {}", + file,utils::getsyserror())); return; } @@ -56,30 +59,44 @@ namespace LAMMPS_NS void *initfunc = dlsym(dso,"lammpsplugin_init"); if (initfunc == nullptr) { dlclose(dso); - utils::logmesg(lmp,fmt::format("Symbol lookup failure in file {}\n",file)); + if (me == 0) + utils::logmesg(lmp,fmt::format("Plugin symbol lookup failure in " + "file {}\n",file)); return; } - // call initializer function loaded from DSO and pass pointer to LAMMPS instance, - // the DSO handle (for reference counting) and plugin registration function pointer + // call initializer function loaded from DSO and pass a pointer + // to the LAMMPS instance, the DSO handle (for reference counting) + // and plugin registration function pointer - ((lammpsplugin_initfunc)(initfunc))((void *)lmp, dso, (void *)&plugin_register); + ((lammpsplugin_initfunc)(initfunc))((void *)lmp, dso, + (void *)&plugin_register); #endif } - // register new style from plugin with LAMMPS + // register a new style from a plugin with LAMMPS + // this is the callback function that is called from within + // the plugin initializer function. all plugin information + // is taken from the lammpsplugin_t struct. + void plugin_register(lammpsplugin_t *plugin, void *ptr) { LAMMPS *lmp = (LAMMPS *)ptr; + int me = lmp->comm->me; if (plugin == nullptr) return; - utils::logmesg(lmp,fmt::format("Loading plugin: {} by {}\n", - plugin->info, plugin->author)); - if ((plugin->version) && (strcmp(plugin->version,lmp->version) != 0)) - utils::logmesg(lmp,fmt::format(" compiled for LAMMPS version {} " - "loaded into LAMMPS version {}\n", - plugin->version, lmp->version)); + if (me == 0) { + utils::logmesg(lmp,fmt::format("Loading plugin: {} by {}\n", + plugin->info, plugin->author)); + // print version info only if the versions of host and plugin don't match + if ((plugin->version) && (strcmp(plugin->version,lmp->version) != 0)) + utils::logmesg(lmp,fmt::format(" compiled for LAMMPS version {} " + "loaded into LAMMPS version {}\n", + plugin->version, lmp->version)); + } + pluginlist.push_back(*plugin); + if (dso_refcounter.find(plugin->handle) != dso_refcounter.end()) { ++ dso_refcounter[plugin->handle]; } else { @@ -88,8 +105,15 @@ namespace LAMMPS_NS std::string pstyle = plugin->style; if (pstyle == "pair") { - (*(lmp->force->pair_map))[plugin->name] = - (LAMMPS_NS::Force::PairCreator)plugin->creator; + auto pair_map = lmp->force->pair_map; + if (pair_map->find(plugin->name) != pair_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR,fmt::format("Overriding built-in pair " + "style {} from plugin", + plugin->name)); + } + + (*pair_map)[plugin->name] = (Force::PairCreator)plugin->creator; } else { utils::logmesg(lmp,fmt::format("Loading plugin for {} styles not " "yet implemented\n", pstyle)); @@ -97,20 +121,14 @@ namespace LAMMPS_NS } } + // number of styles loaded from plugin files + int plugin_get_num_plugins() { return pluginlist.size(); } - const lammpsplugin_t *plugin_get_info(int idx) - { - int i=0; - for (auto p=pluginlist.begin(); p != pluginlist.end(); ++p) { - if (i == idx) return &(*p); - ++i; - } - return nullptr; - } + // return position index in list of given plugin of given style int plugin_find(const char *style, const char *name) { @@ -124,10 +142,22 @@ namespace LAMMPS_NS return -1; } + // get pointer to plugin initializer struct at position idx + + const lammpsplugin_t *plugin_get_info(int idx) + { + int i=0; + for (auto p=pluginlist.begin(); p != pluginlist.end(); ++p) { + if (i == idx) return &(*p); + ++i; + } + return nullptr; + } + + // remove plugin of given name and style from internal lists + void plugin_erase(const char *style, const char *name) { - fmt::print("Erasing {} style {} from list with {} plugins\n", - style, name, pluginlist.size()); for (auto p=pluginlist.begin(); p != pluginlist.end(); ++p) { if ((strcmp(style,p->style) == 0) && (strcmp(name,p->name) == 0)) { @@ -138,26 +168,43 @@ namespace LAMMPS_NS } // remove plugin from given style table and plugin list. - // close dso handle if this is the last plugin from that dso. + // optionally close the DSO handle if last plugin from that DSO + // must delete style instance if style is currently active. + void plugin_unload(const char *style, const char *name, LAMMPS *lmp) { + int me = lmp->comm->me; + + // ignore unload request if not loaded from a plugin int idx = plugin_find(style,name); - if (idx < 0) - lmp->error->all(FLERR,fmt::format("{} style {} is not loaded from " - "a plugin", style, name)); - auto plugin = plugin_get_info(idx); - void *handle = plugin->handle; - utils::logmesg(lmp,fmt::format("Unloading {} style {}\n",style,name)); + if (idx < 0) { + if (me == 0) + utils::logmesg(lmp,fmt::format("Ignoring unload of {} style {}: not " + "loaded from a plugin", style, name)); + return; + } + + // copy of DSO handle for later + void *handle = plugin_get_info(idx)->handle; + + // remove selected plugin from list of plugins + + if (me == 0) + utils::logmesg(lmp,fmt::format("Unloading {} style {}\n",style,name)); plugin_erase(style,name); + // remove style of given name from corresponding map + // must delete style instance if currently active so + // we can close the DSO handle if the last reference is gone. + std::string pstyle = style; if (pstyle == "pair") { auto found = lmp->force->pair_map->find(name); - if (found != lmp->force->pair_map->end()) { + if (found != lmp->force->pair_map->end()) lmp->force->pair_map->erase(found); - } // must delete pair style instance if in use + if (lmp->force->pair_style) { if (utils::strmatch(lmp->force->pair_style,"^hybrid")) { if (lmp->force->pair_match(name,1,1) != nullptr) @@ -169,6 +216,8 @@ namespace LAMMPS_NS } } + // if reference count is down to zero, close DSO handle. + -- dso_refcounter[handle]; if (dso_refcounter[handle] == 0) { dlclose(handle); From ee8246f590979e561562fdc621d9598d7004bd53 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 17:44:05 -0500 Subject: [PATCH 022/257] recover compilation on windows --- src/plugin.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugin.cpp b/src/plugin.cpp index 1b9db01780..19a5c1b754 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -58,7 +58,9 @@ namespace LAMMPS_NS void *initfunc = dlsym(dso,"lammpsplugin_init"); if (initfunc == nullptr) { +#ifndef WIN32 dlclose(dso); +#endif if (me == 0) utils::logmesg(lmp,fmt::format("Plugin symbol lookup failure in " "file {}\n",file)); From 3ec9f2fd5e0b72a942a91ca7ad78807c51b04279 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 17:44:11 -0500 Subject: [PATCH 023/257] whitespace --- src/plugin.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugin.cpp b/src/plugin.cpp index 19a5c1b754..7e7bd6e86f 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -33,7 +33,7 @@ namespace LAMMPS_NS { // store list of plugin information data for loaded styles static std::list pluginlist; - // map of dso handles + // map of dso handles static std::map dso_refcounter; // load DSO and call included registration function @@ -45,7 +45,7 @@ namespace LAMMPS_NS #else // open DSO file from given path load symbols globally - + void *dso = dlopen(file,RTLD_NOW|RTLD_GLOBAL); if (dso == nullptr) { if (me == 0) @@ -125,7 +125,7 @@ namespace LAMMPS_NS // number of styles loaded from plugin files - int plugin_get_num_plugins() + int plugin_get_num_plugins() { return pluginlist.size(); } @@ -210,7 +210,7 @@ namespace LAMMPS_NS if (lmp->force->pair_style) { if (utils::strmatch(lmp->force->pair_style,"^hybrid")) { if (lmp->force->pair_match(name,1,1) != nullptr) - lmp->force->create_pair("none",0); + lmp->force->create_pair("none",0); } else { if (strcmp(lmp->force->pair_style,name) == 0) lmp->force->create_pair("none",0); From c61de8740c65c8f9555cc08ac6d23fc281a52d4e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 19:33:07 -0500 Subject: [PATCH 024/257] add preliminary documentation for plugin command and about how to write plugins --- doc/src/Commands_all.rst | 1 + doc/src/Developer.rst | 1 + doc/src/Developer_plugins.rst | 98 +++++++++++++++++++++++++++++++++++ doc/src/commands_list.rst | 1 + 4 files changed, 101 insertions(+) create mode 100644 doc/src/Developer_plugins.rst diff --git a/doc/src/Commands_all.rst b/doc/src/Commands_all.rst index 132425948e..b43fd0ed56 100644 --- a/doc/src/Commands_all.rst +++ b/doc/src/Commands_all.rst @@ -86,6 +86,7 @@ An alphabetic list of all general LAMMPS commands. * :doc:`pair_style ` * :doc:`pair_write ` * :doc:`partition ` + * :doc:`plugin ` * :doc:`prd ` * :doc:`print ` * :doc:`processors ` diff --git a/doc/src/Developer.rst b/doc/src/Developer.rst index 3a0c03b7ea..f54bc4152f 100644 --- a/doc/src/Developer.rst +++ b/doc/src/Developer.rst @@ -14,6 +14,7 @@ of time and requests from the LAMMPS user community. Developer_flow Developer_write Developer_notes + Developer_plugins Developer_unittest Classes Developer_utils diff --git a/doc/src/Developer_plugins.rst b/doc/src/Developer_plugins.rst new file mode 100644 index 0000000000..ffbcf8a667 --- /dev/null +++ b/doc/src/Developer_plugins.rst @@ -0,0 +1,98 @@ +Writing plugins +--------------- + +Plugins provide a mechanism to add functionality to a LAMMPS executable +without recompiling LAMMPS. This uses the operating system's +capability to load dynamic shared object (DSO) files in a way similar +shared libraries and then references specific functions those DSOs. +Any DSO file with plugins has to include an initialization function +with a specific name that has to follow specific rules. When loading +the DSO, this function is called and will then register the contained +plugin(s) with LAMMPS. + +From the programmer perspective this can work because of the object +oriented design where all pair style commands are derived from the class +Pair, all fix style commands from the class Fix and so on and only +functions from those base classes are called directly. When a +:doc:`pair_style` command or :doc:`fix` command is issued a new +instance of such a derived class is created. This is done by a +so-called factory function which is mapped to the style name. Thus +when, for example, the LAMMPS processes the command +``pair_style lj/cut 2.5``, LAMMPS will look up the factory function +for creating the ``PairLJCut`` class and then execute it. The return +value of that function is a ``Pair *`` pointer and the pointer will +be assigned to the location for the currently active pair style. + +A plugin thus has to implement such a factory function and register it +with LAMMPS so that it gets added to the map of available styles of +the given category. To register a plugin with LAMMPS an initialization +function has to be called that follows specific rules explained below. + + +As an example, for a hypothetical pair style "morse2" implemented in a +class ``PairMorse2`` in the files ``pair_morse2.h`` and +``pair_morse2.cpp`` the file with the factory function and initialization +function would look like this: + +.. code-block:: C++ + + #include "lammpsplugin.h" + #include "version.h" + #include "pair_morse2.h" + + using namespace LAMMPS_NS; + + static Pair *morse2creator(LAMMPS *lmp) + { + return new PairMorse2(lmp); + } + + extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) + { + lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc; + lammpsplugin_t plugin; + + plugin.version = LAMMPS_VERSION; + plugin.style = "pair"; + plugin.name = "morse2"; + plugin.info = "Morse2 variant pair style v1.0"; + plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; + plugin.creator = (lammpsplugin_factory *) &morse2creator; + plugin.handle = handle; + (*register_plugin)(&plugin,lmp); + } + +The factory function in this example is called ``morse2creator()``. It +receives a pointer to the LAMMPS class as argument and returns a +pointer to the allocated class instance derived from the ``Pair`` class. +This function may be declared static to avoid clashes with other plugins. +The name of the derived class, ``PairMorse2``, must be unique inside +the entire LAMMPS executable. + +The initialization function **must** be called ``lammpsplugin_init``, it +**must** have C bindings and it takes three void pointers as arguments. +The first is a pointer to the LAMMPS class that calls it and it needs to +be passed to the registration function. The second argument is a +pointer to the internal handle of the DSO file, this needs to added to +the plugin info struct, so that the DSO can be close and unloaded when +all its contained plugins are unloaded. The third argument is a +function pointer to the registration function and needs to be stored +in a variable of ``lammpsplugin_regfunc`` type. + +To register a plugin a struct of the ``lammpsplugin_t`` needs to be filled +with relevant info: current LAMMPS version string, kind of style, name of +style, info string, author string, pointer to factory function, DSO handle. +The the registration function is called with a pointer to the address of +this struct and the pointer of the LAMMPS class. The registration function +will then add the factory function of the plugin style to the respective +style map under the provided name. It will also make a copy of the struct +in a list of all loaded plugins and update the reference counter for loaded +plugins from this specific DSO file. + +The pair style itself (i.e. the PairMorse2 class in this example) can be +written just like any other pair style that is included in LAMMPS. For +a plugin, the use of the ``PairStyle`` macro in the section encapsulated +by ``#ifdef PAIR_CLASS`` is not needed, since the mapping of the class +name to the style name is done by the plugin registration function with +the information from the ``lammpsplugin_t`` struct. It may be included +in case the new code is intended to be later included in LAMMPS directly. diff --git a/doc/src/commands_list.rst b/doc/src/commands_list.rst index 2ec20ac220..e30d5c52dc 100644 --- a/doc/src/commands_list.rst +++ b/doc/src/commands_list.rst @@ -77,6 +77,7 @@ Commands pair_style pair_write partition + plugin prd print processors From dfe4f7a49d353a22c1c9cd56f2027e0b3a9d9ef3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 19:33:50 -0500 Subject: [PATCH 025/257] small tweaks and simplify --- examples/plugins/morse2plugin.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/plugins/morse2plugin.cpp b/examples/plugins/morse2plugin.cpp index cfb6689cae..286aa30c35 100644 --- a/examples/plugins/morse2plugin.cpp +++ b/examples/plugins/morse2plugin.cpp @@ -1,7 +1,6 @@ #include "lammpsplugin.h" -#include "lammps.h" #include "version.h" #include @@ -21,12 +20,12 @@ static Pair *morse2ompcreator(LAMMPS *lmp) return new PairMorse2OMP(lmp); } -static lammpsplugin_t plugin; extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) { - // register plain morse2 pair style + lammpsplugin_t plugin; lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc; - memset(&plugin,0,sizeof(lammpsplugin_t)); + + // register plain morse2 pair style plugin.version = LAMMPS_VERSION; plugin.style = "pair"; plugin.name = "morse2"; @@ -34,11 +33,11 @@ extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; plugin.creator = (lammpsplugin_factory *) &morse2creator; plugin.handle = handle; - register_plugin(&plugin,lmp); + (*register_plugin)(&plugin,lmp); // also register morse2/omp pair style. only need to update changed fields plugin.name = "morse2/omp"; plugin.info = "Morse2 variant pair style for OpenMP v1.0"; plugin.creator = (lammpsplugin_factory *) &morse2ompcreator; - register_plugin(&plugin,lmp); + (*register_plugin)(&plugin,lmp); } From b252946fba664c51e92a508b49a96ffd0ace0717 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 19:34:13 -0500 Subject: [PATCH 026/257] now fix windows compile for real --- src/plugin.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugin.cpp b/src/plugin.cpp index 7e7bd6e86f..07e3c60dd0 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -222,7 +222,9 @@ namespace LAMMPS_NS -- dso_refcounter[handle]; if (dso_refcounter[handle] == 0) { +#ifndef WIN32 dlclose(handle); +#endif } } } From f982d98574269cd4e04db9616664f1758b1cb83d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 19:34:28 -0500 Subject: [PATCH 027/257] small tweaks --- examples/plugins/Makefile | 2 +- src/plugin.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/plugins/Makefile b/examples/plugins/Makefile index 2f563f924e..5d60ae8651 100644 --- a/examples/plugins/Makefile +++ b/examples/plugins/Makefile @@ -1,5 +1,5 @@ CXX=mpicxx -CXXFLAGS=-I../../src -Wall -O3 -fPIC -I../../src/USER-OMP -fopenmp +CXXFLAGS=-I../../src -Wall -Wextra -O3 -fPIC -I../../src/USER-OMP -fopenmp LD=$(CXX) -shared -rdynamic -fopenmp morse2plugin.so: morse2plugin.o pair_morse2.o pair_morse2_omp.o diff --git a/src/plugin.cpp b/src/plugin.cpp index 07e3c60dd0..f2499e6528 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -58,9 +58,8 @@ namespace LAMMPS_NS void *initfunc = dlsym(dso,"lammpsplugin_init"); if (initfunc == nullptr) { -#ifndef WIN32 dlclose(dso); -#endif + if (me == 0) utils::logmesg(lmp,fmt::format("Plugin symbol lookup failure in " "file {}\n",file)); @@ -182,7 +181,7 @@ namespace LAMMPS_NS if (idx < 0) { if (me == 0) utils::logmesg(lmp,fmt::format("Ignoring unload of {} style {}: not " - "loaded from a plugin", style, name)); + "loaded from a plugin\n", style, name)); return; } From 9209cbba92a9a271b8642a86b766b4e507f9d2ee Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 21:19:04 -0500 Subject: [PATCH 028/257] add support for loading plugins for fixes --- doc/src/Developer_plugins.rst | 41 ++++++- examples/plugins/Makefile | 8 ++ examples/plugins/fix_nve2.cpp | 171 ++++++++++++++++++++++++++++++ examples/plugins/fix_nve2.h | 58 ++++++++++ examples/plugins/morse2plugin.cpp | 5 +- examples/plugins/nve2plugin.cpp | 30 ++++++ src/lammpsplugin.h | 6 +- src/plugin.cpp | 14 ++- 8 files changed, 325 insertions(+), 8 deletions(-) create mode 100644 examples/plugins/fix_nve2.cpp create mode 100644 examples/plugins/fix_nve2.h create mode 100644 examples/plugins/nve2plugin.cpp diff --git a/doc/src/Developer_plugins.rst b/doc/src/Developer_plugins.rst index ffbcf8a667..59402165d1 100644 --- a/doc/src/Developer_plugins.rst +++ b/doc/src/Developer_plugins.rst @@ -57,17 +57,54 @@ function would look like this: plugin.name = "morse2"; plugin.info = "Morse2 variant pair style v1.0"; plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; - plugin.creator = (lammpsplugin_factory *) &morse2creator; + plugin.creator1 = (lammpsplugin_factory1 *) &morse2creator; + plugin.creator2 = nullptr; plugin.handle = handle; (*register_plugin)(&plugin,lmp); } The factory function in this example is called ``morse2creator()``. It -receives a pointer to the LAMMPS class as argument and returns a +receives a pointer to the LAMMPS class as only argument and thus has to +be assigned to the *creator1* member of the plugin struct and cast to the +``lammpsplugin_factory1`` pointer type. It returns a pointer to the allocated class instance derived from the ``Pair`` class. This function may be declared static to avoid clashes with other plugins. The name of the derived class, ``PairMorse2``, must be unique inside the entire LAMMPS executable. +If the factory function would be for a fix or compute, which take three +arguments (a pointer to the LAMMPS class, the number of arguments and the +list of argument strings), then the pointer type is ``lammpsplugin_factory2`` +and it must be assigned to the *creator2* member of the plugin struct. +Below is an example for that: + +.. code-block:: C++ + + #include "lammpsplugin.h" + #include "version.h" + #include "fix_nve2.h" + + using namespace LAMMPS_NS; + + static Fix *nve2creator(LAMMPS *lmp, int argc, char **argv) + { + return new FixNVE2(lmp,argc,argv); + } + + extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) + { + lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc; + lammpsplugin_t plugin; + + plugin.version = LAMMPS_VERSION; + plugin.style = "fix"; + plugin.name = "nve2"; + plugin.info = "NVE2 variant fix style v1.0"; + plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; + plugin.creator1 = nullptr; + plugin.creator2 = (lammpsplugin_factory2 *) &nve2creator; + plugin.handle = handle; + (*register_plugin)(&plugin,lmp); + } The initialization function **must** be called ``lammpsplugin_init``, it **must** have C bindings and it takes three void pointers as arguments. diff --git a/examples/plugins/Makefile b/examples/plugins/Makefile index 5d60ae8651..c8ec554d5d 100644 --- a/examples/plugins/Makefile +++ b/examples/plugins/Makefile @@ -2,9 +2,14 @@ CXX=mpicxx CXXFLAGS=-I../../src -Wall -Wextra -O3 -fPIC -I../../src/USER-OMP -fopenmp LD=$(CXX) -shared -rdynamic -fopenmp +default: morse2plugin.so nve2plugin.so + morse2plugin.so: morse2plugin.o pair_morse2.o pair_morse2_omp.o $(LD) -o $@ $^ +nve2plugin.so: nve2plugin.o fix_nve2.o + $(LD) -o $@ $^ + .cpp.o: $(CXX) -o $@ $(CXXFLAGS) -c $< @@ -12,6 +17,9 @@ pair_morse2.o: pair_morse2.cpp pair_morse2.h pair_morse2_omp.o: pair_morse2_omp.cpp pair_morse2_omp.h pair_morse2.h morse2plugin.o: morse2plugin.cpp pair_morse2.h pair_morse2_omp.h +fix_nve2.o: fix_nve2.cpp fix_nve2.h +nve2plugin.o: nve2plugin.cpp fix_nve2.h + clean: rm -f *~ *.so *.o log.lammps diff --git a/examples/plugins/fix_nve2.cpp b/examples/plugins/fix_nve2.cpp new file mode 100644 index 0000000000..bb6f53b810 --- /dev/null +++ b/examples/plugins/fix_nve2.cpp @@ -0,0 +1,171 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://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 "fix_nve2.h" +#include +#include "atom.h" +#include "force.h" +#include "update.h" +#include "respa.h" +#include "error.h" + +using namespace LAMMPS_NS; +using namespace FixConst; + +/* ---------------------------------------------------------------------- */ + +FixNVE2::FixNVE2(LAMMPS *lmp, int narg, char **arg) : + Fix(lmp, narg, arg) +{ + if (strcmp(style,"nve/sphere") != 0 && narg < 3) + error->all(FLERR,"Illegal fix nve command"); + + dynamic_group_allow = 1; + time_integrate = 1; +} + +/* ---------------------------------------------------------------------- */ + +int FixNVE2::setmask() +{ + int mask = 0; + mask |= INITIAL_INTEGRATE; + mask |= FINAL_INTEGRATE; + mask |= INITIAL_INTEGRATE_RESPA; + mask |= FINAL_INTEGRATE_RESPA; + return mask; +} + +/* ---------------------------------------------------------------------- */ + +void FixNVE2::init() +{ + dtv = update->dt; + dtf = 0.5 * update->dt * force->ftm2v; + + if (strstr(update->integrate_style,"respa")) + step_respa = ((Respa *) update->integrate)->step; +} + +/* ---------------------------------------------------------------------- + allow for both per-type and per-atom mass +------------------------------------------------------------------------- */ + +void FixNVE2::initial_integrate(int /*vflag*/) +{ + double dtfm; + + // update v and x of atoms in group + + double **x = atom->x; + double **v = atom->v; + double **f = atom->f; + double *rmass = atom->rmass; + double *mass = atom->mass; + int *type = atom->type; + int *mask = atom->mask; + int nlocal = atom->nlocal; + if (igroup == atom->firstgroup) nlocal = atom->nfirst; + + if (rmass) { + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit) { + dtfm = dtf / rmass[i]; + v[i][0] += dtfm * f[i][0]; + v[i][1] += dtfm * f[i][1]; + v[i][2] += dtfm * f[i][2]; + x[i][0] += dtv * v[i][0]; + x[i][1] += dtv * v[i][1]; + x[i][2] += dtv * v[i][2]; + } + + } else { + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit) { + dtfm = dtf / mass[type[i]]; + v[i][0] += dtfm * f[i][0]; + v[i][1] += dtfm * f[i][1]; + v[i][2] += dtfm * f[i][2]; + x[i][0] += dtv * v[i][0]; + x[i][1] += dtv * v[i][1]; + x[i][2] += dtv * v[i][2]; + } + } +} + +/* ---------------------------------------------------------------------- */ + +void FixNVE2::final_integrate() +{ + double dtfm; + + // update v of atoms in group + + double **v = atom->v; + double **f = atom->f; + double *rmass = atom->rmass; + double *mass = atom->mass; + int *type = atom->type; + int *mask = atom->mask; + int nlocal = atom->nlocal; + if (igroup == atom->firstgroup) nlocal = atom->nfirst; + + if (rmass) { + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit) { + dtfm = dtf / rmass[i]; + v[i][0] += dtfm * f[i][0]; + v[i][1] += dtfm * f[i][1]; + v[i][2] += dtfm * f[i][2]; + } + + } else { + for (int i = 0; i < nlocal; i++) + if (mask[i] & groupbit) { + dtfm = dtf / mass[type[i]]; + v[i][0] += dtfm * f[i][0]; + v[i][1] += dtfm * f[i][1]; + v[i][2] += dtfm * f[i][2]; + } + } +} + +/* ---------------------------------------------------------------------- */ + +void FixNVE2::initial_integrate_respa(int vflag, int ilevel, int /*iloop*/) +{ + dtv = step_respa[ilevel]; + dtf = 0.5 * step_respa[ilevel] * force->ftm2v; + + // innermost level - NVE update of v and x + // all other levels - NVE update of v + + if (ilevel == 0) initial_integrate(vflag); + else final_integrate(); +} + +/* ---------------------------------------------------------------------- */ + +void FixNVE2::final_integrate_respa(int ilevel, int /*iloop*/) +{ + dtf = 0.5 * step_respa[ilevel] * force->ftm2v; + final_integrate(); +} + +/* ---------------------------------------------------------------------- */ + +void FixNVE2::reset_dt() +{ + dtv = update->dt; + dtf = 0.5 * update->dt * force->ftm2v; +} diff --git a/examples/plugins/fix_nve2.h b/examples/plugins/fix_nve2.h new file mode 100644 index 0000000000..f1b2244128 --- /dev/null +++ b/examples/plugins/fix_nve2.h @@ -0,0 +1,58 @@ +/* -*- 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 FIX_CLASS + +FixStyle(nve2,FixNVE2) + +#else + +#ifndef LMP_FIX_NVE2_H +#define LMP_FIX_NVE2_H + +#include "fix.h" + +namespace LAMMPS_NS { + +class FixNVE2 : public Fix { + public: + FixNVE2(class LAMMPS *, int, char **); + virtual ~FixNVE2() {} + int setmask(); + virtual void init(); + virtual void initial_integrate(int); + virtual void final_integrate(); + virtual void initial_integrate_respa(int, int, int); + virtual void final_integrate_respa(int, int); + virtual void reset_dt(); + + protected: + double dtv,dtf; + double *step_respa; + int mass_require; +}; + +} + +#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/examples/plugins/morse2plugin.cpp b/examples/plugins/morse2plugin.cpp index 286aa30c35..7151e35cd2 100644 --- a/examples/plugins/morse2plugin.cpp +++ b/examples/plugins/morse2plugin.cpp @@ -31,13 +31,14 @@ extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) plugin.name = "morse2"; plugin.info = "Morse2 variant pair style v1.0"; plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; - plugin.creator = (lammpsplugin_factory *) &morse2creator; + plugin.creator1 = (lammpsplugin_factory1 *) &morse2creator; + plugin.creator2 = nullptr; plugin.handle = handle; (*register_plugin)(&plugin,lmp); // also register morse2/omp pair style. only need to update changed fields plugin.name = "morse2/omp"; plugin.info = "Morse2 variant pair style for OpenMP v1.0"; - plugin.creator = (lammpsplugin_factory *) &morse2ompcreator; + plugin.creator1 = (lammpsplugin_factory1 *) &morse2ompcreator; (*register_plugin)(&plugin,lmp); } diff --git a/examples/plugins/nve2plugin.cpp b/examples/plugins/nve2plugin.cpp new file mode 100644 index 0000000000..9c9ce3d8d2 --- /dev/null +++ b/examples/plugins/nve2plugin.cpp @@ -0,0 +1,30 @@ + +#include "lammpsplugin.h" + +#include "version.h" + +#include + +#include "fix_nve2.h" + +using namespace LAMMPS_NS; + +static Fix *nve2creator(LAMMPS *lmp, int argc, char **argv) +{ + return new FixNVE2(lmp, argc, argv); +} + +extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) +{ + lammpsplugin_t plugin; + lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc; + + plugin.version = LAMMPS_VERSION; + plugin.style = "fix"; + plugin.name = "nve2"; + plugin.info = "NVE2 variant fix style v1.0"; + plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; + plugin.creator2 = (lammpsplugin_factory2 *) &nve2creator; + plugin.handle = handle; + (*register_plugin)(&plugin,lmp); +} diff --git a/src/lammpsplugin.h b/src/lammpsplugin.h index 34a0b60811..958235fdaa 100644 --- a/src/lammpsplugin.h +++ b/src/lammpsplugin.h @@ -18,7 +18,8 @@ extern "C" { - typedef void *(lammpsplugin_factory)(void *); + typedef void *(lammpsplugin_factory1)(void *); + typedef void *(lammpsplugin_factory2)(void *, int, char **); typedef struct { const char *version; @@ -26,7 +27,8 @@ extern "C" { const char *name; const char *info; const char *author; - lammpsplugin_factory *creator; + lammpsplugin_factory1 *creator1; + lammpsplugin_factory2 *creator2; void *handle; } lammpsplugin_t; diff --git a/src/plugin.cpp b/src/plugin.cpp index f2499e6528..7a42734bd9 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -114,10 +114,20 @@ namespace LAMMPS_NS plugin->name)); } - (*pair_map)[plugin->name] = (Force::PairCreator)plugin->creator; + (*pair_map)[plugin->name] = (Force::PairCreator)plugin->creator1; + } else if (pstyle == "fix") { + auto fix_map = lmp->modify->fix_map; + if (fix_map->find(plugin->name) != fix_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR,fmt::format("Overriding built-in fix " + "style {} from plugin", + plugin->name)); + } + + (*fix_map)[plugin->name] = (Modify::FixCreator)plugin->creator2; } else { utils::logmesg(lmp,fmt::format("Loading plugin for {} styles not " - "yet implemented\n", pstyle)); + "yet implemented\n",pstyle)); pluginlist.pop_back(); } } From 3d1c6b30af02a2e375be66de98180d6609bf6fab Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 21:19:29 -0500 Subject: [PATCH 029/257] refuse to load a plugin over an existing plugin for the same style --- src/plugin.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/plugin.cpp b/src/plugin.cpp index 7a42734bd9..d2ea0943ad 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -86,14 +86,25 @@ namespace LAMMPS_NS int me = lmp->comm->me; if (plugin == nullptr) return; + + // ignore load request if same plugin already loaded + int idx = plugin_find(plugin->style,plugin->name); + if (idx >= 0) { + if (me == 0) + utils::logmesg(lmp,fmt::format("Ignoring load of {} style {}: must " + "unload existing {} plugin first\n", + plugin->style,plugin->name,plugin->name)); + return; + } + if (me == 0) { utils::logmesg(lmp,fmt::format("Loading plugin: {} by {}\n", - plugin->info, plugin->author)); + plugin->info,plugin->author)); // print version info only if the versions of host and plugin don't match if ((plugin->version) && (strcmp(plugin->version,lmp->version) != 0)) utils::logmesg(lmp,fmt::format(" compiled for LAMMPS version {} " "loaded into LAMMPS version {}\n", - plugin->version, lmp->version)); + plugin->version,lmp->version)); } pluginlist.push_back(*plugin); @@ -191,7 +202,7 @@ namespace LAMMPS_NS if (idx < 0) { if (me == 0) utils::logmesg(lmp,fmt::format("Ignoring unload of {} style {}: not " - "loaded from a plugin\n", style, name)); + "loaded from a plugin\n",style,name)); return; } From 620dd09509b9ec7cbecbe1c0acc971e242617f19 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 21:36:14 -0500 Subject: [PATCH 030/257] delete active fixes when unloading fix style plugin --- src/plugin.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugin.cpp b/src/plugin.cpp index d2ea0943ad..0eece6793e 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -236,6 +236,10 @@ namespace LAMMPS_NS lmp->force->create_pair("none",0); } } + } else if (pstyle == "fix") { + for (int ifix = lmp->modify->find_fix_by_style(name); + ifix >= 0; ifix = lmp->modify->find_fix_by_style(name)) + lmp->modify->delete_fix(ifix); } // if reference count is down to zero, close DSO handle. From 347db1458daa89f5ec9ef743d32c625f2b3aaf1e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 22:34:23 -0500 Subject: [PATCH 031/257] always link with libdl.so/.a or equivalent except on windows --- cmake/CMakeLists.txt | 5 +++++ cmake/Modules/Packages/USER-MOLFILE.cmake | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 06600d02c4..7081d6aa80 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -240,6 +240,11 @@ if(BUILD_OMP) target_link_libraries(lammps PRIVATE OpenMP::OpenMP_CXX) endif() +# link with -ldl or equivalent for plugin loading; except on Windows +if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + target_link_libraries(lammps PRIVATE ${CMAKE_DL_LIBS}) +endif() + # Compiler specific features for testing if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") option(ENABLE_COVERAGE "Enable collecting code coverage data" OFF) diff --git a/cmake/Modules/Packages/USER-MOLFILE.cmake b/cmake/Modules/Packages/USER-MOLFILE.cmake index 4d414acead..427f0ed6fa 100644 --- a/cmake/Modules/Packages/USER-MOLFILE.cmake +++ b/cmake/Modules/Packages/USER-MOLFILE.cmake @@ -2,8 +2,4 @@ set(MOLFILE_INCLUDE_DIR "${LAMMPS_LIB_SOURCE_DIR}/molfile" CACHE STRING "Path to set(MOLFILE_INCLUDE_DIRS "${MOLFILE_INCLUDE_DIR}") add_library(molfile INTERFACE) target_include_directories(molfile INTERFACE ${MOLFILE_INCLUDE_DIRS}) -# no need to link with -ldl on windows -if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") - target_link_libraries(molfile INTERFACE ${CMAKE_DL_LIBS}) -endif() target_link_libraries(lammps PRIVATE molfile) From 256c478a6bae76c044efb7c262e858b547f3c286 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 22:34:47 -0500 Subject: [PATCH 032/257] reorder functions and make header and implemention order consistent --- src/plugin.cpp | 132 +++++++++++++++++++++++++++---------------------- src/plugin.h | 11 +++-- 2 files changed, 80 insertions(+), 63 deletions(-) diff --git a/src/plugin.cpp b/src/plugin.cpp index 0eece6793e..85870952e9 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -31,9 +31,10 @@ namespace LAMMPS_NS { - // store list of plugin information data for loaded styles + // list of plugin information data for loaded styles static std::list pluginlist; - // map of dso handles + + // map for counting references to dso handles static std::map dso_refcounter; // load DSO and call included registration function @@ -44,7 +45,7 @@ namespace LAMMPS_NS lmp->error->all(FLERR,"Loading of plugins on Windows not yet supported\n"); #else - // open DSO file from given path load symbols globally + // open DSO file from given path; load symbols globally void *dso = dlopen(file,RTLD_NOW|RTLD_GLOBAL); if (dso == nullptr) { @@ -54,7 +55,8 @@ namespace LAMMPS_NS return; } - // look up lammpsplugin_init() function in DSO. must have C bindings. + // look up lammpsplugin_init() function in DSO + // function must have C bindings so there is no name mangling void *initfunc = dlsym(dso,"lammpsplugin_init"); if (initfunc == nullptr) { @@ -70,15 +72,17 @@ namespace LAMMPS_NS // to the LAMMPS instance, the DSO handle (for reference counting) // and plugin registration function pointer - ((lammpsplugin_initfunc)(initfunc))((void *)lmp, dso, - (void *)&plugin_register); + (*(lammpsplugin_initfunc)(initfunc))((void *)lmp, dso, + (void *)&plugin_register); #endif } - // register a new style from a plugin with LAMMPS - // this is the callback function that is called from within - // the plugin initializer function. all plugin information - // is taken from the lammpsplugin_t struct. + /* -------------------------------------------------------------------- + register a new style from a plugin with LAMMPS + this is the callback function that is called from within + the plugin initializer function. all plugin information + is taken from the lammpsplugin_t struct. + -------------------------------------------------------------------- */ void plugin_register(lammpsplugin_t *plugin, void *ptr) { @@ -143,55 +147,11 @@ namespace LAMMPS_NS } } - // number of styles loaded from plugin files - - int plugin_get_num_plugins() - { - return pluginlist.size(); - } - - // return position index in list of given plugin of given style - - int plugin_find(const char *style, const char *name) - { - int i=0; - for (auto entry : pluginlist) { - if ((strcmp(style,entry.style) == 0) - && (strcmp(name,entry.name) == 0)) - return i; - ++i; - } - return -1; - } - - // get pointer to plugin initializer struct at position idx - - const lammpsplugin_t *plugin_get_info(int idx) - { - int i=0; - for (auto p=pluginlist.begin(); p != pluginlist.end(); ++p) { - if (i == idx) return &(*p); - ++i; - } - return nullptr; - } - - // remove plugin of given name and style from internal lists - - void plugin_erase(const char *style, const char *name) - { - for (auto p=pluginlist.begin(); p != pluginlist.end(); ++p) { - if ((strcmp(style,p->style) == 0) - && (strcmp(name,p->name) == 0)) { - pluginlist.erase(p); - return; - } - } - } - - // remove plugin from given style table and plugin list. - // optionally close the DSO handle if last plugin from that DSO - // must delete style instance if style is currently active. + /* -------------------------------------------------------------------- + remove plugin from given style table and plugin list + optionally close the DSO handle if it is the last plugin from that DSO + must also delete style instances if style is currently active + -------------------------------------------------------------------- */ void plugin_unload(const char *style, const char *name, LAMMPS *lmp) { @@ -251,4 +211,58 @@ namespace LAMMPS_NS #endif } } + + /* -------------------------------------------------------------------- + remove plugin of given name and style from internal lists + -------------------------------------------------------------------- */ + + void plugin_erase(const char *style, const char *name) + { + for (auto p=pluginlist.begin(); p != pluginlist.end(); ++p) { + if ((strcmp(style,p->style) == 0) + && (strcmp(name,p->name) == 0)) { + pluginlist.erase(p); + return; + } + } + } + + /* -------------------------------------------------------------------- + number of styles loaded from plugin files + -------------------------------------------------------------------- */ + + int plugin_get_num_plugins() + { + return pluginlist.size(); + } + + /* -------------------------------------------------------------------- + return position index in list of given plugin of given style + -------------------------------------------------------------------- */ + + int plugin_find(const char *style, const char *name) + { + int i=0; + for (auto entry : pluginlist) { + if ((strcmp(style,entry.style) == 0) + && (strcmp(name,entry.name) == 0)) + return i; + ++i; + } + return -1; + } + + /* -------------------------------------------------------------------- + get pointer to plugin initializer struct at position idx + -------------------------------------------------------------------- */ + + const lammpsplugin_t *plugin_get_info(int idx) + { + int i=0; + for (auto p=pluginlist.begin(); p != pluginlist.end(); ++p) { + if (i == idx) return &(*p); + ++i; + } + return nullptr; + } } diff --git a/src/plugin.h b/src/plugin.h index 172b2f0c37..32a5a280a1 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -19,13 +19,16 @@ namespace LAMMPS_NS { class LAMMPS; + void plugin_load(const char *, LAMMPS *); void plugin_register(lammpsplugin_t *, void *); - int plugin_get_num_plugins(); - const lammpsplugin_t *plugin_get_info(int); - int plugin_find(const char *, const char *); - void plugin_erase(const char *, const char *); + void plugin_unload(const char *, const char *, LAMMPS *); + void plugin_erase(const char *, const char *); + + int plugin_get_num_plugins(); + int plugin_find(const char *, const char *); + const lammpsplugin_t *plugin_get_info(int); } #endif From 83583c465eb6f2b88d7eb12befb8b65e5065e508 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 22:58:22 -0500 Subject: [PATCH 033/257] add support for command plugins with example --- examples/plugins/Makefile | 8 +++-- examples/plugins/helloplugin.cpp | 49 +++++++++++++++++++++++++++++++ examples/plugins/morse2plugin.cpp | 1 + examples/plugins/nve2plugin.cpp | 2 ++ src/lammpsplugin.h | 2 ++ src/plugin.cpp | 15 ++++++++-- 6 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 examples/plugins/helloplugin.cpp diff --git a/examples/plugins/Makefile b/examples/plugins/Makefile index c8ec554d5d..bf6bc804be 100644 --- a/examples/plugins/Makefile +++ b/examples/plugins/Makefile @@ -2,7 +2,10 @@ CXX=mpicxx CXXFLAGS=-I../../src -Wall -Wextra -O3 -fPIC -I../../src/USER-OMP -fopenmp LD=$(CXX) -shared -rdynamic -fopenmp -default: morse2plugin.so nve2plugin.so +default: morse2plugin.so nve2plugin.so helloplugin.so + +helloplugin.so: helloplugin.o + $(LD) -o $@ $^ morse2plugin.so: morse2plugin.o pair_morse2.o pair_morse2_omp.o $(LD) -o $@ $^ @@ -13,6 +16,8 @@ nve2plugin.so: nve2plugin.o fix_nve2.o .cpp.o: $(CXX) -o $@ $(CXXFLAGS) -c $< +helloplugin.o: helloplugin.cpp + pair_morse2.o: pair_morse2.cpp pair_morse2.h pair_morse2_omp.o: pair_morse2_omp.cpp pair_morse2_omp.h pair_morse2.h morse2plugin.o: morse2plugin.cpp pair_morse2.h pair_morse2_omp.h @@ -23,4 +28,3 @@ nve2plugin.o: nve2plugin.cpp fix_nve2.h clean: rm -f *~ *.so *.o log.lammps - diff --git a/examples/plugins/helloplugin.cpp b/examples/plugins/helloplugin.cpp new file mode 100644 index 0000000000..1c9d0c2779 --- /dev/null +++ b/examples/plugins/helloplugin.cpp @@ -0,0 +1,49 @@ + +#include "lammpsplugin.h" + +#include "comm.h" +#include "error.h" +#include "pointers.h" +#include "version.h" + +#include + +namespace LAMMPS_NS { + class Hello : protected Pointers { + public: + Hello(class LAMMPS *lmp) : Pointers(lmp) {}; + void command(int, char **); + }; +} + +using namespace LAMMPS_NS; + +void Hello::command(int argc, char **argv) +{ + if (argc != 1) error->all(FLERR,"Illegal hello command"); + if (comm->me == 0) + utils::logmesg(lmp,fmt::format("Hello, {}!\n",argv[0])); +} + +static void hellocreator(LAMMPS *lmp, int argc, char **argv) +{ + Hello hello(lmp); + hello.command(argc,argv); +} + +extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) +{ + lammpsplugin_t plugin; + lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc; + + plugin.version = LAMMPS_VERSION; + plugin.style = "command"; + plugin.name = "hello"; + plugin.info = "Hello world command v1.0"; + plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; + plugin.creator1 = nullptr; + plugin.creator2 = nullptr; + plugin.creator3 = (lammpsplugin_factory3 *) &hellocreator; + plugin.handle = handle; + (*register_plugin)(&plugin,lmp); +} diff --git a/examples/plugins/morse2plugin.cpp b/examples/plugins/morse2plugin.cpp index 7151e35cd2..dfc341e0c0 100644 --- a/examples/plugins/morse2plugin.cpp +++ b/examples/plugins/morse2plugin.cpp @@ -33,6 +33,7 @@ extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; plugin.creator1 = (lammpsplugin_factory1 *) &morse2creator; plugin.creator2 = nullptr; + plugin.creator3 = nullptr; plugin.handle = handle; (*register_plugin)(&plugin,lmp); diff --git a/examples/plugins/nve2plugin.cpp b/examples/plugins/nve2plugin.cpp index 9c9ce3d8d2..785ec8dbe1 100644 --- a/examples/plugins/nve2plugin.cpp +++ b/examples/plugins/nve2plugin.cpp @@ -24,7 +24,9 @@ extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) plugin.name = "nve2"; plugin.info = "NVE2 variant fix style v1.0"; plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; + plugin.creator1 = nullptr; plugin.creator2 = (lammpsplugin_factory2 *) &nve2creator; + plugin.creator3 = nullptr; plugin.handle = handle; (*register_plugin)(&plugin,lmp); } diff --git a/src/lammpsplugin.h b/src/lammpsplugin.h index 958235fdaa..3de2bcdcdf 100644 --- a/src/lammpsplugin.h +++ b/src/lammpsplugin.h @@ -20,6 +20,7 @@ extern "C" { typedef void *(lammpsplugin_factory1)(void *); typedef void *(lammpsplugin_factory2)(void *, int, char **); + typedef void (lammpsplugin_factory3)(void *, int, char **); typedef struct { const char *version; @@ -29,6 +30,7 @@ extern "C" { const char *author; lammpsplugin_factory1 *creator1; lammpsplugin_factory2 *creator2; + lammpsplugin_factory3 *creator3; void *handle; } lammpsplugin_t; diff --git a/src/plugin.cpp b/src/plugin.cpp index 85870952e9..ea1c46b705 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -15,6 +15,7 @@ #include "comm.h" #include "error.h" +#include "input.h" #include "force.h" #include "lammps.h" #include "modify.h" @@ -128,8 +129,8 @@ namespace LAMMPS_NS "style {} from plugin", plugin->name)); } - (*pair_map)[plugin->name] = (Force::PairCreator)plugin->creator1; + } else if (pstyle == "fix") { auto fix_map = lmp->modify->fix_map; if (fix_map->find(plugin->name) != fix_map->end()) { @@ -138,8 +139,18 @@ namespace LAMMPS_NS "style {} from plugin", plugin->name)); } - (*fix_map)[plugin->name] = (Modify::FixCreator)plugin->creator2; + + } else if (pstyle == "command") { + auto command_map = lmp->input->command_map; + if (command_map->find(plugin->name) != command_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR,fmt::format("Overriding built-in fix " + "style {} from plugin", + plugin->name)); + } + (*command_map)[plugin->name] = (Input::CommandCreator)plugin->creator3; + } else { utils::logmesg(lmp,fmt::format("Loading plugin for {} styles not " "yet implemented\n",pstyle)); From dde00ab344340ffbf29fb5eb34462f1a8439319e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 23:10:26 -0500 Subject: [PATCH 034/257] add plugin command documentation --- doc/src/plugin.rst | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 doc/src/plugin.rst diff --git a/doc/src/plugin.rst b/doc/src/plugin.rst new file mode 100644 index 0000000000..42d53aabe3 --- /dev/null +++ b/doc/src/plugin.rst @@ -0,0 +1,76 @@ +.. index:: plugin + +plugin command +============== + +Syntax +"""""" + +.. parsed-literal:: + + plugin command args + +* command = *load* or *unload* or *list* +* args = list of arguments for a particular plugin command + + .. parsed-literal:: + + *load* file = load plugin(s) from shared object in *file* + *unload* style name = unload plugin *name* of style *style* + *list* = print a list of currently loaded plugins + +Examples +"""""""" + +.. code-block:: LAMMPS + + plugin load morse2plugin.so + plugin unload pair morse2/omp + plugin list + +Description +""""""""""" + +The plugin command allows to load (and unload) additional styles and +commands into a LAMMPS binary from so-called dynamic shared object (DSO) +files. This enables to add new functionality to an existing LAMMPS +binary without having to recompile and link the entire executable. + +The *load* command will load and initialize all plugins contained in the +plugin DSO with the given filename. A message with information the +plugin style and name and more will be printed. Individual DSO files +may contain multiple plugins. More details about how to write and +compile the plugin DSO is given in programmer's guide part of the manual +under :doc:`Developer_plugins`. + +The *unload* command will remove the given style or the given name from +the list of available styles. If the plugin style is currently in use, +that style instance will be deleted. + +The *list* command will print a list of the loaded plugins and their +styles and names. + + +Restrictions +"""""""""""" + +Plugins are currently not available on Windows. + +Plugins are dependent on the LAMMPS binary interface (ABI) +and particularly the MPI library used. So they are not guaranteed +to work when the plugin was compiled with a different MPI library +or different compilation settings or a different LAMMPS version. +If there is a mismatch the *plugin* command may fail to load the +plugin(s) or data corruption or crashes may happen. + + +Related commands +"""""""""""""""" + +none + + +Default +""""""" + +none From 524c62994eba5be3c1786ffaab32fc8d3edf9226 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 23:12:00 -0500 Subject: [PATCH 035/257] update docs --- doc/src/plugin.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/src/plugin.rst b/doc/src/plugin.rst index 42d53aabe3..25a55565b9 100644 --- a/doc/src/plugin.rst +++ b/doc/src/plugin.rst @@ -17,6 +17,7 @@ Syntax *load* file = load plugin(s) from shared object in *file* *unload* style name = unload plugin *name* of style *style* + *style* = *pair* or *fix* or *command* *list* = print a list of currently loaded plugins Examples @@ -26,6 +27,7 @@ Examples plugin load morse2plugin.so plugin unload pair morse2/omp + plugin unload command hello plugin list Description From d95d5f19547a88dc595922f5254c4b308ec643ac Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 23:52:35 -0500 Subject: [PATCH 036/257] store different factory variants in a union --- examples/plugins/helloplugin.cpp | 4 +--- examples/plugins/morse2plugin.cpp | 6 ++---- examples/plugins/nve2plugin.cpp | 4 +--- src/lammpsplugin.h | 8 +++++--- src/plugin.cpp | 6 +++--- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/examples/plugins/helloplugin.cpp b/examples/plugins/helloplugin.cpp index 1c9d0c2779..11f2cfb891 100644 --- a/examples/plugins/helloplugin.cpp +++ b/examples/plugins/helloplugin.cpp @@ -41,9 +41,7 @@ extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) plugin.name = "hello"; plugin.info = "Hello world command v1.0"; plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; - plugin.creator1 = nullptr; - plugin.creator2 = nullptr; - plugin.creator3 = (lammpsplugin_factory3 *) &hellocreator; + plugin.creator.v3 = (lammpsplugin_factory3 *) &hellocreator; plugin.handle = handle; (*register_plugin)(&plugin,lmp); } diff --git a/examples/plugins/morse2plugin.cpp b/examples/plugins/morse2plugin.cpp index dfc341e0c0..a4151dcc3d 100644 --- a/examples/plugins/morse2plugin.cpp +++ b/examples/plugins/morse2plugin.cpp @@ -31,15 +31,13 @@ extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) plugin.name = "morse2"; plugin.info = "Morse2 variant pair style v1.0"; plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; - plugin.creator1 = (lammpsplugin_factory1 *) &morse2creator; - plugin.creator2 = nullptr; - plugin.creator3 = nullptr; + plugin.creator.v1 = (lammpsplugin_factory1 *) &morse2creator; plugin.handle = handle; (*register_plugin)(&plugin,lmp); // also register morse2/omp pair style. only need to update changed fields plugin.name = "morse2/omp"; plugin.info = "Morse2 variant pair style for OpenMP v1.0"; - plugin.creator1 = (lammpsplugin_factory1 *) &morse2ompcreator; + plugin.creator.v1 = (lammpsplugin_factory1 *) &morse2ompcreator; (*register_plugin)(&plugin,lmp); } diff --git a/examples/plugins/nve2plugin.cpp b/examples/plugins/nve2plugin.cpp index 785ec8dbe1..d17db1dfc7 100644 --- a/examples/plugins/nve2plugin.cpp +++ b/examples/plugins/nve2plugin.cpp @@ -24,9 +24,7 @@ extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) plugin.name = "nve2"; plugin.info = "NVE2 variant fix style v1.0"; plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; - plugin.creator1 = nullptr; - plugin.creator2 = (lammpsplugin_factory2 *) &nve2creator; - plugin.creator3 = nullptr; + plugin.creator.v2 = (lammpsplugin_factory2 *) &nve2creator; plugin.handle = handle; (*register_plugin)(&plugin,lmp); } diff --git a/src/lammpsplugin.h b/src/lammpsplugin.h index 3de2bcdcdf..1baed9799d 100644 --- a/src/lammpsplugin.h +++ b/src/lammpsplugin.h @@ -28,9 +28,11 @@ extern "C" { const char *name; const char *info; const char *author; - lammpsplugin_factory1 *creator1; - lammpsplugin_factory2 *creator2; - lammpsplugin_factory3 *creator3; + union { + lammpsplugin_factory1 *v1; + lammpsplugin_factory2 *v2; + lammpsplugin_factory3 *v3; + } creator; void *handle; } lammpsplugin_t; diff --git a/src/plugin.cpp b/src/plugin.cpp index ea1c46b705..a95fde5b73 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -129,7 +129,7 @@ namespace LAMMPS_NS "style {} from plugin", plugin->name)); } - (*pair_map)[plugin->name] = (Force::PairCreator)plugin->creator1; + (*pair_map)[plugin->name] = (Force::PairCreator)plugin->creator.v1; } else if (pstyle == "fix") { auto fix_map = lmp->modify->fix_map; @@ -139,7 +139,7 @@ namespace LAMMPS_NS "style {} from plugin", plugin->name)); } - (*fix_map)[plugin->name] = (Modify::FixCreator)plugin->creator2; + (*fix_map)[plugin->name] = (Modify::FixCreator)plugin->creator.v2; } else if (pstyle == "command") { auto command_map = lmp->input->command_map; @@ -149,7 +149,7 @@ namespace LAMMPS_NS "style {} from plugin", plugin->name)); } - (*command_map)[plugin->name] = (Input::CommandCreator)plugin->creator3; + (*command_map)[plugin->name] = (Input::CommandCreator)plugin->creator.v3; } else { utils::logmesg(lmp,fmt::format("Loading plugin for {} styles not " From 930c0fca30fc24a3180d0ded815b8716063e5af4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 11 Mar 2021 23:59:23 -0500 Subject: [PATCH 037/257] must link with -ldl --- src/MAKE/Makefile.mpi | 2 +- src/MAKE/Makefile.serial | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MAKE/Makefile.mpi b/src/MAKE/Makefile.mpi index db134de68a..c66e66c217 100644 --- a/src/MAKE/Makefile.mpi +++ b/src/MAKE/Makefile.mpi @@ -13,7 +13,7 @@ DEPFLAGS = -M LINK = mpicxx LINKFLAGS = -g -O3 -LIB = +LIB = -ldl SIZE = size ARCHIVE = ar diff --git a/src/MAKE/Makefile.serial b/src/MAKE/Makefile.serial index a0b2959c4b..daf04cc5b0 100644 --- a/src/MAKE/Makefile.serial +++ b/src/MAKE/Makefile.serial @@ -13,7 +13,7 @@ DEPFLAGS = -M LINK = g++ LINKFLAGS = -g -O -LIB = +LIB = -ldl SIZE = size ARCHIVE = ar From a2bcd7fe68f0501733da98c9f941bae9f514b4f5 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Mar 2021 00:07:52 -0500 Subject: [PATCH 038/257] programmer documentation update --- doc/src/Developer_plugins.rst | 64 +++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/doc/src/Developer_plugins.rst b/doc/src/Developer_plugins.rst index 59402165d1..192c57ccbb 100644 --- a/doc/src/Developer_plugins.rst +++ b/doc/src/Developer_plugins.rst @@ -57,15 +57,14 @@ function would look like this: plugin.name = "morse2"; plugin.info = "Morse2 variant pair style v1.0"; plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; - plugin.creator1 = (lammpsplugin_factory1 *) &morse2creator; - plugin.creator2 = nullptr; + plugin.creator.v1 = (lammpsplugin_factory1 *) &morse2creator; plugin.handle = handle; (*register_plugin)(&plugin,lmp); } The factory function in this example is called ``morse2creator()``. It receives a pointer to the LAMMPS class as only argument and thus has to -be assigned to the *creator1* member of the plugin struct and cast to the +be assigned to the *creator.v1* member of the plugin struct and cast to the ``lammpsplugin_factory1`` pointer type. It returns a pointer to the allocated class instance derived from the ``Pair`` class. This function may be declared static to avoid clashes with other plugins. @@ -74,7 +73,7 @@ the entire LAMMPS executable. If the factory function would be for a fix or compute, which take three arguments (a pointer to the LAMMPS class, the number of arguments and the list of argument strings), then the pointer type is ``lammpsplugin_factory2`` -and it must be assigned to the *creator2* member of the plugin struct. +and it must be assigned to the *creator.v2* member of the plugin struct. Below is an example for that: .. code-block:: C++ @@ -100,12 +99,65 @@ Below is an example for that: plugin.name = "nve2"; plugin.info = "NVE2 variant fix style v1.0"; plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; - plugin.creator1 = nullptr; - plugin.creator2 = (lammpsplugin_factory2 *) &nve2creator; + plugin.creator.v2 = (lammpsplugin_factory2 *) &nve2creator; plugin.handle = handle; (*register_plugin)(&plugin,lmp); } +For command styles there is a third variant of factory function as +demonstrated in the following example, which also shows that the +implementation of the plugin class may also be within the same +file as the plugin interface code: + +.. code-block:: C++ + + #include "lammpsplugin.h" + + #include "comm.h" + #include "error.h" + #include "pointers.h" + #include "version.h" + + #include + + namespace LAMMPS_NS { + class Hello : protected Pointers { + public: + Hello(class LAMMPS *lmp) : Pointers(lmp) {}; + void command(int, char **); + }; + } + + using namespace LAMMPS_NS; + + void Hello::command(int argc, char **argv) + { + if (argc != 1) error->all(FLERR,"Illegal hello command"); + if (comm->me == 0) + utils::logmesg(lmp,fmt::format("Hello, {}!\n",argv[0])); + } + + static void hellocreator(LAMMPS *lmp, int argc, char **argv) + { + Hello hello(lmp); + hello.command(argc,argv); + } + + extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) + { + lammpsplugin_t plugin; + lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc; + + plugin.version = LAMMPS_VERSION; + plugin.style = "command"; + plugin.name = "hello"; + plugin.info = "Hello world command v1.0"; + plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; + plugin.creator.v3 = (lammpsplugin_factory3 *) &hellocreator; + plugin.handle = handle; + (*register_plugin)(&plugin,lmp); + } + The initialization function **must** be called ``lammpsplugin_init``, it **must** have C bindings and it takes three void pointers as arguments. The first is a pointer to the LAMMPS class that calls it and it needs to From c3f6fb914ff9ff287482f805e97663c6a356e2df Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Mar 2021 11:43:37 -0500 Subject: [PATCH 039/257] add CMake build environment demo for plugins --- examples/plugins/CMakeLists.txt | 56 +++++++++++++++ examples/plugins/LAMMPSInterfaceCXX.cmake | 86 +++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 examples/plugins/CMakeLists.txt create mode 100644 examples/plugins/LAMMPSInterfaceCXX.cmake diff --git a/examples/plugins/CMakeLists.txt b/examples/plugins/CMakeLists.txt new file mode 100644 index 0000000000..2fb8ca746f --- /dev/null +++ b/examples/plugins/CMakeLists.txt @@ -0,0 +1,56 @@ +########################################## +# CMake build system for plugin examples. +# The is meant to be used as a template for plugins that are +# distributed independent from the LAMMPS package. +########################################## + +cmake_minimum_required(VERSION 3.10) + +# enforce out-of-source build +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) + message(FATAL_ERROR "In-source builds are not allowed. You must create and use a build directory. " + "Please remove CMakeCache.txt and CMakeFiles first.") +endif() + +project(plugins VERSION 1.0 LANGUAGES CXX) + +# NOTE: the next line should be commented out when used outside of the LAMMPS package +get_filename_component(LAMMPS_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../../src ABSOLUTE) +set(LAMMPS_HEADER_DIR ${LAMMPS_SOURCE_DIR} CACHE PATH "Location of LAMMPS headers") +if(NOT LAMMPS_HEADER_DIR) + message(FATAL_ERROR "Must set LAMMPS_HEADER_DIR") +endif() + +# by default, install into $HOME/.local (not /usr/local), +# so that no root access (and sudo) is needed +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local" CACHE PATH "Default install path" FORCE) +endif() + +# C++11 is required +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# bail out on windows +if(CMAKE_SYSTEM_NAME STREQUAL Windows) + message(FATAL_ERROR "LAMMPS plugins are currently not supported on Windows") +endif() + +set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}) +include(CheckIncludeFileCXX) +include(LAMMPSInterfaceCXX) + +########################## +# building the plugins + +add_library(morse2plugin MODULE morse2plugin.cpp pair_morse2.cpp pair_morse2_omp.cpp) +target_include_directories(morse2plugin PRIVATE "${LAMMPS_HEADER_DIR}/USER-OMP") +target_link_libraries(morse2plugin PRIVATE lammps) + +add_library(nve2plugin MODULE nve2plugin.cpp fix_nve2.cpp) +target_link_libraries(nve2plugin PRIVATE lammps) + +add_library(helloplugin MODULE helloplugin.cpp) +target_link_libraries(helloplugin PRIVATE lammps) + +set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES PREFIX "") diff --git a/examples/plugins/LAMMPSInterfaceCXX.cmake b/examples/plugins/LAMMPSInterfaceCXX.cmake new file mode 100644 index 0000000000..02f9159319 --- /dev/null +++ b/examples/plugins/LAMMPSInterfaceCXX.cmake @@ -0,0 +1,86 @@ +# Cmake script code to define the LAMMPS C++ interface +# settings required for building LAMMPS plugins + +################################################################################ +# helper function +function(validate_option name values) + string(TOLOWER ${${name}} needle_lower) + string(TOUPPER ${${name}} needle_upper) + list(FIND ${values} ${needle_lower} IDX_LOWER) + list(FIND ${values} ${needle_upper} IDX_UPPER) + if(${IDX_LOWER} LESS 0 AND ${IDX_UPPER} LESS 0) + list_to_bulletpoints(POSSIBLE_VALUE_LIST ${${values}}) + message(FATAL_ERROR "\n########################################################################\n" + "Invalid value '${${name}}' for option ${name}\n" + "\n" + "Possible values are:\n" + "${POSSIBLE_VALUE_LIST}" + "########################################################################") + endif() +endfunction(validate_option) + +################################################################################# +# LAMMPS C++ interface. We only need the header related parts. +add_library(lammps INTERFACE) +target_include_directories(lammps INTERFACE ${LAMMPS_HEADER_DIR}) + +################################################################################ +# MPI configuration +if(NOT CMAKE_CROSSCOMPILING) + set(MPI_CXX_SKIP_MPICXX TRUE) + find_package(MPI QUIET) + option(BUILD_MPI "Build MPI version" ${MPI_FOUND}) +else() + option(BUILD_MPI "Build MPI version" OFF) +endif() + +if(BUILD_MPI) + find_package(MPI REQUIRED) + option(LAMMPS_LONGLONG_TO_LONG "Workaround if your system or MPI version does not recognize 'long long' data types" OFF) + if(LAMMPS_LONGLONG_TO_LONG) + target_compile_definitions(lammps INTERFACE -DLAMMPS_LONGLONG_TO_LONG) + endif() + target_link_libraries(lammps INTERFACE MPI::MPI_CXX) +else() + target_include_directories(lammps INTERFACE "${LAMMPS_SOURCE_DIR}/STUBS") +endif() + +set(LAMMPS_SIZES "smallbig" CACHE STRING "LAMMPS integer sizes (smallsmall: all 32-bit, smallbig: 64-bit #atoms #timesteps, bigbig: also 64-bit imageint, 64-bit atom ids)") +set(LAMMPS_SIZES_VALUES smallbig bigbig smallsmall) +set_property(CACHE LAMMPS_SIZES PROPERTY STRINGS ${LAMMPS_SIZES_VALUES}) +validate_option(LAMMPS_SIZES LAMMPS_SIZES_VALUES) +string(TOUPPER ${LAMMPS_SIZES} LAMMPS_SIZES) +target_compile_definitions(lammps INTERFACE -DLAMMPS_${LAMMPS_SIZES}) + +################################################################################ +# detect if we may enable OpenMP support by default +set(BUILD_OMP_DEFAULT OFF) +find_package(OpenMP QUIET) +if(OpenMP_FOUND) + check_include_file_cxx(omp.h HAVE_OMP_H_INCLUDE) + if(HAVE_OMP_H_INCLUDE) + set(BUILD_OMP_DEFAULT ON) + endif() +endif() + +option(BUILD_OMP "Build with OpenMP support" ${BUILD_OMP_DEFAULT}) + +if(BUILD_OMP) + find_package(OpenMP REQUIRED) + check_include_file_cxx(omp.h HAVE_OMP_H_INCLUDE) + if(NOT HAVE_OMP_H_INCLUDE) + message(FATAL_ERROR "Cannot find the 'omp.h' header file required for full OpenMP support") + endif() + + if (((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.0)) OR + (CMAKE_CXX_COMPILER_ID STREQUAL "PGI") OR + ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)) OR + ((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0))) + # GCC 9.x and later plus Clang 10.x and later implement strict OpenMP 4.0 semantics for consts. + # Intel 18.0 was tested to support both, so we switch to OpenMP 4+ from 19.x onward to be safe. + target_compile_definitions(lammps INTERFACE -DLAMMPS_OMP_COMPAT=4) + else() + target_compile_definitions(lammps INTERFACE -DLAMMPS_OMP_COMPAT=3) + endif() + target_link_libraries(lammps INTERFACE OpenMP::OpenMP_CXX) +endif() From 7b4e14317685278c5e62217aaffddd5bdb2773cb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Mar 2021 14:29:40 -0500 Subject: [PATCH 040/257] support building plugins on MacOS (tested on version 11.0 aka Big Sur) --- examples/plugins/CMakeLists.txt | 10 +++++++++- examples/plugins/Makefile | 2 +- examples/plugins/Makefile.macos | 30 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 examples/plugins/Makefile.macos diff --git a/examples/plugins/CMakeLists.txt b/examples/plugins/CMakeLists.txt index 2fb8ca746f..74a1cd4e3b 100644 --- a/examples/plugins/CMakeLists.txt +++ b/examples/plugins/CMakeLists.txt @@ -53,4 +53,12 @@ target_link_libraries(nve2plugin PRIVATE lammps) add_library(helloplugin MODULE helloplugin.cpp) target_link_libraries(helloplugin PRIVATE lammps) -set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES PREFIX "") +set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES + PREFIX "" + LINK_FLAGS "-rdynamic") + +# MacOS seems to need this +if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES + LINK_FLAGS "-Wl,-undefined,dynamic_lookup") +endif() diff --git a/examples/plugins/Makefile b/examples/plugins/Makefile index bf6bc804be..dbb0023991 100644 --- a/examples/plugins/Makefile +++ b/examples/plugins/Makefile @@ -26,5 +26,5 @@ fix_nve2.o: fix_nve2.cpp fix_nve2.h nve2plugin.o: nve2plugin.cpp fix_nve2.h clean: - rm -f *~ *.so *.o log.lammps + rm -rf *~ *.so *.dylib *.o log.lammps CMakeCache.txt CMakeFiles diff --git a/examples/plugins/Makefile.macos b/examples/plugins/Makefile.macos new file mode 100644 index 0000000000..2490418a09 --- /dev/null +++ b/examples/plugins/Makefile.macos @@ -0,0 +1,30 @@ +CXX=mpicxx +CXXFLAGS=-I../../src -Wall -Wextra -O3 -fPIC -I../../src/USER-OMP +LD=$(CXX) -bundle -rdynamic -Wl,-undefined,dynamic_lookup + +default: morse2plugin.dylib nve2plugin.dylib helloplugin.dylib + +helloplugin.dylib: helloplugin.o + $(LD) -o $@ $^ + +morse2plugin.dylib: morse2plugin.o pair_morse2.o pair_morse2_omp.o + $(LD) -o $@ $^ + +nve2plugin.dylib: nve2plugin.o fix_nve2.o + $(LD) -o $@ $^ + +.cpp.o: + $(CXX) -o $@ $(CXXFLAGS) -c $< + +helloplugin.o: helloplugin.cpp + +pair_morse2.o: pair_morse2.cpp pair_morse2.h +pair_morse2_omp.o: pair_morse2_omp.cpp pair_morse2_omp.h pair_morse2.h +morse2plugin.o: morse2plugin.cpp pair_morse2.h pair_morse2_omp.h + +fix_nve2.o: fix_nve2.cpp fix_nve2.h +nve2plugin.o: nve2plugin.cpp fix_nve2.h + +clean: + rm -rf *~ *.dylib *.dylib *.o log.lammps CMakeCache.txt CMakeFiles + From 4b1924fad10322d5173d982115bcdb42252a9477 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Mar 2021 14:29:59 -0500 Subject: [PATCH 041/257] add missing check --- src/plugin.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/plugin.cpp b/src/plugin.cpp index a95fde5b73..68b9978353 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -207,10 +207,16 @@ namespace LAMMPS_NS lmp->force->create_pair("none",0); } } + } else if (pstyle == "fix") { for (int ifix = lmp->modify->find_fix_by_style(name); ifix >= 0; ifix = lmp->modify->find_fix_by_style(name)) lmp->modify->delete_fix(ifix); + + } else if (pstyle == "command") { + auto command_map = lmp->input->command_map; + auto cmd = command_map->find(name); + if (cmd != command_map->end()) command_map->erase(name); } // if reference count is down to zero, close DSO handle. From 1c222286e22e699068a0021221d9c8b1090681e2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Mar 2021 14:30:08 -0500 Subject: [PATCH 042/257] correct output --- src/plugin.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/plugin.cpp b/src/plugin.cpp index 68b9978353..f9bd36f875 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -51,8 +51,7 @@ namespace LAMMPS_NS void *dso = dlopen(file,RTLD_NOW|RTLD_GLOBAL); if (dso == nullptr) { if (me == 0) - utils::logmesg(lmp,fmt::format("Open of plugin file {} failed: {}", - file,utils::getsyserror())); + utils::logmesg(lmp,fmt::format("Open of file {} failed\n",file)); return; } @@ -145,7 +144,7 @@ namespace LAMMPS_NS auto command_map = lmp->input->command_map; if (command_map->find(plugin->name) != command_map->end()) { if (lmp->comm->me == 0) - lmp->error->warning(FLERR,fmt::format("Overriding built-in fix " + lmp->error->warning(FLERR,fmt::format("Overriding built-in command " "style {} from plugin", plugin->name)); } From 98013a1528ab55d9209eff6de4d604574d7bd57e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Mar 2021 15:32:50 -0500 Subject: [PATCH 043/257] add draft version of unit test (will have to be improved for MacOS) --- unittest/commands/CMakeLists.txt | 19 +++++++++++++++++++ unittest/commands/test_simple_commands.cpp | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/unittest/commands/CMakeLists.txt b/unittest/commands/CMakeLists.txt index 7a804820cb..0fb0c8088e 100644 --- a/unittest/commands/CMakeLists.txt +++ b/unittest/commands/CMakeLists.txt @@ -1,5 +1,24 @@ +# build LAMMPS plugins, but not on Windows +if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + ExternalProject_Add(plugins + SOURCE_DIR "${LAMMPS_DIR}/examples/plugins" + BINARY_DIR "${CMAKE_BINARY_DIR}/plugins" + CMAKE_ARGS ${CMAKE_REQUEST_PIC} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_INSTALL_PREFIX= + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} + BUILD_BYPRODUCTS /morse2plugin${CMAKE_STATIC_LIBRARY_SUFFIX} + /nve2plugin${CMAKE_STATIC_LIBRARY_SUFFIX} + /helloplugin${CMAKE_STATIC_LIBRARY_SUFFIX} + INSTALL_COMMAND "" + TEST_COMMAND "") +endif() + add_executable(test_simple_commands test_simple_commands.cpp) +add_dependencies(test_simple_commands plugins) target_link_libraries(test_simple_commands PRIVATE lammps GTest::GMock GTest::GTest) add_test(NAME SimpleCommands COMMAND test_simple_commands WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index 4fce58c668..09f81b8f71 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -344,6 +344,15 @@ TEST_F(SimpleCommandsTest, Units) TEST_FAILURE(".*ERROR: Illegal units command.*", lmp->input->one("units unknown");); } +TEST_F(SimpleCommandsTest, Plugin) +{ + ::testing::internal::CaptureStdout(); + lmp->input->one("plugin load plugins/helloplugin.so"); + auto text = ::testing::internal::GetCapturedStdout(); + + ASSERT_THAT(text, MatchesRegex(".*Loading plugin: Hello world command.*")); +} + TEST_F(SimpleCommandsTest, Shell) { if (!verbose) ::testing::internal::CaptureStdout(); From 93bbaef5473b3ad126b28865e50b8081c7245aeb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Mar 2021 17:28:22 -0500 Subject: [PATCH 044/257] add unit tests for plugin command --- unittest/commands/test_simple_commands.cpp | 66 +++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index 09f81b8f71..08fe53a6b9 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -346,11 +346,73 @@ TEST_F(SimpleCommandsTest, Units) TEST_F(SimpleCommandsTest, Plugin) { +#if defined(__APPLE__) + std::string loadfmt("plugin load plugins/{}plugin.dylib"); +#else + std::string loadfmt("plugin load plugins/{}plugin.so"); +#endif ::testing::internal::CaptureStdout(); - lmp->input->one("plugin load plugins/helloplugin.so"); + lmp->input->one(fmt::format(loadfmt, "hello")); auto text = ::testing::internal::GetCapturedStdout(); - + if (verbose) std::cout << text; ASSERT_THAT(text, MatchesRegex(".*Loading plugin: Hello world command.*")); + + ::testing::internal::CaptureStdout(); + lmp->input->one(fmt::format(loadfmt, "xxx")); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*Open of file plugins/xxx.* failed.*")); + + ::testing::internal::CaptureStdout(); + lmp->input->one(fmt::format(loadfmt, "nve2")); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*Loading plugin: NVE2 variant fix style.*")); + ::testing::internal::CaptureStdout(); + lmp->input->one("plugin list"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*1: command style plugin hello" + ".*2: fix style plugin nve2.*")); + + ::testing::internal::CaptureStdout(); + lmp->input->one(fmt::format(loadfmt, "hello")); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*Ignoring load of command style hello: " + "must unload existing hello plugin.*")); + + ::testing::internal::CaptureStdout(); + lmp->input->one("plugin unload command hello"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*Unloading command style hello.*")); + + ::testing::internal::CaptureStdout(); + lmp->input->one("plugin unload pair nve2"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*Ignoring unload of pair style nve2: " + "not loaded from a plugin.*")); + + ::testing::internal::CaptureStdout(); + lmp->input->one("plugin unload fix nve2"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*Unloading fix style nve2.*")); + + ::testing::internal::CaptureStdout(); + lmp->input->one("plugin unload fix nve"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*Ignoring unload of fix style nve: " + "not loaded from a plugin.*")); + + ::testing::internal::CaptureStdout(); + lmp->input->one("plugin list"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*Currently loaded plugins.*")); } TEST_F(SimpleCommandsTest, Shell) From b2085f56d6478552110fcdcc5f16921b30a885b4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Mar 2021 18:35:39 -0500 Subject: [PATCH 045/257] install compiled plugins into the current working directory of the tester --- unittest/commands/CMakeLists.txt | 15 ++++++++++----- unittest/commands/test_simple_commands.cpp | 6 +++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/unittest/commands/CMakeLists.txt b/unittest/commands/CMakeLists.txt index 0fb0c8088e..6c68bfb274 100644 --- a/unittest/commands/CMakeLists.txt +++ b/unittest/commands/CMakeLists.txt @@ -3,17 +3,22 @@ if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") ExternalProject_Add(plugins SOURCE_DIR "${LAMMPS_DIR}/examples/plugins" - BINARY_DIR "${CMAKE_BINARY_DIR}/plugins" + BINARY_DIR ${CMAKE_BINARY_DIR}/build-plugins + INSTALL_DIR ${CMAKE_BINARY_DIR} CMAKE_ARGS ${CMAKE_REQUEST_PIC} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} - BUILD_BYPRODUCTS /morse2plugin${CMAKE_STATIC_LIBRARY_SUFFIX} - /nve2plugin${CMAKE_STATIC_LIBRARY_SUFFIX} - /helloplugin${CMAKE_STATIC_LIBRARY_SUFFIX} - INSTALL_COMMAND "" + BUILD_BYPRODUCTS /morse2plugin${CMAKE_SHARED_LIBRARY_SUFFIX} + /nve2plugin${CMAKE_SHARED_LIBRARY_SUFFIX} + /helloplugin${CMAKE_SHARED_LIBRARY_SUFFIX} + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different + /morse2plugin${CMAKE_SHARED_LIBRARY_SUFFIX} + /nve2plugin${CMAKE_SHARED_LIBRARY_SUFFIX} + /helloplugin${CMAKE_SHARED_LIBRARY_SUFFIX} + ${CMAKE_CURRENT_BINARY_DIR} TEST_COMMAND "") endif() diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index 08fe53a6b9..0e26734dfb 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -347,9 +347,9 @@ TEST_F(SimpleCommandsTest, Units) TEST_F(SimpleCommandsTest, Plugin) { #if defined(__APPLE__) - std::string loadfmt("plugin load plugins/{}plugin.dylib"); + std::string loadfmt("plugin load {}plugin.dylib"); #else - std::string loadfmt("plugin load plugins/{}plugin.so"); + std::string loadfmt("plugin load {}plugin.so"); #endif ::testing::internal::CaptureStdout(); lmp->input->one(fmt::format(loadfmt, "hello")); @@ -361,7 +361,7 @@ TEST_F(SimpleCommandsTest, Plugin) lmp->input->one(fmt::format(loadfmt, "xxx")); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*Open of file plugins/xxx.* failed.*")); + ASSERT_THAT(text, MatchesRegex(".*Open of file xxx.* failed.*")); ::testing::internal::CaptureStdout(); lmp->input->one(fmt::format(loadfmt, "nve2")); From 3e90b1971a9f9890be584c47db12c2d922de5b37 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Mar 2021 22:21:11 -0500 Subject: [PATCH 046/257] add preliminary support for compiling/loading plugins on windows --- doc/src/plugin.rst | 3 ++ examples/plugins/CMakeLists.txt | 14 +++----- examples/plugins/Makefile.serial | 30 ++++++++++++++++ src/MAKE/Makefile.mpi | 2 +- src/MAKE/Makefile.serial | 2 +- src/plugin.cpp | 59 ++++++++++++++++++++++++-------- 6 files changed, 85 insertions(+), 25 deletions(-) create mode 100644 examples/plugins/Makefile.serial diff --git a/doc/src/plugin.rst b/doc/src/plugin.rst index 25a55565b9..a75e39ccae 100644 --- a/doc/src/plugin.rst +++ b/doc/src/plugin.rst @@ -58,6 +58,9 @@ Restrictions Plugins are currently not available on Windows. +For the loading of plugins to work, the LAMMPS library must be +:ref:`compiled as a shared library `. + Plugins are dependent on the LAMMPS binary interface (ABI) and particularly the MPI library used. So they are not guaranteed to work when the plugin was compiled with a different MPI library diff --git a/examples/plugins/CMakeLists.txt b/examples/plugins/CMakeLists.txt index 74a1cd4e3b..2db2c041fd 100644 --- a/examples/plugins/CMakeLists.txt +++ b/examples/plugins/CMakeLists.txt @@ -31,11 +31,6 @@ endif() set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) -# bail out on windows -if(CMAKE_SYSTEM_NAME STREQUAL Windows) - message(FATAL_ERROR "LAMMPS plugins are currently not supported on Windows") -endif() - set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}) include(CheckIncludeFileCXX) include(LAMMPSInterfaceCXX) @@ -53,12 +48,13 @@ target_link_libraries(nve2plugin PRIVATE lammps) add_library(helloplugin MODULE helloplugin.cpp) target_link_libraries(helloplugin PRIVATE lammps) -set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES - PREFIX "" - LINK_FLAGS "-rdynamic") +set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES PREFIX "") -# MacOS seems to need this if(CMAKE_SYSTEM_NAME STREQUAL Darwin) set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES LINK_FLAGS "-Wl,-undefined,dynamic_lookup") +elseif(CMAKE_SYSTEM_NAME STREQUAL Windows) + set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES LINK_FLAGS "-Wl,--undefined") +else() + set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES LINK_FLAGS "-rdynamic") endif() diff --git a/examples/plugins/Makefile.serial b/examples/plugins/Makefile.serial new file mode 100644 index 0000000000..feb58bd9b3 --- /dev/null +++ b/examples/plugins/Makefile.serial @@ -0,0 +1,30 @@ +CXX=g++ +CXXFLAGS=-I../../src -I../../src/STUBS -Wall -Wextra -O3 -fPIC -I../../src/USER-OMP -fopenmp +LD=$(CXX) -shared -rdynamic -fopenmp + +default: morse2plugin.so nve2plugin.so helloplugin.so + +helloplugin.so: helloplugin.o + $(LD) -o $@ $^ + +morse2plugin.so: morse2plugin.o pair_morse2.o pair_morse2_omp.o + $(LD) -o $@ $^ + +nve2plugin.so: nve2plugin.o fix_nve2.o + $(LD) -o $@ $^ + +.cpp.o: + $(CXX) -o $@ $(CXXFLAGS) -c $< + +helloplugin.o: helloplugin.cpp + +pair_morse2.o: pair_morse2.cpp pair_morse2.h +pair_morse2_omp.o: pair_morse2_omp.cpp pair_morse2_omp.h pair_morse2.h +morse2plugin.o: morse2plugin.cpp pair_morse2.h pair_morse2_omp.h + +fix_nve2.o: fix_nve2.cpp fix_nve2.h +nve2plugin.o: nve2plugin.cpp fix_nve2.h + +clean: + rm -rf *~ *.so *.dylib *.o log.lammps CMakeCache.txt CMakeFiles + diff --git a/src/MAKE/Makefile.mpi b/src/MAKE/Makefile.mpi index c66e66c217..68e79e9e8e 100644 --- a/src/MAKE/Makefile.mpi +++ b/src/MAKE/Makefile.mpi @@ -18,7 +18,7 @@ SIZE = size ARCHIVE = ar ARFLAGS = -rc -SHLIBFLAGS = -shared +SHLIBFLAGS = -shared -rdynamic # --------------------------------------------------------------------- # LAMMPS-specific settings, all OPTIONAL diff --git a/src/MAKE/Makefile.serial b/src/MAKE/Makefile.serial index daf04cc5b0..8b4e2e5982 100644 --- a/src/MAKE/Makefile.serial +++ b/src/MAKE/Makefile.serial @@ -18,7 +18,7 @@ SIZE = size ARCHIVE = ar ARFLAGS = -rc -SHLIBFLAGS = -shared +SHLIBFLAGS = -shared -rdynamic # --------------------------------------------------------------------- # LAMMPS-specific settings, all OPTIONAL diff --git a/src/plugin.cpp b/src/plugin.cpp index f9bd36f875..2c4f2da396 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -24,12 +24,49 @@ #include #include -#ifdef _WIN32 +#if defined(_WIN32) #include #else #include #endif +#if defined(_WIN32) + +// open a shared object file +static void *my_dlopen(const char *fname) { + return (void *)LoadLibrary(fname); +} + +// resolve a symbol in shared object +static void *my_dlsym(void *h, const char *sym) { + return (void *)GetProcAddress((HINSTANCE)h, sym); +} + +// close a shared object +static int my_dlclose(void *h) { + /* FreeLibrary returns nonzero on success */ + return !FreeLibrary((HINSTANCE)h); +} + +#else + +// open a shared object file +static void *my_dlopen(const char *fname) { + return dlopen(fname, RTLD_NOW|RTLD_GLOBAL); +} + +// resolve a symbol in shared object +static void *my_dlsym(void *h, const char *sym) { + return dlsym(h, sym); +} + +// close a shared object +static int my_dlclose(void *h) { + return dlclose(h); +} + +#endif + namespace LAMMPS_NS { // list of plugin information data for loaded styles @@ -42,13 +79,11 @@ namespace LAMMPS_NS void plugin_load(const char *file, LAMMPS *lmp) { int me = lmp->comm->me; -#if defined(WIN32) - lmp->error->all(FLERR,"Loading of plugins on Windows not yet supported\n"); -#else // open DSO file from given path; load symbols globally - - void *dso = dlopen(file,RTLD_NOW|RTLD_GLOBAL); + + void *dso = my_dlopen(file); + if (dso == nullptr) { if (me == 0) utils::logmesg(lmp,fmt::format("Open of file {} failed\n",file)); @@ -58,9 +93,10 @@ namespace LAMMPS_NS // look up lammpsplugin_init() function in DSO // function must have C bindings so there is no name mangling - void *initfunc = dlsym(dso,"lammpsplugin_init"); + void *initfunc = my_dlsym(dso,"lammpsplugin_init"); + if (initfunc == nullptr) { - dlclose(dso); + my_dlclose(dso); if (me == 0) utils::logmesg(lmp,fmt::format("Plugin symbol lookup failure in " @@ -74,7 +110,6 @@ namespace LAMMPS_NS (*(lammpsplugin_initfunc)(initfunc))((void *)lmp, dso, (void *)&plugin_register); -#endif } /* -------------------------------------------------------------------- @@ -221,11 +256,7 @@ namespace LAMMPS_NS // if reference count is down to zero, close DSO handle. -- dso_refcounter[handle]; - if (dso_refcounter[handle] == 0) { -#ifndef WIN32 - dlclose(handle); -#endif - } + if (dso_refcounter[handle] == 0) my_dlclose(handle); } /* -------------------------------------------------------------------- From d05137455c660e2c801ebffddc36ca9eaf51b8d2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Mar 2021 22:21:24 -0500 Subject: [PATCH 047/257] ignore build folders --- examples/plugins/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 examples/plugins/.gitignore diff --git a/examples/plugins/.gitignore b/examples/plugins/.gitignore new file mode 100644 index 0000000000..0ec9e7f982 --- /dev/null +++ b/examples/plugins/.gitignore @@ -0,0 +1 @@ +/build* From 4ae7f84c2ac0552c3f123e6e9f02911b526ed6b9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 12 Mar 2021 22:27:38 -0500 Subject: [PATCH 048/257] whitespace --- src/plugin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugin.cpp b/src/plugin.cpp index 2c4f2da396..73fcfd947e 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -81,9 +81,9 @@ namespace LAMMPS_NS int me = lmp->comm->me; // open DSO file from given path; load symbols globally - + void *dso = my_dlopen(file); - + if (dso == nullptr) { if (me == 0) utils::logmesg(lmp,fmt::format("Open of file {} failed\n",file)); From e3d9c3126b12c081598b3ac36e5497edca8f12bd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Mar 2021 10:25:44 -0500 Subject: [PATCH 049/257] revert back to not supporting loading plugins on windows --- examples/plugins/CMakeLists.txt | 14 +++++--- src/plugin.cpp | 57 ++++++++------------------------- 2 files changed, 22 insertions(+), 49 deletions(-) diff --git a/examples/plugins/CMakeLists.txt b/examples/plugins/CMakeLists.txt index 2db2c041fd..74a1cd4e3b 100644 --- a/examples/plugins/CMakeLists.txt +++ b/examples/plugins/CMakeLists.txt @@ -31,6 +31,11 @@ endif() set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# bail out on windows +if(CMAKE_SYSTEM_NAME STREQUAL Windows) + message(FATAL_ERROR "LAMMPS plugins are currently not supported on Windows") +endif() + set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}) include(CheckIncludeFileCXX) include(LAMMPSInterfaceCXX) @@ -48,13 +53,12 @@ target_link_libraries(nve2plugin PRIVATE lammps) add_library(helloplugin MODULE helloplugin.cpp) target_link_libraries(helloplugin PRIVATE lammps) -set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES PREFIX "") +set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES + PREFIX "" + LINK_FLAGS "-rdynamic") +# MacOS seems to need this if(CMAKE_SYSTEM_NAME STREQUAL Darwin) set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES LINK_FLAGS "-Wl,-undefined,dynamic_lookup") -elseif(CMAKE_SYSTEM_NAME STREQUAL Windows) - set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES LINK_FLAGS "-Wl,--undefined") -else() - set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES LINK_FLAGS "-rdynamic") endif() diff --git a/src/plugin.cpp b/src/plugin.cpp index 73fcfd947e..d654535f56 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -24,49 +24,12 @@ #include #include -#if defined(_WIN32) +#ifdef _WIN32 #include #else #include #endif -#if defined(_WIN32) - -// open a shared object file -static void *my_dlopen(const char *fname) { - return (void *)LoadLibrary(fname); -} - -// resolve a symbol in shared object -static void *my_dlsym(void *h, const char *sym) { - return (void *)GetProcAddress((HINSTANCE)h, sym); -} - -// close a shared object -static int my_dlclose(void *h) { - /* FreeLibrary returns nonzero on success */ - return !FreeLibrary((HINSTANCE)h); -} - -#else - -// open a shared object file -static void *my_dlopen(const char *fname) { - return dlopen(fname, RTLD_NOW|RTLD_GLOBAL); -} - -// resolve a symbol in shared object -static void *my_dlsym(void *h, const char *sym) { - return dlsym(h, sym); -} - -// close a shared object -static int my_dlclose(void *h) { - return dlclose(h); -} - -#endif - namespace LAMMPS_NS { // list of plugin information data for loaded styles @@ -79,11 +42,13 @@ namespace LAMMPS_NS void plugin_load(const char *file, LAMMPS *lmp) { int me = lmp->comm->me; +#if defined(WIN32) + lmp->error->all(FLERR,"Loading of plugins on Windows is not supported\n"); +#else // open DSO file from given path; load symbols globally - void *dso = my_dlopen(file); - + void *dso = dlopen(file,RTLD_NOW|RTLD_GLOBAL); if (dso == nullptr) { if (me == 0) utils::logmesg(lmp,fmt::format("Open of file {} failed\n",file)); @@ -93,10 +58,9 @@ namespace LAMMPS_NS // look up lammpsplugin_init() function in DSO // function must have C bindings so there is no name mangling - void *initfunc = my_dlsym(dso,"lammpsplugin_init"); - + void *initfunc = dlsym(dso,"lammpsplugin_init"); if (initfunc == nullptr) { - my_dlclose(dso); + dlclose(dso); if (me == 0) utils::logmesg(lmp,fmt::format("Plugin symbol lookup failure in " @@ -110,6 +74,7 @@ namespace LAMMPS_NS (*(lammpsplugin_initfunc)(initfunc))((void *)lmp, dso, (void *)&plugin_register); +#endif } /* -------------------------------------------------------------------- @@ -256,7 +221,11 @@ namespace LAMMPS_NS // if reference count is down to zero, close DSO handle. -- dso_refcounter[handle]; - if (dso_refcounter[handle] == 0) my_dlclose(handle); + if (dso_refcounter[handle] == 0) { +#ifndef WIN32 + dlclose(handle); +#endif + } } /* -------------------------------------------------------------------- From 76cff1ed1ec1ce562ed58d4c3f2e0aa483d18444 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Mar 2021 12:17:20 -0500 Subject: [PATCH 050/257] add library interface for introspection of loaded plugins --- src/library.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ src/library.h | 3 +++ 2 files changed, 57 insertions(+) diff --git a/src/library.cpp b/src/library.cpp index 2a7bbf07b3..ae3212d6f3 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -38,6 +38,7 @@ #include "neighbor.h" #include "region.h" #include "output.h" +#include "plugin.h" #include "thermo.h" #include "timer.h" #include "universe.h" @@ -4581,6 +4582,59 @@ int lammps_id_name(void *handle, const char *category, int idx, return 0; } +/* ---------------------------------------------------------------------- */ + +/** Count the number of loaded plugins + * +\verbatim embed:rst +This function counts how many plugins are currently loaded. + +.. versionadded:: 10Mar2021 + +\endverbatim + * + * \return number of loaded plugins + */ +int lammps_plugin_count() +{ + return plugin_get_num_plugins(); +} + +/* ---------------------------------------------------------------------- */ + +/** Look up the info of a loaded plugin by its index in the list of plugins + * +\verbatim embed:rst +This function copies the name of the *style* plugin with the index +*idx* into the provided C-style string buffer. The length of the buffer +must be provided as *buf_size* argument. If the name of the style +exceeds the length of the buffer, it will be truncated accordingly. +If the index is out of range, the function returns 0 and *buffer* is +set to an empty string, otherwise 1. + +.. versionadded:: 10Mar2021 + +\endverbatim + * + * \param idx index of the plugin in the list all or *style* plugins + * \param stylebuf string buffer to copy the style of the plugin to + * \param namebuf string buffer to copy the name of the plugin to + * \param buf_size size of the provided string buffers + * \return 1 if successful, otherwise 0 + */ +int lammps_plugin_name(int idx, char *stylebuf, char *namebuf, int buf_size) +{ + stylebuf[0] = namebuf[0] = '\0'; + + const lammpsplugin_t *plugin = plugin_get_info(idx); + if (plugin) { + strncpy(stylebuf,plugin->style,buf_size); + strncpy(namebuf,plugin->name,buf_size); + return 1; + } + return 0; +} + // ---------------------------------------------------------------------- // utility functions // ---------------------------------------------------------------------- diff --git a/src/library.h b/src/library.h index d98bf426b3..11cd72388a 100644 --- a/src/library.h +++ b/src/library.h @@ -205,6 +205,9 @@ int lammps_has_id(void *, const char *, const char *); int lammps_id_count(void *, const char *); int lammps_id_name(void *, const char *, int, char *, int); +int lammps_plugin_count(); +int lammps_plugin_name(int, char *, char *, int); + /* ---------------------------------------------------------------------- * Utility functions * ---------------------------------------------------------------------- */ From dd94bac0c8b3b61cb1805d703f189b78958a2f3d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Mar 2021 12:17:45 -0500 Subject: [PATCH 051/257] better error message when trying to unload an unsupported plugin style --- src/plugin.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/plugin.cpp b/src/plugin.cpp index d654535f56..fb3186c69e 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -167,6 +167,16 @@ namespace LAMMPS_NS { int me = lmp->comm->me; + // ignore unload request from unsupported style categories + if ((strcmp(style,"pair") != 0) + && (strcmp(style,"fix") != 0) + && (strcmp(style,"command") != 0)) { + if (me == 0) + utils::logmesg(lmp,fmt::format("Ignoring unload: {} is not a " + "supported plugin style\n",style)); + return; + } + // ignore unload request if not loaded from a plugin int idx = plugin_find(style,name); if (idx < 0) { From 79d438e090e9b72ac6db2d04403005bad3086645 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Mar 2021 12:18:07 -0500 Subject: [PATCH 052/257] add support for plugin command to LAMMPS shell --- tools/lammps-shell/lammps-shell.cpp | 66 ++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/tools/lammps-shell/lammps-shell.cpp b/tools/lammps-shell/lammps-shell.cpp index 7ace6d6819..8153c1bcfa 100644 --- a/tools/lammps-shell/lammps-shell.cpp +++ b/tools/lammps-shell/lammps-shell.cpp @@ -128,6 +128,7 @@ const char *cmdlist[] = {"clear", "pair_modify", "pair_style", "pair_write", + "plugin", "processors", "region", "reset_timestep", @@ -347,6 +348,59 @@ static char *variable_expand_generator(const char *text, int state) return nullptr; } +static char *plugin_generator(const char *text, int state) +{ + const char *subcmd[] = {"load", "unload", "list", NULL}; + const char *sub; + static std::size_t idx, len; + if (!state) idx = 0; + len = strlen(text); + + while ((sub = subcmd[idx]) != NULL) { + ++idx; + if (strncmp(text,sub,len) == 0) + return dupstring(sub); + } + return nullptr; +} + +static char *plugin_style_generator(const char *text, int state) +{ + const char *styles[] = {"pair", "fix", "command", NULL}; + const char *s; + static std::size_t idx, len; + if (!state) idx = 0; + len = strlen(text); + while ((s = styles[idx]) != NULL) { + ++idx; + if (strncmp(text,s,len) == 0) + return dupstring(s); + } + return nullptr; +} + +static char *plugin_name_generator(const char *text, int state) +{ + auto words = utils::split_words(text); + if (words.size() < 4) return nullptr; + + static std::size_t idx, len; + if (!state) idx = 0; + len = words[3].size(); + int nmax = lammps_plugin_count(); + + while (idx < nmax) { + char style[buflen], name[buflen]; + lammps_plugin_name(idx, style, name, buflen); + ++idx; + if (words[2] == style) { + if (strncmp(name, words[3].c_str(), len) == 0) + return dupstring(name); + } + } + return nullptr; +} + static char *atom_generator(const char *text, int state) { return style_generator(text, state); @@ -477,14 +531,21 @@ static char **cmd_completion(const char *text, int start, int) matches = rl_completion_matches(text, dump_id_generator); } else if (words[0] == "fix_modify") { matches = rl_completion_matches(text, fix_id_generator); + } else if (words[0] == "plugin") { + matches = rl_completion_matches(text, plugin_generator); } } else if (words.size() == 2) { // expand third word // these commands have a group name as 3rd word - if ((words[0] == "fix") || (words[0] == "compute") || (words[0] == "dump")) { + if ((words[0] == "fix") + || (words[0] == "compute") + || (words[0] == "dump")) { matches = rl_completion_matches(text, group_generator); } else if (words[0] == "region") { matches = rl_completion_matches(text, region_generator); + // plugin style is the third word + } else if ((words[0] == "plugin") && (words[1] == "unload")) { + matches = rl_completion_matches(text, plugin_style_generator); } } else if (words.size() == 3) { // expand fourth word @@ -495,6 +556,9 @@ static char **cmd_completion(const char *text, int start, int) matches = rl_completion_matches(text, compute_generator); } else if (words[0] == "dump") { matches = rl_completion_matches(text, dump_generator); + // plugin name is the fourth word + } else if ((words[0] == "plugin") && (words[1] == "unload")) { + matches = rl_completion_matches(rl_line_buffer, plugin_name_generator); } } } From 88760fa648a69352bd333e6b06c412acb17eec08 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Mar 2021 12:40:04 -0500 Subject: [PATCH 053/257] add plugin clear command to unload all loaded plugins --- doc/src/plugin.rst | 18 ++++++++++++------ src/input.cpp | 2 ++ src/plugin.cpp | 12 ++++++++++++ src/plugin.h | 1 + tools/lammps-shell/lammps-shell.cpp | 2 +- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/doc/src/plugin.rst b/doc/src/plugin.rst index a75e39ccae..e8a5f67e3c 100644 --- a/doc/src/plugin.rst +++ b/doc/src/plugin.rst @@ -10,7 +10,7 @@ Syntax plugin command args -* command = *load* or *unload* or *list* +* command = *load* or *unload* or *list* or *clear* * args = list of arguments for a particular plugin command .. parsed-literal:: @@ -19,6 +19,7 @@ Syntax *unload* style name = unload plugin *name* of style *style* *style* = *pair* or *fix* or *command* *list* = print a list of currently loaded plugins + *clear* = unload all currently loaded plugins Examples """""""" @@ -29,6 +30,7 @@ Examples plugin unload pair morse2/omp plugin unload command hello plugin list + plugin clear Description """"""""""" @@ -52,21 +54,25 @@ that style instance will be deleted. The *list* command will print a list of the loaded plugins and their styles and names. +The *clear* command will unload all currently loaded plugins. + Restrictions """""""""""" -Plugins are currently not available on Windows. +Plugins are not available on Windows. -For the loading of plugins to work, the LAMMPS library must be -:ref:`compiled as a shared library `. +For the loading of plugins to work the LAMMPS library must be +:ref:`compiled as a shared library `. If plugins +access functions or classes from a package, LAMMPS must have +been compiled with that package included. Plugins are dependent on the LAMMPS binary interface (ABI) and particularly the MPI library used. So they are not guaranteed to work when the plugin was compiled with a different MPI library or different compilation settings or a different LAMMPS version. -If there is a mismatch the *plugin* command may fail to load the -plugin(s) or data corruption or crashes may happen. +There are no checks, so if there is a mismatch the plugin object +will either not load or data corruption and crashes may happen. Related commands diff --git a/src/input.cpp b/src/input.cpp index 6d1564ecb6..1df60f5298 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1110,6 +1110,8 @@ void Input::plugin() } else if (cmd == "unload") { if (narg != 3) error->all(FLERR,"Illegal plugin unload command"); plugin_unload(arg[1],arg[2],lmp); + } else if (cmd == "clear") { + plugin_clear(lmp); } else if (cmd == "list") { if (comm->me == 0) { int num = plugin_get_num_plugins(); diff --git a/src/plugin.cpp b/src/plugin.cpp index fb3186c69e..99b1b086c5 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -238,6 +238,18 @@ namespace LAMMPS_NS } } + /* -------------------------------------------------------------------- + unload all loaded plugins + -------------------------------------------------------------------- */ + + void plugin_clear(LAMMPS *lmp) + { + while (pluginlist.size() > 0) { + auto p = pluginlist.begin(); + plugin_unload(p->style,p->name,lmp); + } + } + /* -------------------------------------------------------------------- remove plugin of given name and style from internal lists -------------------------------------------------------------------- */ diff --git a/src/plugin.h b/src/plugin.h index 32a5a280a1..90952224a6 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -25,6 +25,7 @@ namespace LAMMPS_NS void plugin_unload(const char *, const char *, LAMMPS *); void plugin_erase(const char *, const char *); + void plugin_clear(LAMMPS *); int plugin_get_num_plugins(); int plugin_find(const char *, const char *); diff --git a/tools/lammps-shell/lammps-shell.cpp b/tools/lammps-shell/lammps-shell.cpp index 8153c1bcfa..6c8873093f 100644 --- a/tools/lammps-shell/lammps-shell.cpp +++ b/tools/lammps-shell/lammps-shell.cpp @@ -350,7 +350,7 @@ static char *variable_expand_generator(const char *text, int state) static char *plugin_generator(const char *text, int state) { - const char *subcmd[] = {"load", "unload", "list", NULL}; + const char *subcmd[] = {"load", "unload", "list", "clear", NULL}; const char *sub; static std::size_t idx, len; if (!state) idx = 0; From 10189760c68799d957e29c389c06ceb6242e5822 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Mar 2021 12:40:49 -0500 Subject: [PATCH 054/257] fix issue of not removing unloaded plugins from fix map --- src/plugin.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/plugin.cpp b/src/plugin.cpp index 99b1b086c5..2d18da64ce 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -186,7 +186,7 @@ namespace LAMMPS_NS return; } - // copy of DSO handle for later + // make copy of DSO handle for later use void *handle = plugin_get_info(idx)->handle; // remove selected plugin from list of plugins @@ -201,6 +201,7 @@ namespace LAMMPS_NS std::string pstyle = style; if (pstyle == "pair") { + auto found = lmp->force->pair_map->find(name); if (found != lmp->force->pair_map->end()) lmp->force->pair_map->erase(found); @@ -218,14 +219,20 @@ namespace LAMMPS_NS } } else if (pstyle == "fix") { + + auto fix_map = lmp->modify->fix_map; + auto found = fix_map->find(name); + if (found != fix_map->end()) fix_map->erase(name); + for (int ifix = lmp->modify->find_fix_by_style(name); ifix >= 0; ifix = lmp->modify->find_fix_by_style(name)) lmp->modify->delete_fix(ifix); } else if (pstyle == "command") { + auto command_map = lmp->input->command_map; - auto cmd = command_map->find(name); - if (cmd != command_map->end()) command_map->erase(name); + auto found = command_map->find(name); + if (found != command_map->end()) command_map->erase(name); } // if reference count is down to zero, close DSO handle. From 98fa3661f382c423748f296e246417f5b4d0698e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Mar 2021 12:41:01 -0500 Subject: [PATCH 055/257] silence compiler warning --- src/library.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index ae3212d6f3..3fed6ba8cd 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -988,12 +988,12 @@ to then decide how to cast the (void*) pointer and access the data. \endverbatim * - * \param handle pointer to a previously created LAMMPS instance + * \param handle pointer to a previously created LAMMPS instance (unused) * \param name string with the name of the extracted property * \return integer constant encoding the data type of the property * or -1 if not found. */ -int lammps_extract_global_datatype(void *handle, const char *name) +int lammps_extract_global_datatype(void * /*handle*/, const char *name) { if (strcmp(name,"dt") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"ntimestep") == 0) return LAMMPS_BIGINT; From 15e30ed44da6d9147f08fedc44e5770df4c93da8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 13 Mar 2021 18:41:36 -0500 Subject: [PATCH 056/257] report dynamic linker error messages on failures --- src/plugin.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/plugin.cpp b/src/plugin.cpp index 2d18da64ce..e252ce67e1 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -48,23 +48,26 @@ namespace LAMMPS_NS // open DSO file from given path; load symbols globally + dlerror(); void *dso = dlopen(file,RTLD_NOW|RTLD_GLOBAL); if (dso == nullptr) { if (me == 0) - utils::logmesg(lmp,fmt::format("Open of file {} failed\n",file)); + utils::logmesg(lmp,fmt::format("Open of file {} failed: {}\n", + file,dlerror())); return; } // look up lammpsplugin_init() function in DSO // function must have C bindings so there is no name mangling + dlerror(); void *initfunc = dlsym(dso,"lammpsplugin_init"); if (initfunc == nullptr) { dlclose(dso); if (me == 0) utils::logmesg(lmp,fmt::format("Plugin symbol lookup failure in " - "file {}\n",file)); + "file {}: {}\n",file,dlerror())); return; } From 11d2b488c1ae18d3d2aaf83ed49025c4b4a0f174 Mon Sep 17 00:00:00 2001 From: Stephen Sanderson Date: Tue, 16 Mar 2021 16:51:10 +1000 Subject: [PATCH 057/257] Fixed incorrect scaling of cdof for 'norm all' --- src/fix_ave_chunk.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fix_ave_chunk.cpp b/src/fix_ave_chunk.cpp index 3b612aeb73..359e3ba588 100644 --- a/src/fix_ave_chunk.cpp +++ b/src/fix_ave_chunk.cpp @@ -881,7 +881,7 @@ void FixAveChunk::end_of_step() if (count_sum[m] > 0.0) for (j = 0; j < nvalues; j++) { if (which[j] == ArgInfo::TEMPERATURE) { - values_sum[m][j] *= mvv2e / ((cdof + adof*count_sum[m]) * boltz); + values_sum[m][j] *= mvv2e/((repeat*cdof + adof*count_sum[m])*boltz); } else if (which[j] == ArgInfo::DENSITY_NUMBER) { if (volflag == SCALAR) values_sum[m][j] /= chunk_volume_scalar; else values_sum[m][j] /= chunk_volume_vec[m]; From 6f07564a926fe3780ec741afb7c7d93760f8b195 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 16 Mar 2021 13:13:45 +0100 Subject: [PATCH 058/257] Create README --- python/examples/pylammps/elastic/README | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 python/examples/pylammps/elastic/README diff --git a/python/examples/pylammps/elastic/README b/python/examples/pylammps/elastic/README new file mode 100644 index 0000000000..8d1712cd10 --- /dev/null +++ b/python/examples/pylammps/elastic/README @@ -0,0 +1,4 @@ +conversion of lammps scripts to python code using PyLammps interface + +Example for elastic.py +python elastic.py Au.data EAM_Dynamo_Ackland_1987_Au__MO_754413982908_000 Au From a1d8e21b04d1b30d1c2957deed9f00ea32b093f6 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Tue, 16 Mar 2021 13:14:20 +0100 Subject: [PATCH 059/257] Add files via upload --- python/examples/pylammps/elastic/Au.data | 515 ++++++++++++++++++++ python/examples/pylammps/elastic/elastic.py | 309 ++++++++++++ 2 files changed, 824 insertions(+) create mode 100644 python/examples/pylammps/elastic/Au.data create mode 100644 python/examples/pylammps/elastic/elastic.py diff --git a/python/examples/pylammps/elastic/Au.data b/python/examples/pylammps/elastic/Au.data new file mode 100644 index 0000000000..0e953f8f79 --- /dev/null +++ b/python/examples/pylammps/elastic/Au.data @@ -0,0 +1,515 @@ +#Generated by cif2cell 1.2.10 from COD reference: 9008463. : Wyckoff, R. W. G., Crystal Structures 1, 7-83 (1963). + +500 atoms +1 atom types + +0.0 20.391250 xlo xhi +0.0 20.391250 ylo yhi +0.0 20.391250 zlo zhi + +Masses + +1 100 + +Atoms + +1 1 0.000000000000000 0.000000000000000 0.000000000000000 +2 1 0.000000000000000 2.039125000000000 2.039125000000000 +3 1 2.039125000000000 0.000000000000000 2.039125000000000 +4 1 2.039125000000000 2.039125000000000 0.000000000000000 +5 1 8.156499999999999 16.312999999999995 0.000000000000000 +6 1 12.234750000000002 4.078249999999999 0.000000000000000 +7 1 12.234750000000002 12.234750000000002 12.234750000000002 +8 1 0.000000000000000 0.000000000000000 12.234750000000002 +9 1 8.156499999999999 12.234750000000002 8.156499999999998 +10 1 8.156499999999999 4.078249999999999 0.000000000000000 +11 1 16.312999999999999 0.000000000000000 12.234750000000002 +12 1 4.078250000000000 12.234750000000002 8.156499999999998 +13 1 8.156499999999999 0.000000000000000 8.156499999999998 +14 1 16.312999999999999 16.312999999999995 8.156499999999998 +15 1 4.078250000000000 4.078249999999999 0.000000000000000 +16 1 16.312999999999999 8.156499999999998 0.000000000000000 +17 1 12.234750000000002 4.078249999999999 4.078249999999999 +18 1 16.312999999999999 0.000000000000000 16.312999999999995 +19 1 0.000000000000000 12.234750000000002 8.156499999999998 +20 1 16.312999999999999 8.156499999999998 12.234750000000002 +21 1 0.000000000000000 4.078249999999999 0.000000000000000 +22 1 16.312999999999999 0.000000000000000 4.078249999999999 +23 1 12.234750000000002 16.312999999999995 8.156499999999998 +24 1 12.234750000000002 4.078249999999999 8.156499999999998 +25 1 0.000000000000000 4.078249999999999 12.234750000000002 +26 1 8.156499999999999 16.312999999999995 8.156499999999998 +27 1 12.234750000000002 8.156499999999998 16.312999999999995 +28 1 8.156499999999999 8.156499999999998 0.000000000000000 +29 1 12.234750000000002 16.312999999999995 12.234750000000002 +30 1 12.234750000000002 0.000000000000000 4.078249999999999 +31 1 4.078250000000000 16.312999999999995 8.156499999999998 +32 1 12.234750000000002 4.078249999999999 12.234750000000002 +33 1 4.078250000000000 8.156499999999998 0.000000000000000 +34 1 16.312999999999999 12.234750000000002 0.000000000000000 +35 1 8.156499999999999 0.000000000000000 16.312999999999995 +36 1 8.156499999999999 8.156499999999998 4.078249999999999 +37 1 16.312999999999999 12.234750000000002 12.234750000000002 +38 1 4.078250000000000 0.000000000000000 4.078249999999999 +39 1 12.234750000000002 4.078249999999999 16.312999999999995 +40 1 16.312999999999999 4.078249999999999 4.078249999999999 +41 1 0.000000000000000 8.156499999999998 12.234750000000002 +42 1 16.312999999999999 4.078249999999999 16.312999999999995 +43 1 0.000000000000000 0.000000000000000 4.078249999999999 +44 1 8.156499999999999 8.156499999999998 8.156499999999998 +45 1 8.156499999999999 12.234750000000002 0.000000000000000 +46 1 0.000000000000000 0.000000000000000 16.312999999999995 +47 1 8.156499999999999 12.234750000000002 12.234750000000002 +48 1 8.156499999999999 4.078249999999999 4.078249999999999 +49 1 4.078250000000000 12.234750000000002 0.000000000000000 +50 1 12.234750000000002 8.156499999999998 4.078249999999999 +51 1 16.312999999999999 16.312999999999995 0.000000000000000 +52 1 8.156499999999999 8.156499999999998 12.234750000000002 +53 1 8.156499999999999 4.078249999999999 16.312999999999995 +54 1 16.312999999999999 16.312999999999995 12.234750000000002 +55 1 12.234750000000002 16.312999999999995 4.078249999999999 +56 1 4.078250000000000 4.078249999999999 4.078249999999999 +57 1 16.312999999999999 8.156499999999998 4.078249999999999 +58 1 8.156499999999999 4.078249999999999 8.156499999999998 +59 1 8.156499999999999 8.156499999999998 16.312999999999995 +60 1 4.078250000000000 4.078249999999999 16.312999999999995 +61 1 0.000000000000000 16.312999999999995 4.078249999999999 +62 1 16.312999999999999 8.156499999999998 16.312999999999995 +63 1 0.000000000000000 4.078249999999999 4.078249999999999 +64 1 16.312999999999999 0.000000000000000 8.156499999999998 +65 1 8.156499999999999 0.000000000000000 4.078249999999999 +66 1 8.156499999999999 4.078249999999999 12.234750000000002 +67 1 0.000000000000000 4.078249999999999 16.312999999999995 +68 1 8.156499999999999 16.312999999999995 12.234750000000002 +69 1 4.078250000000000 16.312999999999995 0.000000000000000 +70 1 4.078250000000000 8.156499999999998 4.078249999999999 +71 1 4.078250000000000 16.312999999999995 12.234750000000002 +72 1 4.078250000000000 12.234750000000002 12.234750000000002 +73 1 0.000000000000000 16.312999999999995 0.000000000000000 +74 1 16.312999999999999 12.234750000000002 4.078249999999999 +75 1 12.234750000000002 0.000000000000000 16.312999999999995 +76 1 4.078250000000000 8.156499999999998 16.312999999999995 +77 1 4.078250000000000 8.156499999999998 8.156499999999998 +78 1 16.312999999999999 12.234750000000002 16.312999999999995 +79 1 0.000000000000000 8.156499999999998 4.078249999999999 +80 1 16.312999999999999 4.078249999999999 8.156499999999998 +81 1 0.000000000000000 8.156499999999998 16.312999999999995 +82 1 0.000000000000000 12.234750000000002 0.000000000000000 +83 1 12.234750000000002 0.000000000000000 12.234750000000002 +84 1 12.234750000000002 12.234750000000002 16.312999999999995 +85 1 0.000000000000000 0.000000000000000 8.156499999999998 +86 1 4.078250000000000 8.156499999999998 12.234750000000002 +87 1 8.156499999999999 12.234750000000002 4.078249999999999 +88 1 12.234750000000002 16.312999999999995 0.000000000000000 +89 1 8.156499999999999 12.234750000000002 16.312999999999995 +90 1 0.000000000000000 12.234750000000002 4.078249999999999 +91 1 4.078250000000000 12.234750000000002 4.078249999999999 +92 1 12.234750000000002 0.000000000000000 8.156499999999998 +93 1 16.312999999999999 16.312999999999995 4.078249999999999 +94 1 0.000000000000000 16.312999999999995 12.234750000000002 +95 1 4.078250000000000 12.234750000000002 16.312999999999995 +96 1 16.312999999999999 16.312999999999995 16.312999999999995 +97 1 0.000000000000000 8.156499999999998 0.000000000000000 +98 1 12.234750000000002 8.156499999999998 8.156499999999998 +99 1 4.078250000000000 4.078249999999999 8.156499999999998 +100 1 16.312999999999999 8.156499999999998 8.156499999999998 +101 1 4.078250000000000 4.078249999999999 12.234750000000002 +102 1 16.312999999999999 0.000000000000000 0.000000000000000 +103 1 0.000000000000000 12.234750000000002 16.312999999999995 +104 1 12.234750000000002 16.312999999999995 16.312999999999995 +105 1 12.234750000000002 12.234750000000002 0.000000000000000 +106 1 0.000000000000000 4.078249999999999 8.156499999999998 +107 1 8.156499999999999 16.312999999999995 4.078249999999999 +108 1 4.078250000000000 0.000000000000000 8.156499999999998 +109 1 12.234750000000002 0.000000000000000 0.000000000000000 +110 1 0.000000000000000 12.234750000000002 12.234750000000002 +111 1 0.000000000000000 16.312999999999995 8.156499999999998 +112 1 8.156499999999999 16.312999999999995 16.312999999999995 +113 1 12.234750000000002 8.156499999999998 12.234750000000002 +114 1 4.078250000000000 16.312999999999995 4.078249999999999 +115 1 12.234750000000002 12.234750000000002 4.078249999999999 +116 1 8.156499999999999 0.000000000000000 0.000000000000000 +117 1 0.000000000000000 8.156499999999998 8.156499999999998 +118 1 4.078250000000000 16.312999999999995 16.312999999999995 +119 1 8.156499999999999 0.000000000000000 12.234750000000002 +120 1 12.234750000000002 8.156499999999998 0.000000000000000 +121 1 16.312999999999999 12.234750000000002 8.156499999999998 +122 1 4.078250000000000 0.000000000000000 0.000000000000000 +123 1 12.234750000000002 12.234750000000002 8.156499999999998 +124 1 16.312999999999999 4.078249999999999 0.000000000000000 +125 1 0.000000000000000 16.312999999999995 16.312999999999995 +126 1 4.078250000000000 0.000000000000000 16.312999999999995 +127 1 4.078250000000000 0.000000000000000 12.234750000000002 +128 1 16.312999999999999 4.078249999999999 12.234750000000002 +129 1 8.156499999999999 18.352124999999997 2.039125000000000 +130 1 12.234750000000002 6.117374999999998 2.039125000000000 +131 1 12.234750000000002 14.273875000000000 14.273875000000000 +132 1 0.000000000000000 2.039125000000000 14.273875000000000 +133 1 8.156499999999999 14.273875000000000 10.195625000000000 +134 1 8.156499999999999 6.117374999999998 2.039125000000000 +135 1 16.312999999999999 2.039125000000000 14.273875000000000 +136 1 4.078250000000000 14.273875000000000 10.195625000000000 +137 1 8.156499999999999 2.039125000000000 10.195625000000000 +138 1 16.312999999999999 18.352124999999997 10.195625000000000 +139 1 4.078250000000000 6.117374999999998 2.039125000000000 +140 1 16.312999999999999 10.195625000000000 2.039125000000000 +141 1 12.234750000000002 6.117374999999998 6.117374999999998 +142 1 16.312999999999999 2.039125000000000 18.352124999999997 +143 1 0.000000000000000 14.273875000000000 10.195625000000000 +144 1 16.312999999999999 10.195625000000000 14.273875000000000 +145 1 0.000000000000000 6.117374999999998 2.039125000000000 +146 1 16.312999999999999 2.039125000000000 6.117374999999998 +147 1 12.234750000000002 18.352124999999997 10.195625000000000 +148 1 12.234750000000002 6.117374999999998 10.195625000000000 +149 1 0.000000000000000 6.117374999999998 14.273875000000000 +150 1 8.156499999999999 18.352124999999997 10.195625000000000 +151 1 12.234750000000002 10.195625000000000 18.352124999999997 +152 1 8.156499999999999 10.195625000000000 2.039125000000000 +153 1 12.234750000000002 18.352124999999997 14.273875000000000 +154 1 12.234750000000002 2.039125000000000 6.117374999999998 +155 1 4.078250000000000 18.352124999999997 10.195625000000000 +156 1 12.234750000000002 6.117374999999998 14.273875000000000 +157 1 4.078250000000000 10.195625000000000 2.039125000000000 +158 1 16.312999999999999 14.273875000000000 2.039125000000000 +159 1 8.156499999999999 2.039125000000000 18.352124999999997 +160 1 8.156499999999999 10.195625000000000 6.117374999999998 +161 1 16.312999999999999 14.273875000000000 14.273875000000000 +162 1 4.078250000000000 2.039125000000000 6.117374999999998 +163 1 12.234750000000002 6.117374999999998 18.352124999999997 +164 1 16.312999999999999 6.117374999999998 6.117374999999998 +165 1 0.000000000000000 10.195625000000000 14.273875000000000 +166 1 16.312999999999999 6.117374999999998 18.352124999999997 +167 1 0.000000000000000 2.039125000000000 6.117374999999998 +168 1 8.156499999999999 10.195625000000000 10.195625000000000 +169 1 8.156499999999999 14.273875000000000 2.039125000000000 +170 1 0.000000000000000 2.039125000000000 18.352124999999997 +171 1 8.156499999999999 14.273875000000000 14.273875000000000 +172 1 8.156499999999999 6.117374999999998 6.117374999999998 +173 1 4.078250000000000 14.273875000000000 2.039125000000000 +174 1 12.234750000000002 10.195625000000000 6.117374999999998 +175 1 16.312999999999999 18.352124999999997 2.039125000000000 +176 1 8.156499999999999 10.195625000000000 14.273875000000000 +177 1 8.156499999999999 6.117374999999998 18.352124999999997 +178 1 16.312999999999999 18.352124999999997 14.273875000000000 +179 1 12.234750000000002 18.352124999999997 6.117374999999998 +180 1 4.078250000000000 6.117374999999998 6.117374999999998 +181 1 16.312999999999999 10.195625000000000 6.117374999999998 +182 1 8.156499999999999 6.117374999999998 10.195625000000000 +183 1 8.156499999999999 10.195625000000000 18.352124999999997 +184 1 4.078250000000000 6.117374999999998 18.352124999999997 +185 1 0.000000000000000 18.352124999999997 6.117374999999998 +186 1 16.312999999999999 10.195625000000000 18.352124999999997 +187 1 0.000000000000000 6.117374999999998 6.117374999999998 +188 1 16.312999999999999 2.039125000000000 10.195625000000000 +189 1 8.156499999999999 2.039125000000000 6.117374999999998 +190 1 8.156499999999999 6.117374999999998 14.273875000000000 +191 1 0.000000000000000 6.117374999999998 18.352124999999997 +192 1 8.156499999999999 18.352124999999997 14.273875000000000 +193 1 4.078250000000000 18.352124999999997 2.039125000000000 +194 1 4.078250000000000 10.195625000000000 6.117374999999998 +195 1 4.078250000000000 18.352124999999997 14.273875000000000 +196 1 4.078250000000000 14.273875000000000 14.273875000000000 +197 1 0.000000000000000 18.352124999999997 2.039125000000000 +198 1 16.312999999999999 14.273875000000000 6.117374999999998 +199 1 12.234750000000002 2.039125000000000 18.352124999999997 +200 1 4.078250000000000 10.195625000000000 18.352124999999997 +201 1 4.078250000000000 10.195625000000000 10.195625000000000 +202 1 16.312999999999999 14.273875000000000 18.352124999999997 +203 1 0.000000000000000 10.195625000000000 6.117374999999998 +204 1 16.312999999999999 6.117374999999998 10.195625000000000 +205 1 0.000000000000000 10.195625000000000 18.352124999999997 +206 1 0.000000000000000 14.273875000000000 2.039125000000000 +207 1 12.234750000000002 2.039125000000000 14.273875000000000 +208 1 12.234750000000002 14.273875000000000 18.352124999999997 +209 1 0.000000000000000 2.039125000000000 10.195625000000000 +210 1 4.078250000000000 10.195625000000000 14.273875000000000 +211 1 8.156499999999999 14.273875000000000 6.117374999999998 +212 1 12.234750000000002 18.352124999999997 2.039125000000000 +213 1 8.156499999999999 14.273875000000000 18.352124999999997 +214 1 0.000000000000000 14.273875000000000 6.117374999999998 +215 1 4.078250000000000 14.273875000000000 6.117374999999998 +216 1 12.234750000000002 2.039125000000000 10.195625000000000 +217 1 16.312999999999999 18.352124999999997 6.117374999999998 +218 1 0.000000000000000 18.352124999999997 14.273875000000000 +219 1 4.078250000000000 14.273875000000000 18.352124999999997 +220 1 16.312999999999999 18.352124999999997 18.352124999999997 +221 1 0.000000000000000 10.195625000000000 2.039125000000000 +222 1 12.234750000000002 10.195625000000000 10.195625000000000 +223 1 4.078250000000000 6.117374999999998 10.195625000000000 +224 1 16.312999999999999 10.195625000000000 10.195625000000000 +225 1 4.078250000000000 6.117374999999998 14.273875000000000 +226 1 16.312999999999999 2.039125000000000 2.039125000000000 +227 1 0.000000000000000 14.273875000000000 18.352124999999997 +228 1 12.234750000000002 18.352124999999997 18.352124999999997 +229 1 12.234750000000002 14.273875000000000 2.039125000000000 +230 1 0.000000000000000 6.117374999999998 10.195625000000000 +231 1 8.156499999999999 18.352124999999997 6.117374999999998 +232 1 4.078250000000000 2.039125000000000 10.195625000000000 +233 1 12.234750000000002 2.039125000000000 2.039125000000000 +234 1 0.000000000000000 14.273875000000000 14.273875000000000 +235 1 0.000000000000000 18.352124999999997 10.195625000000000 +236 1 8.156499999999999 18.352124999999997 18.352124999999997 +237 1 12.234750000000002 10.195625000000000 14.273875000000000 +238 1 4.078250000000000 18.352124999999997 6.117374999999998 +239 1 12.234750000000002 14.273875000000000 6.117374999999998 +240 1 8.156499999999999 2.039125000000000 2.039125000000000 +241 1 0.000000000000000 10.195625000000000 10.195625000000000 +242 1 4.078250000000000 18.352124999999997 18.352124999999997 +243 1 8.156499999999999 2.039125000000000 14.273875000000000 +244 1 12.234750000000002 10.195625000000000 2.039125000000000 +245 1 16.312999999999999 14.273875000000000 10.195625000000000 +246 1 4.078250000000000 2.039125000000000 2.039125000000000 +247 1 12.234750000000002 14.273875000000000 10.195625000000000 +248 1 16.312999999999999 6.117374999999998 2.039125000000000 +249 1 0.000000000000000 18.352124999999997 18.352124999999997 +250 1 4.078250000000000 2.039125000000000 18.352124999999997 +251 1 4.078250000000000 2.039125000000000 14.273875000000000 +252 1 16.312999999999999 6.117374999999998 14.273875000000000 +253 1 10.195625000000000 16.312999999999995 2.039125000000000 +254 1 14.273875000000004 4.078249999999999 2.039125000000000 +255 1 14.273875000000004 12.234750000000002 14.273875000000000 +256 1 2.039125000000000 0.000000000000000 14.273875000000000 +257 1 10.195625000000000 12.234750000000002 10.195625000000000 +258 1 10.195625000000000 4.078249999999999 2.039125000000000 +259 1 18.352125000000001 0.000000000000000 14.273875000000000 +260 1 6.117375000000001 12.234750000000002 10.195625000000000 +261 1 10.195625000000000 0.000000000000000 10.195625000000000 +262 1 18.352125000000001 16.312999999999995 10.195625000000000 +263 1 6.117375000000001 4.078249999999999 2.039125000000000 +264 1 18.352125000000001 8.156499999999998 2.039125000000000 +265 1 14.273875000000004 4.078249999999999 6.117374999999998 +266 1 18.352125000000001 0.000000000000000 18.352124999999997 +267 1 2.039125000000000 12.234750000000002 10.195625000000000 +268 1 18.352125000000001 8.156499999999998 14.273875000000000 +269 1 2.039125000000000 4.078249999999999 2.039125000000000 +270 1 18.352125000000001 0.000000000000000 6.117374999999998 +271 1 14.273875000000004 16.312999999999995 10.195625000000000 +272 1 14.273875000000004 4.078249999999999 10.195625000000000 +273 1 2.039125000000000 4.078249999999999 14.273875000000000 +274 1 10.195625000000000 16.312999999999995 10.195625000000000 +275 1 14.273875000000004 8.156499999999998 18.352124999999997 +276 1 10.195625000000000 8.156499999999998 2.039125000000000 +277 1 14.273875000000004 16.312999999999995 14.273875000000000 +278 1 14.273875000000004 0.000000000000000 6.117374999999998 +279 1 6.117375000000001 16.312999999999995 10.195625000000000 +280 1 14.273875000000004 4.078249999999999 14.273875000000000 +281 1 6.117375000000001 8.156499999999998 2.039125000000000 +282 1 18.352125000000001 12.234750000000002 2.039125000000000 +283 1 10.195625000000000 0.000000000000000 18.352124999999997 +284 1 10.195625000000000 8.156499999999998 6.117374999999998 +285 1 18.352125000000001 12.234750000000002 14.273875000000000 +286 1 6.117375000000001 0.000000000000000 6.117374999999998 +287 1 14.273875000000004 4.078249999999999 18.352124999999997 +288 1 18.352125000000001 4.078249999999999 6.117374999999998 +289 1 2.039125000000000 8.156499999999998 14.273875000000000 +290 1 18.352125000000001 4.078249999999999 18.352124999999997 +291 1 2.039125000000000 0.000000000000000 6.117374999999998 +292 1 10.195625000000000 8.156499999999998 10.195625000000000 +293 1 10.195625000000000 12.234750000000002 2.039125000000000 +294 1 2.039125000000000 0.000000000000000 18.352124999999997 +295 1 10.195625000000000 12.234750000000002 14.273875000000000 +296 1 10.195625000000000 4.078249999999999 6.117374999999998 +297 1 6.117375000000001 12.234750000000002 2.039125000000000 +298 1 14.273875000000004 8.156499999999998 6.117374999999998 +299 1 18.352125000000001 16.312999999999995 2.039125000000000 +300 1 10.195625000000000 8.156499999999998 14.273875000000000 +301 1 10.195625000000000 4.078249999999999 18.352124999999997 +302 1 18.352125000000001 16.312999999999995 14.273875000000000 +303 1 14.273875000000004 16.312999999999995 6.117374999999998 +304 1 6.117375000000001 4.078249999999999 6.117374999999998 +305 1 18.352125000000001 8.156499999999998 6.117374999999998 +306 1 10.195625000000000 4.078249999999999 10.195625000000000 +307 1 10.195625000000000 8.156499999999998 18.352124999999997 +308 1 6.117375000000001 4.078249999999999 18.352124999999997 +309 1 2.039125000000000 16.312999999999995 6.117374999999998 +310 1 18.352125000000001 8.156499999999998 18.352124999999997 +311 1 2.039125000000000 4.078249999999999 6.117374999999998 +312 1 18.352125000000001 0.000000000000000 10.195625000000000 +313 1 10.195625000000000 0.000000000000000 6.117374999999998 +314 1 10.195625000000000 4.078249999999999 14.273875000000000 +315 1 2.039125000000000 4.078249999999999 18.352124999999997 +316 1 10.195625000000000 16.312999999999995 14.273875000000000 +317 1 6.117375000000001 16.312999999999995 2.039125000000000 +318 1 6.117375000000001 8.156499999999998 6.117374999999998 +319 1 6.117375000000001 16.312999999999995 14.273875000000000 +320 1 6.117375000000001 12.234750000000002 14.273875000000000 +321 1 2.039125000000000 16.312999999999995 2.039125000000000 +322 1 18.352125000000001 12.234750000000002 6.117374999999998 +323 1 14.273875000000004 0.000000000000000 18.352124999999997 +324 1 6.117375000000001 8.156499999999998 18.352124999999997 +325 1 6.117375000000001 8.156499999999998 10.195625000000000 +326 1 18.352125000000001 12.234750000000002 18.352124999999997 +327 1 2.039125000000000 8.156499999999998 6.117374999999998 +328 1 18.352125000000001 4.078249999999999 10.195625000000000 +329 1 2.039125000000000 8.156499999999998 18.352124999999997 +330 1 2.039125000000000 12.234750000000002 2.039125000000000 +331 1 14.273875000000004 0.000000000000000 14.273875000000000 +332 1 14.273875000000004 12.234750000000002 18.352124999999997 +333 1 2.039125000000000 0.000000000000000 10.195625000000000 +334 1 6.117375000000001 8.156499999999998 14.273875000000000 +335 1 10.195625000000000 12.234750000000002 6.117374999999998 +336 1 14.273875000000004 16.312999999999995 2.039125000000000 +337 1 10.195625000000000 12.234750000000002 18.352124999999997 +338 1 2.039125000000000 12.234750000000002 6.117374999999998 +339 1 6.117375000000001 12.234750000000002 6.117374999999998 +340 1 14.273875000000004 0.000000000000000 10.195625000000000 +341 1 18.352125000000001 16.312999999999995 6.117374999999998 +342 1 2.039125000000000 16.312999999999995 14.273875000000000 +343 1 6.117375000000001 12.234750000000002 18.352124999999997 +344 1 18.352125000000001 16.312999999999995 18.352124999999997 +345 1 2.039125000000000 8.156499999999998 2.039125000000000 +346 1 14.273875000000004 8.156499999999998 10.195625000000000 +347 1 6.117375000000001 4.078249999999999 10.195625000000000 +348 1 18.352125000000001 8.156499999999998 10.195625000000000 +349 1 6.117375000000001 4.078249999999999 14.273875000000000 +350 1 18.352125000000001 0.000000000000000 2.039125000000000 +351 1 2.039125000000000 12.234750000000002 18.352124999999997 +352 1 14.273875000000004 16.312999999999995 18.352124999999997 +353 1 14.273875000000004 12.234750000000002 2.039125000000000 +354 1 2.039125000000000 4.078249999999999 10.195625000000000 +355 1 10.195625000000000 16.312999999999995 6.117374999999998 +356 1 6.117375000000001 0.000000000000000 10.195625000000000 +357 1 14.273875000000004 0.000000000000000 2.039125000000000 +358 1 2.039125000000000 12.234750000000002 14.273875000000000 +359 1 2.039125000000000 16.312999999999995 10.195625000000000 +360 1 10.195625000000000 16.312999999999995 18.352124999999997 +361 1 14.273875000000004 8.156499999999998 14.273875000000000 +362 1 6.117375000000001 16.312999999999995 6.117374999999998 +363 1 14.273875000000004 12.234750000000002 6.117374999999998 +364 1 10.195625000000000 0.000000000000000 2.039125000000000 +365 1 2.039125000000000 8.156499999999998 10.195625000000000 +366 1 6.117375000000001 16.312999999999995 18.352124999999997 +367 1 10.195625000000000 0.000000000000000 14.273875000000000 +368 1 14.273875000000004 8.156499999999998 2.039125000000000 +369 1 18.352125000000001 12.234750000000002 10.195625000000000 +370 1 6.117375000000001 0.000000000000000 2.039125000000000 +371 1 14.273875000000004 12.234750000000002 10.195625000000000 +372 1 18.352125000000001 4.078249999999999 2.039125000000000 +373 1 2.039125000000000 16.312999999999995 18.352124999999997 +374 1 6.117375000000001 0.000000000000000 18.352124999999997 +375 1 6.117375000000001 0.000000000000000 14.273875000000000 +376 1 18.352125000000001 4.078249999999999 14.273875000000000 +377 1 10.195625000000000 18.352124999999997 0.000000000000000 +378 1 14.273875000000004 6.117374999999998 0.000000000000000 +379 1 14.273875000000004 14.273875000000000 12.234750000000002 +380 1 2.039125000000000 2.039125000000000 12.234750000000002 +381 1 10.195625000000000 14.273875000000000 8.156499999999998 +382 1 10.195625000000000 6.117374999999998 0.000000000000000 +383 1 18.352125000000001 2.039125000000000 12.234750000000002 +384 1 6.117375000000001 14.273875000000000 8.156499999999998 +385 1 10.195625000000000 2.039125000000000 8.156499999999998 +386 1 18.352125000000001 18.352124999999997 8.156499999999998 +387 1 6.117375000000001 6.117374999999998 0.000000000000000 +388 1 18.352125000000001 10.195625000000000 0.000000000000000 +389 1 14.273875000000004 6.117374999999998 4.078249999999999 +390 1 18.352125000000001 2.039125000000000 16.312999999999995 +391 1 2.039125000000000 14.273875000000000 8.156499999999998 +392 1 18.352125000000001 10.195625000000000 12.234750000000002 +393 1 2.039125000000000 6.117374999999998 0.000000000000000 +394 1 18.352125000000001 2.039125000000000 4.078249999999999 +395 1 14.273875000000004 18.352124999999997 8.156499999999998 +396 1 14.273875000000004 6.117374999999998 8.156499999999998 +397 1 2.039125000000000 6.117374999999998 12.234750000000002 +398 1 10.195625000000000 18.352124999999997 8.156499999999998 +399 1 14.273875000000004 10.195625000000000 16.312999999999995 +400 1 10.195625000000000 10.195625000000000 0.000000000000000 +401 1 14.273875000000004 18.352124999999997 12.234750000000002 +402 1 14.273875000000004 2.039125000000000 4.078249999999999 +403 1 6.117375000000001 18.352124999999997 8.156499999999998 +404 1 14.273875000000004 6.117374999999998 12.234750000000002 +405 1 6.117375000000001 10.195625000000000 0.000000000000000 +406 1 18.352125000000001 14.273875000000000 0.000000000000000 +407 1 10.195625000000000 2.039125000000000 16.312999999999995 +408 1 10.195625000000000 10.195625000000000 4.078249999999999 +409 1 18.352125000000001 14.273875000000000 12.234750000000002 +410 1 6.117375000000001 2.039125000000000 4.078249999999999 +411 1 14.273875000000004 6.117374999999998 16.312999999999995 +412 1 18.352125000000001 6.117374999999998 4.078249999999999 +413 1 2.039125000000000 10.195625000000000 12.234750000000002 +414 1 18.352125000000001 6.117374999999998 16.312999999999995 +415 1 2.039125000000000 2.039125000000000 4.078249999999999 +416 1 10.195625000000000 10.195625000000000 8.156499999999998 +417 1 10.195625000000000 14.273875000000000 0.000000000000000 +418 1 2.039125000000000 2.039125000000000 16.312999999999995 +419 1 10.195625000000000 14.273875000000000 12.234750000000002 +420 1 10.195625000000000 6.117374999999998 4.078249999999999 +421 1 6.117375000000001 14.273875000000000 0.000000000000000 +422 1 14.273875000000004 10.195625000000000 4.078249999999999 +423 1 18.352125000000001 18.352124999999997 0.000000000000000 +424 1 10.195625000000000 10.195625000000000 12.234750000000002 +425 1 10.195625000000000 6.117374999999998 16.312999999999995 +426 1 18.352125000000001 18.352124999999997 12.234750000000002 +427 1 14.273875000000004 18.352124999999997 4.078249999999999 +428 1 6.117375000000001 6.117374999999998 4.078249999999999 +429 1 18.352125000000001 10.195625000000000 4.078249999999999 +430 1 10.195625000000000 6.117374999999998 8.156499999999998 +431 1 10.195625000000000 10.195625000000000 16.312999999999995 +432 1 6.117375000000001 6.117374999999998 16.312999999999995 +433 1 2.039125000000000 18.352124999999997 4.078249999999999 +434 1 18.352125000000001 10.195625000000000 16.312999999999995 +435 1 2.039125000000000 6.117374999999998 4.078249999999999 +436 1 18.352125000000001 2.039125000000000 8.156499999999998 +437 1 10.195625000000000 2.039125000000000 4.078249999999999 +438 1 10.195625000000000 6.117374999999998 12.234750000000002 +439 1 2.039125000000000 6.117374999999998 16.312999999999995 +440 1 10.195625000000000 18.352124999999997 12.234750000000002 +441 1 6.117375000000001 18.352124999999997 0.000000000000000 +442 1 6.117375000000001 10.195625000000000 4.078249999999999 +443 1 6.117375000000001 18.352124999999997 12.234750000000002 +444 1 6.117375000000001 14.273875000000000 12.234750000000002 +445 1 2.039125000000000 18.352124999999997 0.000000000000000 +446 1 18.352125000000001 14.273875000000000 4.078249999999999 +447 1 14.273875000000004 2.039125000000000 16.312999999999995 +448 1 6.117375000000001 10.195625000000000 16.312999999999995 +449 1 6.117375000000001 10.195625000000000 8.156499999999998 +450 1 18.352125000000001 14.273875000000000 16.312999999999995 +451 1 2.039125000000000 10.195625000000000 4.078249999999999 +452 1 18.352125000000001 6.117374999999998 8.156499999999998 +453 1 2.039125000000000 10.195625000000000 16.312999999999995 +454 1 2.039125000000000 14.273875000000000 0.000000000000000 +455 1 14.273875000000004 2.039125000000000 12.234750000000002 +456 1 14.273875000000004 14.273875000000000 16.312999999999995 +457 1 2.039125000000000 2.039125000000000 8.156499999999998 +458 1 6.117375000000001 10.195625000000000 12.234750000000002 +459 1 10.195625000000000 14.273875000000000 4.078249999999999 +460 1 14.273875000000004 18.352124999999997 0.000000000000000 +461 1 10.195625000000000 14.273875000000000 16.312999999999995 +462 1 2.039125000000000 14.273875000000000 4.078249999999999 +463 1 6.117375000000001 14.273875000000000 4.078249999999999 +464 1 14.273875000000004 2.039125000000000 8.156499999999998 +465 1 18.352125000000001 18.352124999999997 4.078249999999999 +466 1 2.039125000000000 18.352124999999997 12.234750000000002 +467 1 6.117375000000001 14.273875000000000 16.312999999999995 +468 1 18.352125000000001 18.352124999999997 16.312999999999995 +469 1 2.039125000000000 10.195625000000000 0.000000000000000 +470 1 14.273875000000004 10.195625000000000 8.156499999999998 +471 1 6.117375000000001 6.117374999999998 8.156499999999998 +472 1 18.352125000000001 10.195625000000000 8.156499999999998 +473 1 6.117375000000001 6.117374999999998 12.234750000000002 +474 1 18.352125000000001 2.039125000000000 0.000000000000000 +475 1 2.039125000000000 14.273875000000000 16.312999999999995 +476 1 14.273875000000004 18.352124999999997 16.312999999999995 +477 1 14.273875000000004 14.273875000000000 0.000000000000000 +478 1 2.039125000000000 6.117374999999998 8.156499999999998 +479 1 10.195625000000000 18.352124999999997 4.078249999999999 +480 1 6.117375000000001 2.039125000000000 8.156499999999998 +481 1 14.273875000000004 2.039125000000000 0.000000000000000 +482 1 2.039125000000000 14.273875000000000 12.234750000000002 +483 1 2.039125000000000 18.352124999999997 8.156499999999998 +484 1 10.195625000000000 18.352124999999997 16.312999999999995 +485 1 14.273875000000004 10.195625000000000 12.234750000000002 +486 1 6.117375000000001 18.352124999999997 4.078249999999999 +487 1 14.273875000000004 14.273875000000000 4.078249999999999 +488 1 10.195625000000000 2.039125000000000 0.000000000000000 +489 1 2.039125000000000 10.195625000000000 8.156499999999998 +490 1 6.117375000000001 18.352124999999997 16.312999999999995 +491 1 10.195625000000000 2.039125000000000 12.234750000000002 +492 1 14.273875000000004 10.195625000000000 0.000000000000000 +493 1 18.352125000000001 14.273875000000000 8.156499999999998 +494 1 6.117375000000001 2.039125000000000 0.000000000000000 +495 1 14.273875000000004 14.273875000000000 8.156499999999998 +496 1 18.352125000000001 6.117374999999998 0.000000000000000 +497 1 2.039125000000000 18.352124999999997 16.312999999999995 +498 1 6.117375000000001 2.039125000000000 16.312999999999995 +499 1 6.117375000000001 2.039125000000000 12.234750000000002 +500 1 18.352125000000001 6.117374999999998 12.234750000000002 diff --git a/python/examples/pylammps/elastic/elastic.py b/python/examples/pylammps/elastic/elastic.py new file mode 100644 index 0000000000..81d3832480 --- /dev/null +++ b/python/examples/pylammps/elastic/elastic.py @@ -0,0 +1,309 @@ + +from argparse import ArgumentParser +from lammps import PyLammps + +def potential(lmp, args): + """ set up potential and minimization """ + ff_string = ' ' + ff_string = ff_string.join(args.elements) # merge all element string to one string + lmp.kim_interactions(ff_string) + + # Setup neighbor style + lmp.neighbor(1.0, "nsq") + lmp.neigh_modify("once no every 1 delay 0 check yes") + + # Setup minimization style + lmp.min_style(args.min_style) + lmp.min_modify("dmax ${dmax} line quadratic") + + # Setup output + lmp.thermo(1) + lmp.thermo_style("custom step temp pe press pxx pyy pzz pxy pxz pyz lx ly lz") + lmp.thermo_modify("norm no") + + return + +def displace(lmp, args, idir): + """computes the response to a small strain """ + + if idir == 1: + lmp.variable("len0 equal {}".format(lmp.variables["lx0"].value)) + elif idir == 2 or idir == 6: + lmp.variable("len0 equal {}".format(lmp.variables["ly0"].value)) + else: + lmp.variable("len0 equal {}".format(lmp.variables["lz0"].value)) + + # Reset box and simulation parameters + lmp.clear() + lmp.box("tilt large") + lmp.kim_init(args.kim_model, "metal", "unit_conversion_mode") + lmp.read_restart("restart.equil") + lmp.change_box("all triclinic") + potential(lmp, args) + + # Negative deformation + lmp.variable("delta equal -${up}*${len0}") + lmp.variable("deltaxy equal -${up}*xy") + lmp.variable("deltaxz equal -${up}*xz") + lmp.variable("deltayz equal -${up}*yz") + + if idir == 1: + lmp.change_box("all x delta 0 ${delta} xy delta ${deltaxy} xz delta ${deltaxz} remap units box") + elif idir == 2: + lmp.change_box("all y delta 0 ${delta} yz delta ${deltayz} remap units box") + elif idir == 3: + lmp.change_box("all z delta 0 ${delta} remap units box") + elif idir == 4: + lmp.change_box("all yz delta ${delta} remap units box") + elif idir == 5: + lmp.change_box("all xz delta ${delta} remap units box") + else: + lmp.change_box("all xy delta ${delta} remap units box") + + # Relax atoms positions + lmp.min_style(args.min_style) + lmp.minimize(args.minimize[0], args.minimize[1], int(args.minimize[2]), int(args.minimize[3])) + + # Obtain new stress tensor + lmp.variable("pxx1 equal {}".format(lmp.eval("pxx"))) + lmp.variable("pyy1 equal {}".format(lmp.eval("pyy"))) + lmp.variable("pzz1 equal {}".format(lmp.eval("pzz"))) + lmp.variable("pxy1 equal {}".format(lmp.eval("pxy"))) + lmp.variable("pxz1 equal {}".format(lmp.eval("pxz"))) + lmp.variable("pyz1 equal {}".format(lmp.eval("pyz"))) + + # Compute elastic constant from pressure tensor + c1neg = lmp.variables["d1"].value + c2neg = lmp.variables["d2"].value + c3neg = lmp.variables["d3"].value + c4neg = lmp.variables["d4"].value + c5neg = lmp.variables["d5"].value + c6neg = lmp.variables["d6"].value + + # Reset box and simulation parameters + lmp.clear() + lmp.box("tilt large") + lmp.kim_init(args.kim_model, "metal", "unit_conversion_mode") + lmp.read_restart("restart.equil") + lmp.change_box("all triclinic") + potential(lmp, args) + + # Positive deformation + lmp.variable("delta equal ${up}*${len0}") + lmp.variable("deltaxy equal ${up}*xy") + lmp.variable("deltaxz equal ${up}*xz") + lmp.variable("deltayz equal ${up}*yz") + + if idir == 1: + lmp.change_box("all x delta 0 ${delta} xy delta ${deltaxy} xz delta ${deltaxz} remap units box") + elif idir == 2: + lmp.change_box("all y delta 0 ${delta} yz delta ${deltayz} remap units box") + elif idir == 3: + lmp.change_box("all z delta 0 ${delta} remap units box") + elif idir == 4: + lmp.change_box("all yz delta ${delta} remap units box") + elif idir == 5: + lmp.change_box("all xz delta ${delta} remap units box") + else: + lmp.change_box("all xy delta ${delta} remap units box") + + # Relax atoms positions + lmp.min_style(args.min_style) + lmp.minimize(args.minimize[0], args.minimize[1], int(args.minimize[2]), int(args.minimize[3])) + + # Obtain new stress tensor + lmp.variable("pxx1 equal {}".format(lmp.eval("pxx"))) + lmp.variable("pyy1 equal {}".format(lmp.eval("pyy"))) + lmp.variable("pzz1 equal {}".format(lmp.eval("pzz"))) + lmp.variable("pxy1 equal {}".format(lmp.eval("pxy"))) + lmp.variable("pxz1 equal {}".format(lmp.eval("pxz"))) + lmp.variable("pyz1 equal {}".format(lmp.eval("pyz"))) + + # Compute elasic constant from pressure tensor + c1pos = lmp.variables["d1"].value + c2pos = lmp.variables["d2"].value + c3pos = lmp.variables["d3"].value + c4pos = lmp.variables["d4"].value + c5pos = lmp.variables["d5"].value + c6pos = lmp.variables["d6"].value + + # Combine posiive and negative + lmp.variable("C1{} equal {}".format(idir, 0.5*(c1neg+c1pos))) + lmp.variable("C2{} equal {}".format(idir, 0.5*(c2neg+c2pos))) + lmp.variable("C3{} equal {}".format(idir, 0.5*(c3neg+c3pos))) + lmp.variable("C4{} equal {}".format(idir, 0.5*(c4neg+c4pos))) + lmp.variable("C5{} equal {}".format(idir, 0.5*(c5neg+c5pos))) + lmp.variable("C6{} equal {}".format(idir, 0.5*(c6neg+c6pos))) + + return + +def elastic(): + """ Compute elastic constant tensor for a crystal + + In order to calculate the elastic constants correctly, care must be taken to specify + the correct units (units). It is also important to verify that the minimization of energy + w.r.t atom positions in the deformed cell is fully converged. + One indication of this is that the elastic constants are insensitive + to the choice of the variable ${up}. Another is to check + the final max and two-norm forces reported in the log file. If you know + that minimization is not required, you can set maxiter = 0.0 """ + + parser = ArgumentParser(description='A python script to compute elastic properties of bulk materials') + + parser.add_argument("input_data_file", help="The full path & name of the lammps data file.") + parser.add_argument("kim_model", help="the KIM ID of the interatomic model archived in OpenKIM") + parser.add_argument("elements", nargs='+', default=['Au'], help="a list of N chemical species, which defines a mapping between atom types in LAMMPS to the available species in the OpenKIM model") + parser.add_argument("--min_style", default="cg", help="which algorithm will be used for minimization from lammps") + parser.add_argument("--minimize", type=float, nargs=4, default=[1.0e-4, 1.0e-6, 100, 1000], help="minimization parameters") + parser.add_argument("--up", type=float, default=1.0e-6, help="the deformation magnitude (in strain units)") + args = parser.parse_args() + + L = PyLammps() + + L.units("metal") + + # Define the finite deformation size. + #Try several values to verify that results do not depend on it. + L.variable("up equal {}".format(args.up)) + + # Define the amount of random jiggle for atoms. It prevents atoms from staying on saddle points + atomjiggle = 1.0e-5 + + # metal units, elastic constants in GPa + cfac = 1.0e-4 + + # Define minimization parameters + L.variable("dmax equal 1.0e-2") + + L.boundary("p", "p", "p") # periodic boundary conditions in all three directions + L.box("tilt large") # to avoid termination if the final simulation box has a high tilt factor + + # use the OpenKIM model to set the energy interactions + L.kim_init(args.kim_model, "metal", "unit_conversion_mode") + + L.read_data(args.input_data_file) + + potential(L, args) + + # Need to set mass to something, just to satisfy LAMMPS + mass_dictionary = {'H': 1.00797, 'He': 4.00260, 'Li': 6.941, 'Be': 9.01218, 'B': 10.81, 'C': 12.011, 'N': 14.0067, 'O': 15.9994, 'F': 18.998403, 'Ne': 20.179, 'Na': 22.98977, 'Mg': 24.305, 'Al': 26.98154, 'Si': 28.0855, 'P': 30.97376, 'S': 32.06, 'Cl': 35.453, 'K': 39.0983, 'Ar': 39.948, 'Ca': 40.08, 'Sc': 44.9559, 'Ti': 47.90, 'V': 50.9415, 'Cr': 51.996, 'Mn': 54.9380, 'Fe': 55.847, 'Ni': 58.70, 'Co': 58.9332, 'Cu': 63.546, 'Zn': 65.38, 'Ga': 69.72, 'Ge': 72.59, 'As': 74.9216, 'Se': 78.96, 'Br': 79.904, 'Kr': 83.80, 'Rb': 85.4678, 'Sr': 87.62, 'Y': 88.9059, 'Zr': 91.22, 'Nb': 92.9064, 'Mo': 95.94, 'Tc': (98), 'Ru': 101.07, 'Rh': 102.9055, 'Pd': 106.4, 'Ag': 107.868, 'Cd': 112.41, 'In': 114.82, 'Sn': 118.69, 'Sb': 121.75, 'I': 126.9045, 'Te': 127.60, 'Xe': 131.30, 'Cs': 132.9054, 'Ba': 137.33, 'La': 138.9055, 'Ce': 140.12, 'Pr': 140.9077, 'Nd': 144.24, 'Pm': (145), 'Sm': 150.4, 'Eu': 151.96, 'Gd': 157.25, 'Tb': 158.9254, 'Dy': 162.50, 'Ho': 164.9304, 'Er': 167.26, 'Tm': 168.9342, 'Yb': 173.04, 'Lu': 174.967, 'Hf': 178.49, 'Ta': 180.9479, 'W': 183.85, 'Re': 186.207, 'Os': 190.2, 'Ir': 192.22, 'Pt': 195.09, 'Au': 196.9665, 'Hg': 200.59, 'Tl': 204.37, 'Pb': 207.2, 'Bi': 208.9804, 'Po': (209), 'At': (210), 'Rn': (222), 'Fr': (223), 'Ra': 226.0254, 'Ac': 227.0278, 'Pa': 231.0359, 'Th': 232.0381, 'Np': 237.0482, 'U': 238.029} + for itype in range(1, len(args.elements)+1): + L.mass(itype, mass_dictionary.get(args.elements[itype-1], 1.0e-20)) + + # Compute initial state at zero pressure + L.fix(3, "all", "box/relax", "aniso", 0.0) + L.min_style(args.min_style) + L.minimize(args.minimize[0], args.minimize[1], int(args.minimize[2]), int(args.minimize[3])) + + L.variable("lx0 equal {}".format(L.eval("lx"))) + L.variable("ly0 equal {}".format(L.eval("ly"))) + L.variable("lz0 equal {}".format(L.eval("lz"))) + + # These formulas define the derivatives w.r.t. strain components + L.variable("d1 equal -(v_pxx1-{})/(v_delta/v_len0)*{}".format(L.eval("pxx"), cfac)) + L.variable("d2 equal -(v_pyy1-{})/(v_delta/v_len0)*{}".format(L.eval("pyy"), cfac)) + L.variable("d3 equal -(v_pzz1-{})/(v_delta/v_len0)*{}".format(L.eval("pzz"), cfac)) + L.variable("d4 equal -(v_pyz1-{})/(v_delta/v_len0)*{}".format(L.eval("pyz"), cfac)) + L.variable("d5 equal -(v_pxz1-{})/(v_delta/v_len0)*{}".format(L.eval("pxz"), cfac)) + L.variable("d6 equal -(v_pxy1-{})/(v_delta/v_len0)*{}".format(L.eval("pxy"), cfac)) + + L.displace_atoms("all", "random", atomjiggle, atomjiggle, atomjiggle, 87287, "units box") + + # Write restart + L.unfix(3) + L.write_restart("restart.equil") + + for idir in range(1, 7): + displace(L, args, idir) + + postprocess_and_output(L) + return + +def postprocess_and_output(lmp): + """Compute the moduli and print everything to screen """ + + # Output final values + c11all = lmp.variables["C11"].value + c22all = lmp.variables["C22"].value + c33all = lmp.variables["C33"].value + + c12all = 0.5*(lmp.variables["C12"].value + lmp.variables["C21"].value) + c13all = 0.5*(lmp.variables["C13"].value + lmp.variables["C31"].value) + c23all = 0.5*(lmp.variables["C23"].value + lmp.variables["C32"].value) + + c44all = lmp.variables["C44"].value + c55all = lmp.variables["C55"].value + c66all = lmp.variables["C66"].value + + c14all = 0.5*(lmp.variables["C14"].value + lmp.variables["C41"].value) + c15all = 0.5*(lmp.variables["C15"].value + lmp.variables["C51"].value) + c16all = 0.5*(lmp.variables["C16"].value + lmp.variables["C61"].value) + + c24all = 0.5*(lmp.variables["C24"].value + lmp.variables["C42"].value) + c25all = 0.5*(lmp.variables["C25"].value + lmp.variables["C52"].value) + c26all = 0.5*(lmp.variables["C26"].value + lmp.variables["C62"].value) + + c34all = 0.5*(lmp.variables["C34"].value + lmp.variables["C43"].value) + c35all = 0.5*(lmp.variables["C35"].value + lmp.variables["C53"].value) + c36all = 0.5*(lmp.variables["C36"].value + lmp.variables["C63"].value) + + c45all = 0.5*(lmp.variables["C45"].value + lmp.variables["C54"].value) + c46all = 0.5*(lmp.variables["C46"].value + lmp.variables["C64"].value) + c56all = 0.5*(lmp.variables["C56"].value + lmp.variables["C65"].value) + + # Average moduli for cubic crystals + c11cubic = (c11all + c22all + c33all)/3.0 + c12cubic = (c12all + c13all + c23all)/3.0 + c44cubic = (c44all + c55all + c66all)/3.0 + + bulkmodulus = (c11cubic + 2*c12cubic)/3.0 + shearmodulus1 = c44cubic + shearmodulus2 = (c11cubic - c12cubic)/2.0 + poisson_ratio = 1.0/(1.0 + c11cubic/c12cubic) + + # print results to screen + print("=========================================") + print("Components of the Elastic Constant Tensor") + print("=========================================") + + print("Elastic Constant C11all = {} GPa".format(c11all)) + print("Elastic Constant C22all = {} GPa".format(c22all)) + print("Elastic Constant C33all = {} GPa".format(c33all)) + + print("Elastic Constant C12all = {} GPa".format(c12all)) + print("Elastic Constant C13all = {} GPa".format(c13all)) + print("Elastic Constant C23all = {} GPa".format(c23all)) + + print("Elastic Constant C44all = {} GPa".format(c44all)) + print("Elastic Constant C55all = {} GPa".format(c55all)) + print("Elastic Constant C66all = {} GPa".format(c66all)) + + print("Elastic Constant C14all = {} GPa".format(c14all)) + print("Elastic Constant C15all = {} GPa".format(c15all)) + print("Elastic Constant C16all = {} GPa".format(c16all)) + + print("Elastic Constant C24all = {} GPa".format(c24all)) + print("Elastic Constant C25all = {} GPa".format(c25all)) + print("Elastic Constant C26all = {} GPa".format(c26all)) + + print("Elastic Constant C34all = {} GPa".format(c34all)) + print("Elastic Constant C35all = {} GPa".format(c35all)) + print("Elastic Constant C36all = {} GPa".format(c36all)) + + print("Elastic Constant C45all = {} GPa".format(c45all)) + print("Elastic Constant C46all = {} GPa".format(c46all)) + print("Elastic Constant C56all = {} GPa".format(c56all)) + + print("=========================================") + print("Average properties for a cubic crystal") + print("=========================================") + + print("Bulk Modulus = {} GPa".format(bulkmodulus)) + print("Shear Modulus 1 = {} GPa".format(shearmodulus1)) + print("Shear Modulus 2 = {} GPa".format(shearmodulus2)) + print("Poisson Ratio = {}".format(poisson_ratio)) + + return + +if __name__ == "__main__": + elastic() From c81610a3e8dc3becc87cd77691ad504171e388b4 Mon Sep 17 00:00:00 2001 From: "Ryan S. Elliott" Date: Tue, 16 Mar 2021 14:39:24 -0500 Subject: [PATCH 060/257] Check for installed OpenKIM models to be returned by kim query command --- src/KIM/kim_query.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/KIM/kim_query.cpp b/src/KIM/kim_query.cpp index cf3e6f51cf..8e9e7fc63f 100644 --- a/src/KIM/kim_query.cpp +++ b/src/KIM/kim_query.cpp @@ -62,6 +62,10 @@ #include "fix_store_kim.h" #include "info.h" #include "input.h" +extern "C" { +#include "KIM_Collections.h" +#include "KIM_CollectionItemType.h" +} #include "modify.h" #include "utils.h" #include "variable.h" @@ -185,6 +189,35 @@ void KimQuery::command(int narg, char **arg) input->write_echo("#=== BEGIN kim-query ==================================" "=======\n"); + // trim list of models to those that are installed on the system + if (query_function == "get_available_models") { + ValueTokenizer vals(value, ","); + std::string available; + std::string missing; + + KIM_Collections * col; + if (KIM_Collections_Create(&col)) { + delete [] value; + error->all(FLERR, fmt::format("Unable to create KIM_Collections object")); + } + + while (vals.has_next()) { + auto svalue = vals.next_string(); + KIM_CollectionItemType typ; + if (KIM_Collections_GetItemType(col, svalue.c_str(), &typ)) + missing += fmt::format("{} ", svalue); + else + available += fmt::format("{} ", svalue); + } + KIM_Collections_Destroy(&col); + + input->write_echo(fmt::format("# Installed OpenKIM models: {}\n", available)); + input->write_echo(fmt::format("# Missing OpenKIM models: {}\n", missing)); + // replace results with available + strcpy(value, available.c_str()); // available guaranteed to fit + }; + + ValueTokenizer values(value, ","); if (format_arg == "split") { int counter = 1; From ec5490e467e16e0c28f563ab859746480479adfa Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Mon, 15 Mar 2021 17:52:17 +0000 Subject: [PATCH 061/257] Allow compiling with SYCL --- src/KOKKOS/kokkos.cpp | 10 +++++----- src/KOKKOS/kokkos_type.h | 34 ++++++++++++++++++++++++---------- src/KOKKOS/npair_kokkos.cpp | 13 +++++++++++-- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index 37060b7387..3153e9a752 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -35,7 +35,7 @@ #define GPU_AWARE_UNKNOWN static int have_gpu_aware = -1; // TODO HIP: implement HIP-aware MPI support (UCX) detection -#if defined(KOKKOS_ENABLE_HIP) +#if defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL) GPU_AWARE_UNKNOWN #elif defined(KOKKOS_ENABLE_CUDA) @@ -108,7 +108,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) } else if (strcmp(arg[iarg],"g") == 0 || strcmp(arg[iarg],"gpus") == 0) { #ifndef LMP_KOKKOS_GPU - error->all(FLERR,"GPUs are requested but Kokkos has not been compiled for CUDA or HIP"); + error->all(FLERR,"GPUs are requested but Kokkos has not been compiled for CUDA, HIP, or SYCL"); #endif if (iarg+2 > narg) error->all(FLERR,"Invalid Kokkos command-line args"); ngpus = atoi(arg[iarg+1]); @@ -149,7 +149,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) if (ngpus > 1 && !set_flag) error->all(FLERR,"Could not determine local MPI rank for multiple " - "GPUs with Kokkos CUDA or HIP because MPI library not recognized"); + "GPUs with Kokkos CUDA, HIP, or SYCL because MPI library not recognized"); } else if (strcmp(arg[iarg],"t") == 0 || strcmp(arg[iarg],"threads") == 0) { @@ -173,7 +173,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) #ifdef LMP_KOKKOS_GPU if (ngpus <= 0) - error->all(FLERR,"Kokkos has been compiled for CUDA or HIP but no GPUs are requested"); + error->all(FLERR,"Kokkos has been compiled for CUDA, HIP, or SYCL but no GPUs are requested"); #endif #ifndef KOKKOS_ENABLE_SERIAL @@ -280,7 +280,7 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) gpu_aware_flag = 0; #else if (me == 0) - error->warning(FLERR,"Kokkos with CUDA or HIP assumes GPU-aware MPI is available," + error->warning(FLERR,"Kokkos with CUDA, HIP, or SYCL assumes CUDA-aware MPI is available," " but cannot determine if this is the case\n try" " '-pk kokkos gpu/aware off' if getting segmentation faults"); diff --git a/src/KOKKOS/kokkos_type.h b/src/KOKKOS/kokkos_type.h index e905aeda98..c819147a4d 100644 --- a/src/KOKKOS/kokkos_type.h +++ b/src/KOKKOS/kokkos_type.h @@ -30,7 +30,7 @@ enum{FULL=1u,HALFTHREAD=2u,HALF=4u}; #define ISFINITE(x) std::isfinite(x) #endif -#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) +#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL) #define LMP_KOKKOS_GPU #endif @@ -207,13 +207,16 @@ template<> struct ExecutionSpaceFromDevice { static const LAMMPS_NS::ExecutionSpace space = LAMMPS_NS::Device; }; -#endif - -#if defined(KOKKOS_ENABLE_HIP) +#elif defined(KOKKOS_ENABLE_HIP) template<> struct ExecutionSpaceFromDevice { static const LAMMPS_NS::ExecutionSpace space = LAMMPS_NS::Device; }; +#elif defined(KOKKOS_ENABLE_SYCL) +template<> +struct ExecutionSpaceFromDevice { + static const LAMMPS_NS::ExecutionSpace space = LAMMPS_NS::Device; +}; #endif // set host pinned space @@ -221,14 +224,18 @@ struct ExecutionSpaceFromDevice { typedef Kokkos::CudaHostPinnedSpace LMPPinnedHostType; #elif defined(KOKKOS_ENABLE_HIP) typedef Kokkos::Experimental::HIPHostPinnedSpace LMPPinnedHostType; +#elif defined(KOKKOS_ENABLE_SYCL) +typedef Kokkos::Experimental::SYCLSharedUSMSpace LMPPinnedHostType; #endif -// create simple LMPDeviceSpace typedef for non HIP or CUDA specific +// create simple LMPDeviceSpace typedef for non CUDA-, HIP-, or SYCL-specific // behaviour #if defined(KOKKOS_ENABLE_CUDA) typedef Kokkos::Cuda LMPDeviceSpace; #elif defined(KOKKOS_ENABLE_HIP) typedef Kokkos::Experimental::HIP LMPDeviceSpace; +#elif defined(KOKKOS_ENABLE_SYCL) +typedef Kokkos::Experimental::SYCL LMPDeviceSpace; #endif @@ -257,13 +264,16 @@ template<> struct AtomicDup { using value = Kokkos::Experimental::ScatterAtomic; }; -#endif - -#ifdef KOKKOS_ENABLE_HIP +#elif defined(KOKKOS_ENABLE_HIP) template<> struct AtomicDup { using value = Kokkos::Experimental::ScatterAtomic; }; +#elif defined(KOKKOS_ENABLE_SYCL) +template<> +struct AtomicDup { + using value = Kokkos::Experimental::ScatterAtomic; +}; #endif #ifdef LMP_KOKKOS_USE_ATOMICS @@ -1154,10 +1164,14 @@ typedef SNAComplex SNAcomplex; #define ISFINITE(x) std::isfinite(x) #endif -#define LAMMPS_LAMBDA KOKKOS_LAMBDA +#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) +#define LAMMPS_LAMBDA [=] __device__ +#else +#define LAMMPS_LAMBDA [=] +#endif #ifdef LMP_KOKKOS_GPU -#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__) +#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__) || defined(__SYCL_DEVICE_ONLY__) #define LMP_KK_DEVICE_COMPILE #endif #endif diff --git a/src/KOKKOS/npair_kokkos.cpp b/src/KOKKOS/npair_kokkos.cpp index f35b464cf4..6e93cde49c 100644 --- a/src/KOKKOS/npair_kokkos.cpp +++ b/src/KOKKOS/npair_kokkos.cpp @@ -594,9 +594,13 @@ void NeighborKokkosExecute::build_ItemGPU(typename Kokkos::TeamPolic other_x[MY_II + 3 * atoms_per_bin] = itype; } other_id[MY_II] = i; +#ifndef KOKKOS_ENABLE_SYCL int test = (__syncthreads_count(i >= 0 && i <= nlocal) == 0); - if (test) return; + if(test) return; +#else + dev.team_barrier(); +#endif if (i >= 0 && i < nlocal) { #pragma unroll 4 @@ -1041,9 +1045,14 @@ void NeighborKokkosExecute::build_ItemSizeGPU(typename Kokkos::TeamP other_x[MY_II + 4 * atoms_per_bin] = radi; } other_id[MY_II] = i; + // FIXME_SYCL +#ifndef KOKKOS_ENABLE_SYCL int test = (__syncthreads_count(i >= 0 && i <= nlocal) == 0); - if (test) return; + if(test) return; +#else + dev.team_barrier(); +#endif if (i >= 0 && i < nlocal) { #pragma unroll 4 From 0e8f64251e1a211eeb243cb75e2afae38bbbe227 Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Tue, 16 Mar 2021 16:23:54 -0500 Subject: [PATCH 062/257] Correct the token to avoid missing model names Correct the missing & available strings to match with the rest of query Add error message when there is no OpenKIM model installed on the system Correct the header file inlcusion order --- src/KIM/kim_query.cpp | 44 +++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/KIM/kim_query.cpp b/src/KIM/kim_query.cpp index 8e9e7fc63f..b344972689 100644 --- a/src/KIM/kim_query.cpp +++ b/src/KIM/kim_query.cpp @@ -62,10 +62,6 @@ #include "fix_store_kim.h" #include "info.h" #include "input.h" -extern "C" { -#include "KIM_Collections.h" -#include "KIM_CollectionItemType.h" -} #include "modify.h" #include "utils.h" #include "variable.h" @@ -82,6 +78,11 @@ extern "C" { #include #endif +extern "C" { +#include "KIM_Collections.h" +#include "KIM_CollectionItemType.h" +} + using namespace LAMMPS_NS; #if defined(LMP_KIM_CURL) @@ -191,33 +192,44 @@ void KimQuery::command(int narg, char **arg) "=======\n"); // trim list of models to those that are installed on the system if (query_function == "get_available_models") { - ValueTokenizer vals(value, ","); + ValueTokenizer vals(value, ", \""); std::string available; std::string missing; - KIM_Collections * col; - if (KIM_Collections_Create(&col)) { + KIM_Collections * collections; + KIM_CollectionItemType typ; + + if (KIM_Collections_Create(&collections)) { delete [] value; - error->all(FLERR, fmt::format("Unable to create KIM_Collections object")); + error->all(FLERR, + fmt::format("Unable to access KIM Collections to find Model")); } + auto logID = fmt::format("{}_Collections", comm->me); + KIM_Collections_SetLogID(collections, logID.c_str()); + while (vals.has_next()) { auto svalue = vals.next_string(); - KIM_CollectionItemType typ; - if (KIM_Collections_GetItemType(col, svalue.c_str(), &typ)) - missing += fmt::format("{} ", svalue); + if (KIM_Collections_GetItemType(collections, svalue.c_str(), &typ)) + missing += fmt::format("{}, ", svalue); else - available += fmt::format("{} ", svalue); + available += fmt::format("{}, ", svalue); } - KIM_Collections_Destroy(&col); + KIM_Collections_Destroy(&collections); + + input->write_echo( + fmt::format("# Missing OpenKIM models: {}\n\n", missing)); + + if (available.empty()) + error->all(FLERR, + fmt::format("There is no OpenKIM model installed on the system")); + input->write_echo( + fmt::format("# Installed OpenKIM models: {}\n\n", available)); - input->write_echo(fmt::format("# Installed OpenKIM models: {}\n", available)); - input->write_echo(fmt::format("# Missing OpenKIM models: {}\n", missing)); // replace results with available strcpy(value, available.c_str()); // available guaranteed to fit }; - ValueTokenizer values(value, ","); if (format_arg == "split") { int counter = 1; From 46b86f3b1ea7595d8d7a7048a9b46c232d1d6de0 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 16 Mar 2021 22:20:47 +0000 Subject: [PATCH 063/257] Define LAMMPS_DEVICE_FUNCTION --- src/KOKKOS/kokkos_type.h | 6 ++++++ src/KOKKOS/npair_kokkos.cpp | 14 ++++---------- src/KOKKOS/npair_kokkos.h | 20 ++++---------------- src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp | 2 +- 4 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/KOKKOS/kokkos_type.h b/src/KOKKOS/kokkos_type.h index c819147a4d..e701cb4064 100644 --- a/src/KOKKOS/kokkos_type.h +++ b/src/KOKKOS/kokkos_type.h @@ -1170,6 +1170,12 @@ typedef SNAComplex SNAcomplex; #define LAMMPS_LAMBDA [=] #endif +#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) +#define LAMMPS_DEVICE_FUNCTION __device__ +#else +#define LAMMPS_DEVICE_FUNCTION +#endif + #ifdef LMP_KOKKOS_GPU #if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__) || defined(__SYCL_DEVICE_ONLY__) #define LMP_KK_DEVICE_COMPILE diff --git a/src/KOKKOS/npair_kokkos.cpp b/src/KOKKOS/npair_kokkos.cpp index 6e93cde49c..7556651cb6 100644 --- a/src/KOKKOS/npair_kokkos.cpp +++ b/src/KOKKOS/npair_kokkos.cpp @@ -545,10 +545,7 @@ __device__ __forceinline__ int __syncthreads_count(int predicate) { #ifdef LMP_KOKKOS_GPU template template -#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) -__device__ -#endif -inline +LAMMPS_DEVICE_FUNCTION inline void NeighborKokkosExecute::build_ItemGPU(typename Kokkos::TeamPolicy::member_type dev, size_t sharedsize) const { @@ -597,7 +594,7 @@ void NeighborKokkosExecute::build_ItemGPU(typename Kokkos::TeamPolic #ifndef KOKKOS_ENABLE_SYCL int test = (__syncthreads_count(i >= 0 && i <= nlocal) == 0); - if(test) return; + if (test) return; #else dev.team_barrier(); #endif @@ -992,10 +989,7 @@ void NeighborKokkosExecute:: #ifdef LMP_KOKKOS_GPU template template -#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) -__device__ -#endif -inline +LAMMPS_DEVICE_FUNCTION inline void NeighborKokkosExecute::build_ItemSizeGPU(typename Kokkos::TeamPolicy::member_type dev, size_t sharedsize) const { @@ -1049,7 +1043,7 @@ void NeighborKokkosExecute::build_ItemSizeGPU(typename Kokkos::TeamP #ifndef KOKKOS_ENABLE_SYCL int test = (__syncthreads_count(i >= 0 && i <= nlocal) == 0); - if(test) return; + if (test) return; #else dev.team_barrier(); #endif diff --git a/src/KOKKOS/npair_kokkos.h b/src/KOKKOS/npair_kokkos.h index c1abc15b3b..0d96762432 100644 --- a/src/KOKKOS/npair_kokkos.h +++ b/src/KOKKOS/npair_kokkos.h @@ -312,18 +312,12 @@ class NeighborKokkosExecute #ifdef LMP_KOKKOS_GPU template -#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) - __device__ -#endif - inline + LAMMPS_DEVICE_FUNCTION inline void build_ItemGPU(typename Kokkos::TeamPolicy::member_type dev, size_t sharedsize) const; template -#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) - __device__ -#endif - inline + LAMMPS_DEVICE_FUNCTION inline void build_ItemSizeGPU(typename Kokkos::TeamPolicy::member_type dev, size_t sharedsize) const; #endif @@ -396,10 +390,7 @@ struct NPairKokkosBuildFunctor { c.template build_Item(i); } #ifdef LMP_KOKKOS_GPU -#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) - __device__ -#endif - inline + LAMMPS_DEVICE_FUNCTION inline void operator() (typename Kokkos::TeamPolicy::member_type dev) const { c.template build_ItemGPU(dev, sharedsize); } @@ -456,10 +447,7 @@ struct NPairKokkosBuildFunctorSize { } #ifdef LMP_KOKKOS_GPU - #if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) - __device__ -#endif - inline + LAMMPS_DEVICE_FUNCTION inline void operator() (typename Kokkos::TeamPolicy::member_type dev) const { c.template build_ItemSizeGPU(dev, sharedsize); } diff --git a/src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp b/src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp index b2e59a27e5..529dead5c8 100644 --- a/src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp +++ b/src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp @@ -113,7 +113,7 @@ void PairDPDfdtEnergyKokkos::init_style() #endif } -#if (defined(KOKKOS_ENABLE_CUDA) && defined(__CUDACC__)) || defined(KOKKOS_ENABLE_HIP) +#if (defined(KOKKOS_ENABLE_CUDA) && defined(__CUDACC__)) || defined(KOKKOS_ENABLE_HIP) || defined(KOKKOS_ENABLE_SYCL) // CUDA specialization of init_style to properly call rand_pool.init() template<> void PairDPDfdtEnergyKokkos::init_style() From 22fdfa27b57fbcdbc9d8e6045df7567491eb3d5e Mon Sep 17 00:00:00 2001 From: Stephen Sanderson Date: Wed, 17 Mar 2021 09:01:35 +1000 Subject: [PATCH 064/257] Updated documentation to clarify the treatment of temperature using norm all --- doc/src/fix_ave_chunk.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/src/fix_ave_chunk.rst b/doc/src/fix_ave_chunk.rst index d2dbaa320a..ce7fcd1fca 100644 --- a/doc/src/fix_ave_chunk.rst +++ b/doc/src/fix_ave_chunk.rst @@ -307,7 +307,9 @@ atoms in the chunk. The averaged output value for the chunk on the average over atoms across the entire *Nfreq* timescale. For the *density/number* and *density/mass* values, the volume (bin volume or system volume) used in the final normalization will be the volume at -the final *Nfreq* timestep. +the final *Nfreq* timestep. For the *temp* values, degrees of freedom and +kinetic energy are summed separately across the entire *Nfreq* timescale, and +the output value is calculated by dividing those two sums. If the *norm* setting is *sample*\ , the chunk value is summed over atoms for each sample, as is the count, and an "average sample value" From 11894f83b9b705eb152a0525e7bd5c04834aac7d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 16 Mar 2021 19:50:45 -0400 Subject: [PATCH 065/257] clarify and fix grammar issues --- doc/src/Developer_plugins.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/doc/src/Developer_plugins.rst b/doc/src/Developer_plugins.rst index 192c57ccbb..7275c12605 100644 --- a/doc/src/Developer_plugins.rst +++ b/doc/src/Developer_plugins.rst @@ -162,17 +162,20 @@ The initialization function **must** be called ``lammpsplugin_init``, it **must** have C bindings and it takes three void pointers as arguments. The first is a pointer to the LAMMPS class that calls it and it needs to be passed to the registration function. The second argument is a -pointer to the internal handle of the DSO file, this needs to added to -the plugin info struct, so that the DSO can be close and unloaded when -all its contained plugins are unloaded. The third argument is a +pointer to the internal handle of the DSO file, this needs to be added +to the plugin info struct, so that the DSO can be closed and unloaded +when all its contained plugins are unloaded. The third argument is a function pointer to the registration function and needs to be stored -in a variable of ``lammpsplugin_regfunc`` type. +in a variable of ``lammpsplugin_regfunc`` type and then called with a +pointer to the ``lammpsplugin_`` struct and the pointer to the LAMMPS +instance as arguments to register a single plugin. There may be multiple +calls to multiple plugins in the same initialization function. To register a plugin a struct of the ``lammpsplugin_t`` needs to be filled with relevant info: current LAMMPS version string, kind of style, name of -style, info string, author string, pointer to factory function, DSO handle. -The the registration function is called with a pointer to the address of -this struct and the pointer of the LAMMPS class. The registration function +style, info string, author string, pointer to factory function, and the +DSO handle. The registration function is called with a pointer to the address +of this struct and the pointer of the LAMMPS class. The registration function will then add the factory function of the plugin style to the respective style map under the provided name. It will also make a copy of the struct in a list of all loaded plugins and update the reference counter for loaded From a6773bad5d2de71b63e013a9f0b297bb393c7bd2 Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Tue, 16 Mar 2021 19:40:49 -0500 Subject: [PATCH 066/257] remove unnecessary echo --- src/KIM/kim_query.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/KIM/kim_query.cpp b/src/KIM/kim_query.cpp index b344972689..cc4ece4406 100644 --- a/src/KIM/kim_query.cpp +++ b/src/KIM/kim_query.cpp @@ -223,8 +223,6 @@ void KimQuery::command(int narg, char **arg) if (available.empty()) error->all(FLERR, fmt::format("There is no OpenKIM model installed on the system")); - input->write_echo( - fmt::format("# Installed OpenKIM models: {}\n\n", available)); // replace results with available strcpy(value, available.c_str()); // available guaranteed to fit From 125ae33ccfa4aa97212607bab3487fb4193d015e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 16 Mar 2021 22:43:13 -0400 Subject: [PATCH 067/257] convert plugin functionality into a package --- cmake/CMakeLists.txt | 19 +++++-- cmake/presets/most.cmake | 2 +- lib/README | 20 ++++--- lib/plugin/README | 16 ++++++ src/.gitignore | 4 ++ src/MAKE/Makefile.mpi | 2 +- src/MAKE/Makefile.serial | 2 +- src/Makefile | 2 +- src/PLUGIN/Install.sh | 64 ++++++++++++++++++++++ src/PLUGIN/README | 12 ++++ src/{ => PLUGIN}/plugin.cpp | 49 +++++++++++++++++ src/{ => PLUGIN}/plugin.h | 15 ++++- src/input.cpp | 30 ---------- src/library.cpp | 8 +++ unittest/commands/CMakeLists.txt | 2 +- unittest/commands/test_simple_commands.cpp | 2 + 16 files changed, 198 insertions(+), 51 deletions(-) create mode 100644 lib/plugin/README create mode 100755 src/PLUGIN/Install.sh create mode 100644 src/PLUGIN/README rename src/{ => PLUGIN}/plugin.cpp (87%) rename src/{ => PLUGIN}/plugin.h (84%) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 7081d6aa80..f05c7f97eb 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -113,7 +113,7 @@ option(CMAKE_VERBOSE_MAKEFILE "Generate verbose Makefiles" OFF) set(STANDARD_PACKAGES ASPHERE BODY CLASS2 COLLOID COMPRESS DIPOLE GRANULAR KSPACE LATTE MANYBODY MC MESSAGE MISC MLIAP MOLECULE PERI POEMS - QEQ REPLICA RIGID SHOCK SPIN SNAP SRD KIM PYTHON MSCG MPIIO VORONOI + PLUGIN QEQ REPLICA RIGID SHOCK SPIN SNAP SRD KIM PYTHON MSCG MPIIO VORONOI USER-ADIOS USER-ATC USER-AWPMD USER-BOCS USER-CGDNA USER-MESODPD USER-CGSDK USER-COLVARS USER-DIFFRACTION USER-DPD USER-DRUDE USER-EFF USER-FEP USER-H5MD USER-LB USER-MANIFOLD USER-MEAMC USER-MESONT USER-MGPT USER-MISC USER-MOFFF @@ -240,11 +240,6 @@ if(BUILD_OMP) target_link_libraries(lammps PRIVATE OpenMP::OpenMP_CXX) endif() -# link with -ldl or equivalent for plugin loading; except on Windows -if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") - target_link_libraries(lammps PRIVATE ${CMAKE_DL_LIBS}) -endif() - # Compiler specific features for testing if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") option(ENABLE_COVERAGE "Enable collecting code coverage data" OFF) @@ -538,6 +533,18 @@ foreach(PKG_WITH_INCL CORESHELL QEQ USER-OMP USER-SDPD KOKKOS OPT USER-INTEL GPU endif() endforeach() +if(PKG_PLUGIN) + if(BUILD_SHARED_LIBS) + target_compile_definitions(lammps PRIVATE -DLMP_PLUGIN) + else() + message(WARNING "Plugin loading will not work unless BUILD_SHARED_LIBS is enabled") + endif() + # link with -ldl or equivalent for plugin loading; except on Windows + if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + target_link_libraries(lammps PRIVATE ${CMAKE_DL_LIBS}) + endif() +endif() + ###################################################################### # the windows version of LAMMPS requires a couple extra libraries # and the MPI library - if use - has to be linked right before those diff --git a/cmake/presets/most.cmake b/cmake/presets/most.cmake index bddefc077b..5dc58b735b 100644 --- a/cmake/presets/most.cmake +++ b/cmake/presets/most.cmake @@ -4,7 +4,7 @@ set(ALL_PACKAGES ASPHERE BODY CLASS2 COLLOID COMPRESS CORESHELL DIPOLE GRANULAR KSPACE MANYBODY MC MISC MLIAP MOLECULE OPT PERI - POEMS PYTHON QEQ REPLICA RIGID SHOCK SNAP SPIN SRD VORONOI + PLUGIN POEMS PYTHON QEQ REPLICA RIGID SHOCK SNAP SPIN SRD VORONOI USER-BOCS USER-CGDNA USER-CGSDK USER-COLVARS USER-DIFFRACTION USER-DPD USER-DRUDE USER-EFF USER-FEP USER-MEAMC USER-MESODPD USER-MISC USER-MOFFF USER-OMP USER-PHONON USER-REACTION diff --git a/lib/README b/lib/README index d89490e202..26c3fad9e0 100644 --- a/lib/README +++ b/lib/README @@ -19,12 +19,12 @@ atc atomistic-to-continuum methods, USER-ATC package from Reese Jones, Jeremy Templeton, Jon Zimmerman (Sandia) awpmd antisymmetrized wave packet molecular dynamics, AWPMD package from Ilya Valuev (JIHT RAS) -colvars collective variable module (Metadynamics, ABF and more) +colvars collective variable module (Metadynamics, ABF and more) from Giacomo Fiorin and Jerome Henin (ICMS, Temple U) compress hook to system lib for performing I/O compression, COMPRESS pkg - from Axel Kohlmeyer (Temple U) -gpu general GPU routines, GPU package - from Mike Brown (ORNL) + from Axel Kohlmeyer (Temple U) +gpu general GPU routines, GPU package + from Mike Brown (ORNL) h5md ch5md library for output of MD data in HDF5 format from Pierre de Buyl (KU Leuven) kim hooks to the KIM library, used by KIM package @@ -32,26 +32,28 @@ kim hooks to the KIM library, used by KIM package kokkos Kokkos package for GPU and many-core acceleration from Kokkos development team (Sandia) linalg set of BLAS and LAPACK routines needed by USER-ATC package - from Axel Kohlmeyer (Temple U) + from Axel Kohlmeyer (Temple U) message client/server communication library via MPI, sockets, files - from Steve Plimpton (Sandia) + from Steve Plimpton (Sandia) molfile hooks to VMD molfile plugins, used by the USER-MOLFILE package from Axel Kohlmeyer (Temple U) and the VMD development team mscg hooks to the MSCG library, used by fix_mscg command from Jacob Wagner and Greg Voth group (U Chicago) netcdf hooks to a NetCDF library installed on your system from Lars Pastewka (Karlsruhe Institute of Technology) -poems POEMS rigid-body integration package, POEMS package +plugin settings to load styles into LAMMPS from plugins + from Axel Kohlmeyer (Temple U) +poems POEMS rigid-body integration package, POEMS package from Rudranarayan Mukherjee (RPI) python hooks to the system Python library, used by the PYTHON package from the LAMMPS development team -qmmm quantum mechanics/molecular mechanics coupling interface +qmmm quantum mechanics/molecular mechanics coupling interface from Axel Kohlmeyer (Temple U) quip interface to QUIP/libAtoms framework, USER-QUIP package from Albert Bartok-Partay and Gabor Csanyi (U Cambridge) smd hooks to Eigen library, used by USER-SMD package from Georg Ganzenmueller (Ernst Mach Institute, Germany) voronoi hooks to the Voro++ library, used by compute voronoi/atom command - from Daniel Schwen (LANL) + from Daniel Schwen (LANL) vtk hooks to the VTK library, used by dump custom/vtk command from Richard Berger (JKU) diff --git a/lib/plugin/README b/lib/plugin/README new file mode 100644 index 0000000000..15abea011d --- /dev/null +++ b/lib/plugin/README @@ -0,0 +1,16 @@ +This directory has a Makefile.lammps file with settings that allows +LAMMPS to dynamically link LAMMPS plugins. More details about this +are in the manual. + +In order to be able to dynamically load and execute the plugins from +inside LAMMPS, you need to link with a system library containing functions +like dlopen(), dlsym() and so on for dynamic linking of executable code +into an executable. This library is defined by setting the plugin_SYSLIB +variable in the Makefile.lammps file in this dir. For this mechanism +to work, LAMMPS must be built as a shared library (i.e. with mode=shared). + +For Linux and most current unix-like operating systems, this can be +kept at the default setting of "-ldl" (on some platforms this library +is called "-ldld"). The Windows platform is currently not supported. + +See the header of Makefile.lammps for more info. diff --git a/src/.gitignore b/src/.gitignore index 45ec71e485..6fa3aef513 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -172,6 +172,10 @@ /pair_lj_charmmfsw_coul_long.cpp /pair_lj_charmmfsw_coul_long.h +/plugin.cpp +/plugin.h +/lammpsplugin.h + /atom_vec_spin.cpp /atom_vec_spin.h /compute_spin.cpp diff --git a/src/MAKE/Makefile.mpi b/src/MAKE/Makefile.mpi index 68e79e9e8e..9776b0153e 100644 --- a/src/MAKE/Makefile.mpi +++ b/src/MAKE/Makefile.mpi @@ -13,7 +13,7 @@ DEPFLAGS = -M LINK = mpicxx LINKFLAGS = -g -O3 -LIB = -ldl +LIB = SIZE = size ARCHIVE = ar diff --git a/src/MAKE/Makefile.serial b/src/MAKE/Makefile.serial index 8b4e2e5982..0f5952f317 100644 --- a/src/MAKE/Makefile.serial +++ b/src/MAKE/Makefile.serial @@ -13,7 +13,7 @@ DEPFLAGS = -M LINK = g++ LINKFLAGS = -g -O -LIB = -ldl +LIB = SIZE = size ARCHIVE = ar diff --git a/src/Makefile b/src/Makefile index 679cbe7b97..a63c49e344 100644 --- a/src/Makefile +++ b/src/Makefile @@ -48,7 +48,7 @@ endif PACKAGE = asphere body class2 colloid compress coreshell dipole gpu \ granular kim kokkos kspace latte manybody mc message misc \ - mliap molecule mpiio mscg opt peri poems \ + mliap molecule mpiio mscg opt peri plugin poems \ python qeq replica rigid shock snap spin srd voronoi PACKUSER = user-adios user-atc user-awpmd user-bocs user-cgdna user-cgsdk user-colvars \ diff --git a/src/PLUGIN/Install.sh b/src/PLUGIN/Install.sh new file mode 100755 index 0000000000..0df642193e --- /dev/null +++ b/src/PLUGIN/Install.sh @@ -0,0 +1,64 @@ +# Install/unInstall package files in LAMMPS +# mode = 0/1/2 for uninstall/install/update + +mode=$1 + +# enforce using portable C locale +LC_ALL=C +export LC_ALL + +# arg1 = file, arg2 = file it depends on + +action () { + if (test $mode = 0) then + rm -f ../$1 + elif (! cmp -s $1 ../$1) then + if (test -z "$2" || test -e ../$2) then + cp $1 .. + if (test $mode = 2) then + echo " updating src/$1" + fi + fi + elif (test -n "$2") then + if (test ! -e ../$2) then + rm -f ../$1 + fi + fi +} + +# all package files with no dependencies + +for file in *.cpp *.h; do + test -f ${file} && action $file +done + +# edit 2 Makefile.package files to include/exclude package info + +if (test $1 = 1) then + + if (test -e ../Makefile.package) then + sed -i -e 's/[^ \t]*plugin[^ \t]* //' ../Makefile.package + sed -i -e 's|^PKG_SYSINC =[ \t]*|&$(plugin_SYSINC) |' ../Makefile.package + sed -i -e 's|^PKG_SYSLIB =[ \t]*|&$(plugin_SYSLIB) |' ../Makefile.package + sed -i -e 's|^PKG_SYSPATH =[ \t]*|&$(plugin_SYSPATH) |' ../Makefile.package + fi + + if (test -e ../Makefile.package.settings) then + sed -i -e '/^include.*plugin.*$/d' ../Makefile.package.settings + # multiline form needed for BSD sed on Macs + sed -i -e '4 i \ +include ..\/..\/lib\/plugin\/Makefile.lammps +' ../Makefile.package.settings + fi + +elif (test $1 = 0) then + + if (test -e ../Makefile.package) then + sed -i -e 's/[^ \t]*plugin[^ \t]* //' ../Makefile.package + fi + + if (test -e ../Makefile.package.settings) then + sed -i -e '/^include.*plugin.*$/d' ../Makefile.package.settings + fi + +fi diff --git a/src/PLUGIN/README b/src/PLUGIN/README new file mode 100644 index 0000000000..4515428e35 --- /dev/null +++ b/src/PLUGIN/README @@ -0,0 +1,12 @@ +This package provides a plugin command that can load LAMMPS +styles linked into shared object files into a LAMMPS binary +at run time without having to recompile and relink LAMMPS. +For more details please see the LAMMPS manual. + +To be able to dynamically load and execute the plugins from inside +LAMMPS, you need to link with an appropriate system library, which +is done using the settings in lib/plugin/Makefile.lammps. See +that file and the lib/plugin/README file for more details. + +The person who created this package is Axel Kohlmeyer at Temple U +(akohlmey at gmail.com). Contact him directly if you have questions. diff --git a/src/plugin.cpp b/src/PLUGIN/plugin.cpp similarity index 87% rename from src/plugin.cpp rename to src/PLUGIN/plugin.cpp index e252ce67e1..1449d0d90f 100644 --- a/src/plugin.cpp +++ b/src/PLUGIN/plugin.cpp @@ -38,9 +38,53 @@ namespace LAMMPS_NS // map for counting references to dso handles static std::map dso_refcounter; + +/* ---------------------------------------------------------------------- */ + + Plugin::Plugin(LAMMPS *lmp) : Pointers(lmp) {} + +/* ---------------------------------------------------------------------- */ + + void Plugin::command(int narg, char **arg) + { + if (narg < 1) error->all(FLERR,"Illegal plugin command"); + +#if defined(LMP_PLUGIN) + std::string cmd = arg[0]; + if (cmd == "load") { + if (narg < 2) error->all(FLERR,"Illegal plugin load command"); + for (int i=1; i < narg; ++i) + plugin_load(arg[i],lmp); + + } else if (cmd == "unload") { + if (narg != 3) error->all(FLERR,"Illegal plugin unload command"); + plugin_unload(arg[1],arg[2],lmp); + + } else if (cmd == "clear") { + plugin_clear(lmp); + + } else if (cmd == "list") { + if (comm->me == 0) { + int num = plugin_get_num_plugins(); + utils::logmesg(lmp,"Currently loaded plugins\n"); + for (int i=0; i < num; ++i) { + auto entry = plugin_get_info(i); + utils::logmesg(lmp,fmt::format("{:4}: {} style plugin {}\n", + i+1,entry->style,entry->name)); + } + } + } else error->all(FLERR,"Illegal plugin command"); +#else + if (comm->me == 0) + error->warning(FLERR,"Ignoring plugin command. LAMMPS must be built as " + "a shared library for it to work."); +#endif + } + // load DSO and call included registration function void plugin_load(const char *file, LAMMPS *lmp) { +#if defined(LMP_PLUGIN) int me = lmp->comm->me; #if defined(WIN32) lmp->error->all(FLERR,"Loading of plugins on Windows is not supported\n"); @@ -77,6 +121,7 @@ namespace LAMMPS_NS (*(lammpsplugin_initfunc)(initfunc))((void *)lmp, dso, (void *)&plugin_register); +#endif #endif } @@ -89,6 +134,7 @@ namespace LAMMPS_NS void plugin_register(lammpsplugin_t *plugin, void *ptr) { +#if defined(LMP_PLUGIN) LAMMPS *lmp = (LAMMPS *)ptr; int me = lmp->comm->me; @@ -158,6 +204,7 @@ namespace LAMMPS_NS "yet implemented\n",pstyle)); pluginlist.pop_back(); } +#endif } /* -------------------------------------------------------------------- @@ -168,6 +215,7 @@ namespace LAMMPS_NS void plugin_unload(const char *style, const char *name, LAMMPS *lmp) { +#if defined(LMP_PLUGIN) int me = lmp->comm->me; // ignore unload request from unsupported style categories @@ -246,6 +294,7 @@ namespace LAMMPS_NS dlclose(handle); #endif } +#endif } /* -------------------------------------------------------------------- diff --git a/src/plugin.h b/src/PLUGIN/plugin.h similarity index 84% rename from src/plugin.h rename to src/PLUGIN/plugin.h index 90952224a6..946b08db1a 100644 --- a/src/plugin.h +++ b/src/PLUGIN/plugin.h @@ -11,14 +11,26 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +#ifdef COMMAND_CLASS + +CommandStyle(plugin,Plugin) + +#else + #ifndef LMP_PLUGIN_H #define LMP_PLUGIN_H #include "lammpsplugin.h" +#include "pointers.h" namespace LAMMPS_NS { - class LAMMPS; + + class Plugin : protected Pointers { + public: + Plugin(class LAMMPS *); + void command(int, char **); + }; void plugin_load(const char *, LAMMPS *); void plugin_register(lammpsplugin_t *, void *); @@ -33,3 +45,4 @@ namespace LAMMPS_NS } #endif +#endif diff --git a/src/input.cpp b/src/input.cpp index 9979bb7705..eeb211a6d1 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -35,7 +35,6 @@ #include "neighbor.h" #include "output.h" #include "pair.h" -#include "plugin.h" #include "special.h" #include "style_command.h" #include "thermo.h" @@ -718,7 +717,6 @@ int Input::execute_command() else if (!strcmp(command,"log")) log(); else if (!strcmp(command,"next")) next_command(); else if (!strcmp(command,"partition")) partition(); - else if (!strcmp(command,"plugin")) plugin(); else if (!strcmp(command,"print")) print(); else if (!strcmp(command,"python")) python(); else if (!strcmp(command,"quit")) quit(); @@ -1097,34 +1095,6 @@ void Input::partition() /* ---------------------------------------------------------------------- */ -void Input::plugin() -{ - if (narg < 1) error->all(FLERR,"Illegal plugin command"); - std::string cmd = arg[0]; - if (cmd == "load") { - if (narg < 2) error->all(FLERR,"Illegal plugin load command"); - for (int i=1; i < narg; ++i) - plugin_load(arg[i],lmp); - } else if (cmd == "unload") { - if (narg != 3) error->all(FLERR,"Illegal plugin unload command"); - plugin_unload(arg[1],arg[2],lmp); - } else if (cmd == "clear") { - plugin_clear(lmp); - } else if (cmd == "list") { - if (comm->me == 0) { - int num = plugin_get_num_plugins(); - utils::logmesg(lmp,"Currently loaded plugins\n"); - for (int i=0; i < num; ++i) { - auto entry = plugin_get_info(i); - utils::logmesg(lmp,fmt::format("{:4}: {} style plugin {}\n", - i+1,entry->style,entry->name)); - } - } - } else error->all(FLERR,"Illegal plugin command"); -} - -/* ---------------------------------------------------------------------- */ - void Input::print() { if (narg < 1) error->all(FLERR,"Illegal print command"); diff --git a/src/library.cpp b/src/library.cpp index 68ce180107..414d0f9f3a 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -38,7 +38,9 @@ #include "neighbor.h" #include "region.h" #include "output.h" +#if defined(LMP_PLUGIN) #include "plugin.h" +#endif #include "thermo.h" #include "timer.h" #include "universe.h" @@ -4590,7 +4592,11 @@ This function counts how many plugins are currently loaded. */ int lammps_plugin_count() { +#if defined(LMP_PLUGIN) return plugin_get_num_plugins(); +#else + return 0; +#endif } /* ---------------------------------------------------------------------- */ @@ -4617,6 +4623,7 @@ set to an empty string, otherwise 1. */ int lammps_plugin_name(int idx, char *stylebuf, char *namebuf, int buf_size) { +#if defined(LMP_PLUGIN) stylebuf[0] = namebuf[0] = '\0'; const lammpsplugin_t *plugin = plugin_get_info(idx); @@ -4625,6 +4632,7 @@ int lammps_plugin_name(int idx, char *stylebuf, char *namebuf, int buf_size) strncpy(namebuf,plugin->name,buf_size); return 1; } +#endif return 0; } diff --git a/unittest/commands/CMakeLists.txt b/unittest/commands/CMakeLists.txt index 50f85475d3..6fae0c2463 100644 --- a/unittest/commands/CMakeLists.txt +++ b/unittest/commands/CMakeLists.txt @@ -1,6 +1,6 @@ # build LAMMPS plugins, but not on Windows -if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") +if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND PKG_PLUGIN) ExternalProject_Add(plugins SOURCE_DIR "${LAMMPS_DIR}/examples/plugins" BINARY_DIR ${CMAKE_BINARY_DIR}/build-plugins diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index 448224f730..d98146d4f3 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -367,6 +367,7 @@ TEST_F(SimpleCommandsTest, Units) TEST_FAILURE(".*ERROR: Illegal units command.*", lmp->input->one("units unknown");); } +#if defined(LMP_PLUGIN) TEST_F(SimpleCommandsTest, Plugin) { #if defined(__APPLE__) @@ -437,6 +438,7 @@ TEST_F(SimpleCommandsTest, Plugin) if (verbose) std::cout << text; ASSERT_THAT(text, MatchesRegex(".*Currently loaded plugins.*")); } +#endif TEST_F(SimpleCommandsTest, Shell) { From 28e986c266580f87d1f100f22e309ea7f2d60c1e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 16 Mar 2021 23:25:46 -0400 Subject: [PATCH 068/257] add python module support for plugins --- python/lammps/core.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/python/lammps/core.py b/python/lammps/core.py index eaf78dfa0c..e75647fe44 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -264,6 +264,9 @@ class lammps(object): self.lib.lammps_id_name.argtypes = [c_void_p, c_char_p, c_int, c_char_p, c_int] + self.lib.lammps_plugin_count.argtypes = [ ] + self.lib.lammps_plugin_name.argtypes = [c_int, c_char_p, c_char_p, c_int] + self.lib.lammps_version.argtypes = [c_void_p] self.lib.lammps_get_os_info.argtypes = [c_char_p, c_int] @@ -1594,6 +1597,29 @@ class lammps(object): # ------------------------------------------------------------------------- + def available_plugins(self, category): + """Returns a list of plugins available for a given category + + This is a wrapper around the functions :cpp:func:`lammps_plugin_count()` + and :cpp:func:`lammps_plugin_name()` of the library interface. + + .. versionadded:: 10Mar2021 + + :return: list of style/name pairs of loaded plugins + :rtype: list + """ + + available_plugins = [] + num = self.lib.lammps_plugin_count(self.lmp) + sty = create_string_buffer(100) + nam = create_string_buffer(100) + for idx in range(num): + self.lib.lammps_plugin_name(idx, sty, nam, 100) + available_plugins.append([sty.value.decode(), nam.value.decode()]) + return available_plugins + + # ------------------------------------------------------------------------- + def set_fix_external_callback(self, fix_name, callback, caller=None): import numpy as np From 78126c5eb3f9f9cd961901301f435c0fdef7fed7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 16 Mar 2021 23:32:08 -0400 Subject: [PATCH 069/257] fix cmake unit test issue --- unittest/commands/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unittest/commands/CMakeLists.txt b/unittest/commands/CMakeLists.txt index 6fae0c2463..a658c8a25d 100644 --- a/unittest/commands/CMakeLists.txt +++ b/unittest/commands/CMakeLists.txt @@ -23,7 +23,9 @@ if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND PKG_PLUGIN) endif() add_executable(test_simple_commands test_simple_commands.cpp) -add_dependencies(test_simple_commands plugins) +if(PKG_PLUGIN) + add_dependencies(test_simple_commands plugins) +endif() target_link_libraries(test_simple_commands PRIVATE lammps GTest::GMock GTest::GTest) add_test(NAME SimpleCommands COMMAND test_simple_commands WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) From a76a8eae59354f28c07a8c752393f86886abfd50 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 16 Mar 2021 23:41:18 -0400 Subject: [PATCH 070/257] fix segfault when processing empty lines --- src/library.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index aefc28801f..8de36a299f 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -444,12 +444,11 @@ is passed to :cpp:func:`lammps_commands_string` for processing. void lammps_commands_list(void *handle, int ncmd, const char **cmds) { - LAMMPS *lmp = (LAMMPS *) handle; std::string allcmds; for (int i = 0; i < ncmd; i++) { allcmds.append(cmds[i]); - if (allcmds.back() != '\n') allcmds.append(1,'\n'); + if (allcmds.empty() || (allcmds.back() != '\n')) allcmds.append(1,'\n'); } lammps_commands_string(handle,allcmds.c_str()); From 2a6fcee5e00b70dafa49b5992507a1eaa721f797 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 16 Mar 2021 23:42:06 -0400 Subject: [PATCH 071/257] add missing file (was ignored by default) --- lib/plugin/Makefile.lammps | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/plugin/Makefile.lammps diff --git a/lib/plugin/Makefile.lammps b/lib/plugin/Makefile.lammps new file mode 100644 index 0000000000..87f4f8a771 --- /dev/null +++ b/lib/plugin/Makefile.lammps @@ -0,0 +1,16 @@ +# This file contains the hooks to build and link LAMMPS so it can load plugins +# +# The plugin_SYSINC and plugin_SYSPATH variables do not typically need +# to be set. If the dl library is not in a place the linker can find +# it, specify its directory via the plugin_SYSPATH variable, e.g. +# -Ldir. + +# ----------------------------------------------------------- + +# Settings that the LAMMPS build will import when this package is installed + +ifeq ($(mode),shared) +plugin_SYSINC = -DLMP_PLUGIN +endif +plugin_SYSLIB = -ldl +plugin_SYSPATH = From ddc77be911e2f61967a1db4685be1c405015d32e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 16 Mar 2021 23:52:44 -0400 Subject: [PATCH 072/257] update docs for converting the plugin feature to a package --- doc/src/Packages_details.rst | 23 +++++++++++++++++++++++ doc/src/plugin.rst | 5 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/doc/src/Packages_details.rst b/doc/src/Packages_details.rst index e858593c4c..301e6bfd4a 100644 --- a/doc/src/Packages_details.rst +++ b/doc/src/Packages_details.rst @@ -50,6 +50,7 @@ page gives those details. * :ref:`MSCG ` * :ref:`OPT ` * :ref:`PERI ` + * :ref:`PLUGIN ` * :ref:`POEMS ` * :ref:`PYTHON ` * :ref:`QEQ ` @@ -843,6 +844,28 @@ Foster (UTSA). ---------- +.. _PKG-PLUGIN: + +PLUGIN package +-------------- + +**Contents:** + +A :doc:`plugin ` command that can load and unload several +kind of styles in LAMMPS from shared object files at runtime without +having to recompile and relink LAMMPS. + +**Authors:** Axel Kohlmeyer (Temple U) + +**Supporting info:** + +* src/PLUGIN: filenames -> commands +* :doc:`plugin command ` +* :doc:`Information on writing plugins ` +* examples/plugin + +---------- + .. _PKG-POEMS: POEMS package diff --git a/doc/src/plugin.rst b/doc/src/plugin.rst index e8a5f67e3c..48638bf97a 100644 --- a/doc/src/plugin.rst +++ b/doc/src/plugin.rst @@ -60,7 +60,10 @@ The *clear* command will unload all currently loaded plugins. Restrictions """""""""""" -Plugins are not available on Windows. +The *plugin* command is part of the PLUGIN package. It is +only enabled if LAMMPS was built with that package. +See the :doc:`Build package ` doc page for +more info. Plugins are not available on Windows. For the loading of plugins to work the LAMMPS library must be :ref:`compiled as a shared library `. If plugins From 2dc0b705755393d14f70e01981458208755f5335 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 17 Mar 2021 00:10:01 -0400 Subject: [PATCH 073/257] simplify some more code by using utils::strdup() --- src/force.cpp | 20 ++++++-------------- src/imbalance_store.cpp | 5 +---- src/imbalance_var.cpp | 5 +---- src/input.cpp | 15 ++++----------- 4 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/force.cpp b/src/force.cpp index 0073366c27..e56e250ffc 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -61,20 +61,12 @@ Force::Force(LAMMPS *lmp) : Pointers(lmp) improper = nullptr; kspace = nullptr; - char *str = (char *) "none"; - int n = strlen(str) + 1; - pair_style = new char[n]; - strcpy(pair_style,str); - bond_style = new char[n]; - strcpy(bond_style,str); - angle_style = new char[n]; - strcpy(angle_style,str); - dihedral_style = new char[n]; - strcpy(dihedral_style,str); - improper_style = new char[n]; - strcpy(improper_style,str); - kspace_style = new char[n]; - strcpy(kspace_style,str); + pair_style = utils::strdup("none"); + bond_style = utils::strdup("none"); + angle_style = utils::strdup("none"); + dihedral_style = utils::strdup("none"); + improper_style = utils::strdup("none"); + kspace_style = utils::strdup("none"); pair_restart = nullptr; create_factories(); diff --git a/src/imbalance_store.cpp b/src/imbalance_store.cpp index 9815744b2d..879b434bfd 100644 --- a/src/imbalance_store.cpp +++ b/src/imbalance_store.cpp @@ -36,10 +36,7 @@ ImbalanceStore::~ImbalanceStore() int ImbalanceStore::options(int narg, char **arg) { if (narg < 1) error->all(FLERR,"Illegal balance weight command"); - - int len = strlen(arg[0]) + 1; - name = new char[len]; - memcpy(name,arg[0],len); + name = utils::strdup(arg[0]); return 1; } diff --git a/src/imbalance_var.cpp b/src/imbalance_var.cpp index 2265e6e4c0..d2a4f0d691 100644 --- a/src/imbalance_var.cpp +++ b/src/imbalance_var.cpp @@ -40,10 +40,7 @@ ImbalanceVar::~ImbalanceVar() int ImbalanceVar::options(int narg, char **arg) { if (narg < 1) error->all(FLERR,"Illegal balance weight command"); - - int len = strlen(arg[0]) + 1; - name = new char[len]; - memcpy(name,arg[0],len); + name = utils::strdup(arg[0]); init(0); return 1; diff --git a/src/input.cpp b/src/input.cpp index eeb211a6d1..9ac140753a 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1013,9 +1013,7 @@ void Input::jump() if (narg == 2) { label_active = 1; if (labelstr) delete [] labelstr; - int n = strlen(arg[1]) + 1; - labelstr = new char[n]; - strcpy(labelstr,arg[1]); + labelstr = utils::strdup(arg[1]); } } @@ -1840,17 +1838,12 @@ void Input::suffix() if (strcmp(arg[0],"hybrid") == 0) { if (narg != 3) error->all(FLERR,"Illegal suffix command"); - int n = strlen(arg[1]) + 1; - lmp->suffix = new char[n]; - strcpy(lmp->suffix,arg[1]); + lmp->suffix = utils::strdup(arg[1]); n = strlen(arg[2]) + 1; - lmp->suffix2 = new char[n]; - strcpy(lmp->suffix2,arg[2]); + lmp->suffix2 = utils::strdup(arg[2]); } else { if (narg != 1) error->all(FLERR,"Illegal suffix command"); - int n = strlen(arg[0]) + 1; - lmp->suffix = new char[n]; - strcpy(lmp->suffix,arg[0]); + lmp->suffix = utils::strdup(arg[0]); } } } From 5ba57fdd446be186e82ef9cb5b818575caaa534c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 17 Mar 2021 00:21:40 -0400 Subject: [PATCH 074/257] forgot to delete this line --- src/input.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/input.cpp b/src/input.cpp index 9ac140753a..53fcc606db 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1839,7 +1839,6 @@ void Input::suffix() if (strcmp(arg[0],"hybrid") == 0) { if (narg != 3) error->all(FLERR,"Illegal suffix command"); lmp->suffix = utils::strdup(arg[1]); - n = strlen(arg[2]) + 1; lmp->suffix2 = utils::strdup(arg[2]); } else { if (narg != 1) error->all(FLERR,"Illegal suffix command"); From 611eb306bea0d53f304d4edcdc46e0095bbe5a69 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Wed, 17 Mar 2021 10:37:24 +0100 Subject: [PATCH 075/257] Update python/examples/pylammps/elastic/elastic.py Co-authored-by: Richard Berger --- python/examples/pylammps/elastic/elastic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/examples/pylammps/elastic/elastic.py b/python/examples/pylammps/elastic/elastic.py index 81d3832480..bfb1215ddc 100644 --- a/python/examples/pylammps/elastic/elastic.py +++ b/python/examples/pylammps/elastic/elastic.py @@ -127,7 +127,7 @@ def displace(lmp, args, idir): c5pos = lmp.variables["d5"].value c6pos = lmp.variables["d6"].value - # Combine posiive and negative + # Combine positive and negative lmp.variable("C1{} equal {}".format(idir, 0.5*(c1neg+c1pos))) lmp.variable("C2{} equal {}".format(idir, 0.5*(c2neg+c2pos))) lmp.variable("C3{} equal {}".format(idir, 0.5*(c3neg+c3pos))) From 05d6c1e7579cc8a9df5d413001165bbb56ecdf72 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Wed, 17 Mar 2021 10:37:39 +0100 Subject: [PATCH 076/257] Update python/examples/pylammps/elastic/elastic.py Co-authored-by: Richard Berger --- python/examples/pylammps/elastic/elastic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/examples/pylammps/elastic/elastic.py b/python/examples/pylammps/elastic/elastic.py index bfb1215ddc..e29d18efb9 100644 --- a/python/examples/pylammps/elastic/elastic.py +++ b/python/examples/pylammps/elastic/elastic.py @@ -179,7 +179,7 @@ def elastic(): L.box("tilt large") # to avoid termination if the final simulation box has a high tilt factor # use the OpenKIM model to set the energy interactions - L.kim_init(args.kim_model, "metal", "unit_conversion_mode") + L.kim("init", args.kim_model, "metal", "unit_conversion_mode") L.read_data(args.input_data_file) From ecbb75ff3ca1f41b3e83833ab64c63e455c77ca2 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Wed, 17 Mar 2021 12:30:02 +0100 Subject: [PATCH 077/257] removing parentheses from mass dictionary --- python/examples/pylammps/elastic/elastic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/examples/pylammps/elastic/elastic.py b/python/examples/pylammps/elastic/elastic.py index e29d18efb9..e4cad11736 100644 --- a/python/examples/pylammps/elastic/elastic.py +++ b/python/examples/pylammps/elastic/elastic.py @@ -186,7 +186,7 @@ def elastic(): potential(L, args) # Need to set mass to something, just to satisfy LAMMPS - mass_dictionary = {'H': 1.00797, 'He': 4.00260, 'Li': 6.941, 'Be': 9.01218, 'B': 10.81, 'C': 12.011, 'N': 14.0067, 'O': 15.9994, 'F': 18.998403, 'Ne': 20.179, 'Na': 22.98977, 'Mg': 24.305, 'Al': 26.98154, 'Si': 28.0855, 'P': 30.97376, 'S': 32.06, 'Cl': 35.453, 'K': 39.0983, 'Ar': 39.948, 'Ca': 40.08, 'Sc': 44.9559, 'Ti': 47.90, 'V': 50.9415, 'Cr': 51.996, 'Mn': 54.9380, 'Fe': 55.847, 'Ni': 58.70, 'Co': 58.9332, 'Cu': 63.546, 'Zn': 65.38, 'Ga': 69.72, 'Ge': 72.59, 'As': 74.9216, 'Se': 78.96, 'Br': 79.904, 'Kr': 83.80, 'Rb': 85.4678, 'Sr': 87.62, 'Y': 88.9059, 'Zr': 91.22, 'Nb': 92.9064, 'Mo': 95.94, 'Tc': (98), 'Ru': 101.07, 'Rh': 102.9055, 'Pd': 106.4, 'Ag': 107.868, 'Cd': 112.41, 'In': 114.82, 'Sn': 118.69, 'Sb': 121.75, 'I': 126.9045, 'Te': 127.60, 'Xe': 131.30, 'Cs': 132.9054, 'Ba': 137.33, 'La': 138.9055, 'Ce': 140.12, 'Pr': 140.9077, 'Nd': 144.24, 'Pm': (145), 'Sm': 150.4, 'Eu': 151.96, 'Gd': 157.25, 'Tb': 158.9254, 'Dy': 162.50, 'Ho': 164.9304, 'Er': 167.26, 'Tm': 168.9342, 'Yb': 173.04, 'Lu': 174.967, 'Hf': 178.49, 'Ta': 180.9479, 'W': 183.85, 'Re': 186.207, 'Os': 190.2, 'Ir': 192.22, 'Pt': 195.09, 'Au': 196.9665, 'Hg': 200.59, 'Tl': 204.37, 'Pb': 207.2, 'Bi': 208.9804, 'Po': (209), 'At': (210), 'Rn': (222), 'Fr': (223), 'Ra': 226.0254, 'Ac': 227.0278, 'Pa': 231.0359, 'Th': 232.0381, 'Np': 237.0482, 'U': 238.029} + mass_dictionary = {'H': 1.00797, 'He': 4.00260, 'Li': 6.941, 'Be': 9.01218, 'B': 10.81, 'C': 12.011, 'N': 14.0067, 'O': 15.9994, 'F': 18.998403, 'Ne': 20.179, 'Na': 22.98977, 'Mg': 24.305, 'Al': 26.98154, 'Si': 28.0855, 'P': 30.97376, 'S': 32.06, 'Cl': 35.453, 'K': 39.0983, 'Ar': 39.948, 'Ca': 40.08, 'Sc': 44.9559, 'Ti': 47.90, 'V': 50.9415, 'Cr': 51.996, 'Mn': 54.9380, 'Fe': 55.847, 'Ni': 58.70, 'Co': 58.9332, 'Cu': 63.546, 'Zn': 65.38, 'Ga': 69.72, 'Ge': 72.59, 'As': 74.9216, 'Se': 78.96, 'Br': 79.904, 'Kr': 83.80, 'Rb': 85.4678, 'Sr': 87.62, 'Y': 88.9059, 'Zr': 91.22, 'Nb': 92.9064, 'Mo': 95.94, 'Tc': 98, 'Ru': 101.07, 'Rh': 102.9055, 'Pd': 106.4, 'Ag': 107.868, 'Cd': 112.41, 'In': 114.82, 'Sn': 118.69, 'Sb': 121.75, 'I': 126.9045, 'Te': 127.60, 'Xe': 131.30, 'Cs': 132.9054, 'Ba': 137.33, 'La': 138.9055, 'Ce': 140.12, 'Pr': 140.9077, 'Nd': 144.24, 'Pm': 145, 'Sm': 150.4, 'Eu': 151.96, 'Gd': 157.25, 'Tb': 158.9254, 'Dy': 162.50, 'Ho': 164.9304, 'Er': 167.26, 'Tm': 168.9342, 'Yb': 173.04, 'Lu': 174.967, 'Hf': 178.49, 'Ta': 180.9479, 'W': 183.85, 'Re': 186.207, 'Os': 190.2, 'Ir': 192.22, 'Pt': 195.09, 'Au': 196.9665, 'Hg': 200.59, 'Tl': 204.37, 'Pb': 207.2, 'Bi': 208.9804, 'Po': 209, 'At': 210, 'Rn': 222, 'Fr': 223, 'Ra': 226.0254, 'Ac': 227.0278, 'Pa': 231.0359, 'Th': 232.0381, 'Np': 237.0482, 'U': 238.029} for itype in range(1, len(args.elements)+1): L.mass(itype, mass_dictionary.get(args.elements[itype-1], 1.0e-20)) From 199595c5105fbd605ada5616aefa21f78f7df0df Mon Sep 17 00:00:00 2001 From: "Ryan S. Elliott" Date: Wed, 17 Mar 2021 10:54:55 -0500 Subject: [PATCH 078/257] Small adjustment to log message --- src/KIM/kim_query.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/KIM/kim_query.cpp b/src/KIM/kim_query.cpp index cc4ece4406..789509682d 100644 --- a/src/KIM/kim_query.cpp +++ b/src/KIM/kim_query.cpp @@ -222,7 +222,8 @@ void KimQuery::command(int narg, char **arg) if (available.empty()) error->all(FLERR, - fmt::format("There is no OpenKIM model installed on the system")); + fmt::format( + "There are no matching OpenKIM models installed on the system")); // replace results with available strcpy(value, available.c_str()); // available guaranteed to fit From 482aa7a66dec4726ffd3db212f760aed21771775 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Thu, 18 Mar 2021 14:19:57 +0000 Subject: [PATCH 079/257] Reset LAMMPS_LAMBDA to KOKKOS_LAMBDA --- src/KOKKOS/kokkos_type.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/KOKKOS/kokkos_type.h b/src/KOKKOS/kokkos_type.h index e701cb4064..b555cc5a03 100644 --- a/src/KOKKOS/kokkos_type.h +++ b/src/KOKKOS/kokkos_type.h @@ -1164,11 +1164,7 @@ typedef SNAComplex SNAcomplex; #define ISFINITE(x) std::isfinite(x) #endif -#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) -#define LAMMPS_LAMBDA [=] __device__ -#else -#define LAMMPS_LAMBDA [=] -#endif +#define LAMMPS_LAMBDA KOKKOS_LAMBDA #if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) #define LAMMPS_DEVICE_FUNCTION __device__ From d5a1591cd11f87c4641106083fcc9ad5fdff506a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 12:12:30 -0400 Subject: [PATCH 080/257] simplify code - use Tokenizer instead of ValueTokenizer since no value conversions are needed - don't use fmt::format() when no string formatting is needed --- src/KIM/kim_query.cpp | 71 +++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/src/KIM/kim_query.cpp b/src/KIM/kim_query.cpp index 789509682d..74b0179302 100644 --- a/src/KIM/kim_query.cpp +++ b/src/KIM/kim_query.cpp @@ -119,38 +119,36 @@ void KimQuery::command(int narg, char **arg) } ++arg; --narg; - // The “list” is the default setting + // The "list" is the default setting // the result is returned as a space-separated list of values in a variable } else format_arg = "list"; - std::string query_function{arg[1]}; + std::string query_function(arg[1]); if (query_function == "split" || query_function == "list" || - query_function == "index") { - auto msg = fmt::format("Illegal 'kim query' command.\nThe '{}' keyword " - "can not be used after '{}'", query_function, format_arg); - error->all(FLERR, msg); - } + query_function == "index") + error->all(FLERR, fmt::format("Illegal 'kim query' command.\nThe '{}' " + "keyword can not be used after '{}'", + query_function, format_arg)); std::string model_name; // check the query_args format (a series of keyword=value pairs) for (int i = 2; i < narg; ++i) { - if (!utils::strmatch(arg[i], "[=][\\[].*[\\]]")) { - auto msg = fmt::format("Illegal query format.\nInput argument " - "of `{}` to 'kim query' is wrong. The query format is the " - "keyword=[value], where value is always an array of one or " - "more comma-separated items", arg[i]); - error->all(FLERR, msg); - } + if (!utils::strmatch(arg[i], "[=][\\[].*[\\]]")) + error->all(FLERR, fmt::format("Illegal query format.\nInput argument " + "of `{}` to 'kim query' is wrong. The " + "query format is the keyword=[value], " + "where value is always an array of one or " + "more comma-separated items", arg[i])); } if (query_function != "get_available_models") { for (int i = 2; i < narg; ++i) { // check if the model is specified as an argument if (utils::strmatch(arg[i], "^model=")) { - ValueTokenizer values(arg[i], "=[]"); - std::string key = values.next_string(); - model_name = values.next_string(); + Tokenizer values(arg[i], "=[]"); + values.skip(1); + model_name = values.next(); break; } } @@ -161,12 +159,12 @@ void KimQuery::command(int narg, char **arg) if (ifix >= 0) { FixStoreKIM *fix_store = (FixStoreKIM *) modify->fix[ifix]; char *model_name_c = (char *) fix_store->getptr("model_name"); - model_name = fmt::format("{}", model_name_c); + model_name = model_name_c; } else { - auto msg = fmt::format("Illegal query format.\nMust use 'kim init' " - "before 'kim query' or must provide the model name after query " - "function with the format of 'model=[model_name]'"); - error->all(FLERR, msg); + error->all(FLERR, "Illegal query format.\nMust use 'kim init' " + "before 'kim query' or must provide the model name " + "after query function with the format of " + "'model=[model_name]'"); } } } @@ -185,31 +183,30 @@ void KimQuery::command(int narg, char **arg) error->all(FLERR, msg); } else if (strcmp(value, "EMPTY") == 0) { delete [] value; - error->all(FLERR, fmt::format("OpenKIM query returned no results")); + error->all(FLERR, "OpenKIM query returned no results"); } input->write_echo("#=== BEGIN kim-query ==================================" "=======\n"); // trim list of models to those that are installed on the system if (query_function == "get_available_models") { - ValueTokenizer vals(value, ", \""); + Tokenizer vals(value, ", \""); std::string available; std::string missing; - KIM_Collections * collections; + KIM_Collections *collections; KIM_CollectionItemType typ; if (KIM_Collections_Create(&collections)) { delete [] value; - error->all(FLERR, - fmt::format("Unable to access KIM Collections to find Model")); + error->all(FLERR, "Unable to access KIM Collections to find Model"); } auto logID = fmt::format("{}_Collections", comm->me); KIM_Collections_SetLogID(collections, logID.c_str()); while (vals.has_next()) { - auto svalue = vals.next_string(); + auto svalue = vals.next(); if (KIM_Collections_GetItemType(collections, svalue.c_str(), &typ)) missing += fmt::format("{}, ", svalue); else @@ -220,34 +217,34 @@ void KimQuery::command(int narg, char **arg) input->write_echo( fmt::format("# Missing OpenKIM models: {}\n\n", missing)); - if (available.empty()) - error->all(FLERR, - fmt::format( - "There are no matching OpenKIM models installed on the system")); + if (available.empty()) { + delete [] value; + error->all(FLERR,"There are no matching OpenKIM models installed on the system"); + } // replace results with available strcpy(value, available.c_str()); // available guaranteed to fit }; - ValueTokenizer values(value, ","); + Tokenizer values(value, ","); if (format_arg == "split") { int counter = 1; while (values.has_next()) { - auto svalue = values.next_string(); + auto svalue = values.next(); auto setcmd = fmt::format("{}_{} string {}", var_name, counter++, svalue); input->variable->set(setcmd); input->write_echo(fmt::format("variable {}\n", setcmd)); } } else { std::string setcmd; - auto svalue = utils::trim(values.next_string()); + auto svalue = utils::trim(values.next()); if (format_arg == "list") { setcmd = fmt::format("{} string \"", var_name); setcmd += (svalue.front() == '"' && svalue.back() == '"') ? fmt::format("{}", svalue.substr(1, svalue.size() - 2)) : fmt::format("{}", svalue); while (values.has_next()) { - svalue = utils::trim(values.next_string()); + svalue = utils::trim(values.next()); setcmd += (svalue.front() == '"' && svalue.back() == '"') ? fmt::format(" {}", svalue.substr(1, svalue.size() - 2)) : fmt::format(" {}", svalue); @@ -257,7 +254,7 @@ void KimQuery::command(int narg, char **arg) // format_arg == "index" setcmd = fmt::format("{} index {}", var_name, svalue); while (values.has_next()) { - svalue = values.next_string(); + svalue = values.next(); setcmd += fmt::format(" {}", svalue); } } From c5ab2becd790649e14845cd8dee45bfa7190e49d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 12:25:31 -0400 Subject: [PATCH 081/257] fix bug in utils::expand_args() --- src/utils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils.cpp b/src/utils.cpp index 3754a9886f..b5576b9f27 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -473,6 +473,7 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, for (iarg = 0; iarg < narg; iarg++) { std::string word(arg[iarg]); + expandflag = 0; // only match compute/fix reference with a '*' wildcard // number range in the first pair of square brackets From 4cbf8eb2f8fc1a75df51837cd6b25d03446570f3 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Thu, 18 Mar 2021 11:55:04 -0600 Subject: [PATCH 082/257] Fix issues in pair_coul_debye_kokkos, pointed out by @weinbe2 --- src/KOKKOS/pair_coul_debye_kokkos.cpp | 32 +++++++++------------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/KOKKOS/pair_coul_debye_kokkos.cpp b/src/KOKKOS/pair_coul_debye_kokkos.cpp index a3332e6997..e380a874ff 100644 --- a/src/KOKKOS/pair_coul_debye_kokkos.cpp +++ b/src/KOKKOS/pair_coul_debye_kokkos.cpp @@ -56,9 +56,8 @@ PairCoulDebyeKokkos::PairCoulDebyeKokkos(LAMMPS *lmp):PairCoulDebye( template PairCoulDebyeKokkos::~PairCoulDebyeKokkos() { - if (!copymode) { + if (allocated) memoryKK->destroy_kokkos(k_cutsq, cutsq); - } } /* ---------------------------------------------------------------------- */ @@ -125,15 +124,12 @@ void PairCoulDebyeKokkos::compute(int eflag_in, int vflag_in) // loop over neighbors of my atoms - copymode = 1; - EV_FLOAT ev = pair_compute,void > (this,(NeighListKokkos*)list); - if (eflag) { - eng_vdwl += ev.evdwl; + if (eflag) eng_coul += ev.ecoul; - } + if (vflag_global) { virial[0] += ev.v[0]; virial[1] += ev.v[1]; @@ -154,8 +150,6 @@ void PairCoulDebyeKokkos::compute(int eflag_in, int vflag_in) } if (vflag_fdotr) pair_virial_fdotr_compute(this); - - copymode = 0; } /* ---------------------------------------------------------------------- @@ -214,6 +208,12 @@ void PairCoulDebyeKokkos::allocate() memory->destroy(cutsq); memoryKK->create_kokkos(k_cutsq,cutsq,n+1,n+1,"pair:cutsq"); d_cutsq = k_cutsq.template view(); + + k_cut_ljsq = typename ArrayTypes::tdual_ffloat_2d("pair:cut_ljsq",n+1,n+1); + d_cut_ljsq = k_cut_ljsq.template view(); + k_cut_coulsq = typename ArrayTypes::tdual_ffloat_2d("pair:cut_coulsq",n+1,n+1); + d_cut_coulsq = k_cut_coulsq.template view(); + k_params = Kokkos::DualView("PairCoulDebye::params",n+1,n+1); params = k_params.template view(); } @@ -250,16 +250,6 @@ void PairCoulDebyeKokkos::init_style() { PairCoulDebye::init_style(); - // error if rRESPA with inner levels - - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { - int respa = 0; - if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; - if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; - if (respa) - error->all(FLERR,"Cannot use Kokkos pair style with rRESPA inner/middle"); - } - // irequest = neigh request made by parent class neighflag = lmp->kokkos->neighflag; @@ -303,9 +293,9 @@ double PairCoulDebyeKokkos::init_one(int i, int j) } k_cutsq.h_view(i,j) = cutone*cutone; k_cutsq.template modify(); - //k_cut_ljsq.h_view(i,j) = cutone*cutone; + k_cut_ljsq.h_view(i,j) = cutone*cutone; k_cut_ljsq.template modify(); - //k_cut_coulsq.h_view(i,j) = cutone*cutone; + k_cut_coulsq.h_view(i,j) = cutone*cutone; k_cut_coulsq.template modify(); k_params.template modify(); From 64ba2f4ee2b27098bd423c18f97fd2e3f8dfd7cb Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 18 Mar 2021 14:26:18 -0400 Subject: [PATCH 083/257] Add missing checks for C++ exceptions --- python/lammps/core.py | 217 +++++++++++++++++++++++++----------------- 1 file changed, 132 insertions(+), 85 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index eaf78dfa0c..be026d5e10 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -39,6 +39,20 @@ class MPIAbortException(Exception): # ------------------------------------------------------------------------- +class ExceptionCheck: + """Utility class to rethrow LAMMPS C++ exceptions as Python exceptions""" + def __init__(self, lmp): + self.lmp = lmp + + def __enter__(self): + pass + + def __exit__(self, type, value, traceback): + if self.lmp.has_exceptions and self.lmp.lib.lammps_has_error(self.lmp.lmp): + raise self.lmp._lammps_exception + +# ------------------------------------------------------------------------- + class lammps(object): """Create an instance of the LAMMPS Python class. @@ -519,10 +533,9 @@ class lammps(object): """ if path: path = path.encode() else: return - self.lib.lammps_file(self.lmp, path) - if self.has_exceptions and self.lib.lammps_has_error(self.lmp): - raise self._lammps_exception + with ExceptionCheck(self): + self.lib.lammps_file(self.lmp, path) # ------------------------------------------------------------------------- @@ -537,10 +550,9 @@ class lammps(object): """ if cmd: cmd = cmd.encode() else: return - self.lib.lammps_command(self.lmp,cmd) - if self.has_exceptions and self.lib.lammps_has_error(self.lmp): - raise self._lammps_exception + with ExceptionCheck(self): + self.lib.lammps_command(self.lmp,cmd) # ------------------------------------------------------------------------- @@ -558,10 +570,9 @@ class lammps(object): narg = len(cmdlist) args = (c_char_p * narg)(*cmds) self.lib.lammps_commands_list.argtypes = [c_void_p, c_int, c_char_p * narg] - self.lib.lammps_commands_list(self.lmp,narg,args) - if self.has_exceptions and self.lib.lammps_has_error(self.lmp): - raise self._lammps_exception + with ExceptionCheck(self): + self.lib.lammps_commands_list(self.lmp,narg,args) # ------------------------------------------------------------------------- @@ -576,10 +587,9 @@ class lammps(object): :type multicmd: string """ if type(multicmd) is str: multicmd = multicmd.encode() - self.lib.lammps_commands_string(self.lmp,c_char_p(multicmd)) - if self.has_exceptions and self.lib.lammps_has_error(self.lmp): - raise self._lammps_exception + with ExceptionCheck(self): + self.lib.lammps_commands_string(self.lmp,c_char_p(multicmd)) # ------------------------------------------------------------------------- @@ -614,9 +624,10 @@ class lammps(object): periodicity = (3*c_int)() box_change = c_int() - self.lib.lammps_extract_box(self.lmp,boxlo,boxhi, - byref(xy),byref(yz),byref(xz), - periodicity,byref(box_change)) + with ExceptionCheck(self): + self.lib.lammps_extract_box(self.lmp,boxlo,boxhi, + byref(xy),byref(yz),byref(xz), + periodicity,byref(box_change)) boxlo = boxlo[:3] boxhi = boxhi[:3] @@ -649,7 +660,8 @@ class lammps(object): """ cboxlo = (3*c_double)(*boxlo) cboxhi = (3*c_double)(*boxhi) - self.lib.lammps_reset_box(self.lmp,cboxlo,cboxhi,xy,yz,xz) + with ExceptionCheck(self): + self.lib.lammps_reset_box(self.lmp,cboxlo,cboxhi,xy,yz,xz) # ------------------------------------------------------------------------- @@ -666,7 +678,9 @@ class lammps(object): """ if name: name = name.encode() else: return None - return self.lib.lammps_get_thermo(self.lmp,name) + + with ExceptionCheck(self): + return self.lib.lammps_get_thermo(self.lmp,name) # ------------------------------------------------------------------------- @@ -838,6 +852,7 @@ class lammps(object): elif dtype == LAMMPS_INT64_2D: self.lib.lammps_extract_atom.restype = POINTER(POINTER(c_int64)) else: return None + ptr = self.lib.lammps_extract_atom(self.lmp, name) if ptr: return ptr else: return None @@ -872,39 +887,44 @@ class lammps(object): if type == LMP_TYPE_SCALAR: if style == LMP_STYLE_GLOBAL: self.lib.lammps_extract_compute.restype = POINTER(c_double) - ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) + with ExceptionCheck(self): + ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) return ptr[0] elif style == LMP_STYLE_ATOM: return None elif style == LMP_STYLE_LOCAL: self.lib.lammps_extract_compute.restype = POINTER(c_int) - ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) + with ExceptionCheck(self): + ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) return ptr[0] - if type == LMP_TYPE_VECTOR: + elif type == LMP_TYPE_VECTOR: self.lib.lammps_extract_compute.restype = POINTER(c_double) - ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) + with ExceptionCheck(self): + ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) return ptr - if type == LMP_TYPE_ARRAY: + elif type == LMP_TYPE_ARRAY: self.lib.lammps_extract_compute.restype = POINTER(POINTER(c_double)) - ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) + with ExceptionCheck(self): + ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) return ptr - if type == LMP_SIZE_COLS: + elif type == LMP_SIZE_COLS: if style == LMP_STYLE_GLOBAL \ or style == LMP_STYLE_ATOM \ or style == LMP_STYLE_LOCAL: self.lib.lammps_extract_compute.restype = POINTER(c_int) - ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) + with ExceptionCheck(self): + ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) return ptr[0] - if type == LMP_SIZE_VECTOR \ - or type == LMP_SIZE_ROWS: + elif type == LMP_SIZE_VECTOR or type == LMP_SIZE_ROWS: if style == LMP_STYLE_GLOBAL \ or style == LMP_STYLE_LOCAL: self.lib.lammps_extract_compute.restype = POINTER(c_int) - ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) + with ExceptionCheck(self): + ptr = self.lib.lammps_extract_compute(self.lmp,id,style,type) return ptr[0] return None @@ -947,13 +967,15 @@ class lammps(object): if style == LMP_STYLE_GLOBAL: if type in (LMP_TYPE_SCALAR, LMP_TYPE_VECTOR, LMP_TYPE_ARRAY): self.lib.lammps_extract_fix.restype = POINTER(c_double) - ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,nrow,ncol) + with ExceptionCheck(self): + ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,nrow,ncol) result = ptr[0] self.lib.lammps_free(ptr) return result elif type in (LMP_SIZE_VECTOR, LMP_SIZE_ROWS, LMP_SIZE_COLS): self.lib.lammps_extract_fix.restype = POINTER(c_int) - ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,nrow,ncol) + with ExceptionCheck(self): + ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,nrow,ncol) return ptr[0] else: return None @@ -967,7 +989,8 @@ class lammps(object): self.lib.lammps_extract_fix.restype = POINTER(c_int) else: return None - ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,nrow,ncol) + with ExceptionCheck(self): + ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,nrow,ncol) if type == LMP_SIZE_COLS: return ptr[0] else: @@ -982,7 +1005,8 @@ class lammps(object): self.lib.lammps_extract_fix.restype = POINTER(c_int) else: return None - ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,nrow,ncol) + with ExceptionCheck(self): + ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,nrow,ncol) if type in (LMP_TYPE_VECTOR, LMP_TYPE_ARRAY): return ptr else: @@ -1026,7 +1050,8 @@ class lammps(object): if group: group = group.encode() if vartype == LMP_VAR_EQUAL: self.lib.lammps_extract_variable.restype = POINTER(c_double) - ptr = self.lib.lammps_extract_variable(self.lmp,name,group) + with ExceptionCheck(self): + ptr = self.lib.lammps_extract_variable(self.lmp,name,group) if ptr: result = ptr[0] else: return None self.lib.lammps_free(ptr) @@ -1035,7 +1060,8 @@ class lammps(object): nlocal = self.extract_global("nlocal") result = (c_double*nlocal)() self.lib.lammps_extract_variable.restype = POINTER(c_double) - ptr = self.lib.lammps_extract_variable(self.lmp,name,group) + with ExceptionCheck(self): + ptr = self.lib.lammps_extract_variable(self.lmp,name,group) if ptr: for i in range(nlocal): result[i] = ptr[i] self.lib.lammps_free(ptr) @@ -1062,7 +1088,8 @@ class lammps(object): else: return -1 if value: value = str(value).encode() else: return -1 - return self.lib.lammps_set_variable(self.lmp,name,value) + with ExceptionCheck(self): + return self.lib.lammps_set_variable(self.lmp,name,value) # ------------------------------------------------------------------------- @@ -1078,13 +1105,15 @@ class lammps(object): def gather_atoms(self,name,type,count): if name: name = name.encode() natoms = self.get_natoms() - if type == 0: - data = ((count*natoms)*c_int)() - self.lib.lammps_gather_atoms(self.lmp,name,type,count,data) - elif type == 1: - data = ((count*natoms)*c_double)() - self.lib.lammps_gather_atoms(self.lmp,name,type,count,data) - else: return None + with ExceptionCheck(self): + if type == 0: + data = ((count*natoms)*c_int)() + self.lib.lammps_gather_atoms(self.lmp,name,type,count,data) + elif type == 1: + data = ((count*natoms)*c_double)() + self.lib.lammps_gather_atoms(self.lmp,name,type,count,data) + else: + return None return data # ------------------------------------------------------------------------- @@ -1092,24 +1121,28 @@ class lammps(object): def gather_atoms_concat(self,name,type,count): if name: name = name.encode() natoms = self.get_natoms() - if type == 0: - data = ((count*natoms)*c_int)() - self.lib.lammps_gather_atoms_concat(self.lmp,name,type,count,data) - elif type == 1: - data = ((count*natoms)*c_double)() - self.lib.lammps_gather_atoms_concat(self.lmp,name,type,count,data) - else: return None + with ExceptionCheck(self): + if type == 0: + data = ((count*natoms)*c_int)() + self.lib.lammps_gather_atoms_concat(self.lmp,name,type,count,data) + elif type == 1: + data = ((count*natoms)*c_double)() + self.lib.lammps_gather_atoms_concat(self.lmp,name,type,count,data) + else: + return None return data def gather_atoms_subset(self,name,type,count,ndata,ids): if name: name = name.encode() - if type == 0: - data = ((count*ndata)*c_int)() - self.lib.lammps_gather_atoms_subset(self.lmp,name,type,count,ndata,ids,data) - elif type == 1: - data = ((count*ndata)*c_double)() - self.lib.lammps_gather_atoms_subset(self.lmp,name,type,count,ndata,ids,data) - else: return None + with ExceptionCheck(self): + if type == 0: + data = ((count*ndata)*c_int)() + self.lib.lammps_gather_atoms_subset(self.lmp,name,type,count,ndata,ids,data) + elif type == 1: + data = ((count*ndata)*c_double)() + self.lib.lammps_gather_atoms_subset(self.lmp,name,type,count,ndata,ids,data) + else: + return None return data # ------------------------------------------------------------------------- @@ -1125,13 +1158,15 @@ class lammps(object): def scatter_atoms(self,name,type,count,data): if name: name = name.encode() - self.lib.lammps_scatter_atoms(self.lmp,name,type,count,data) + with ExceptionCheck(self): + self.lib.lammps_scatter_atoms(self.lmp,name,type,count,data) # ------------------------------------------------------------------------- def scatter_atoms_subset(self,name,type,count,ndata,ids,data): if name: name = name.encode() - self.lib.lammps_scatter_atoms_subset(self.lmp,name,type,count,ndata,ids,data) + with ExceptionCheck(self): + self.lib.lammps_scatter_atoms_subset(self.lmp,name,type,count,ndata,ids,data) # return vector of atom/compute/fix properties gathered across procs # 3 variants to match src/library.cpp @@ -1144,36 +1179,42 @@ class lammps(object): def gather(self,name,type,count): if name: name = name.encode() natoms = self.get_natoms() - if type == 0: - data = ((count*natoms)*c_int)() - self.lib.lammps_gather(self.lmp,name,type,count,data) - elif type == 1: - data = ((count*natoms)*c_double)() - self.lib.lammps_gather(self.lmp,name,type,count,data) - else: return None + with ExceptionCheck(self): + if type == 0: + data = ((count*natoms)*c_int)() + self.lib.lammps_gather(self.lmp,name,type,count,data) + elif type == 1: + data = ((count*natoms)*c_double)() + self.lib.lammps_gather(self.lmp,name,type,count,data) + else: + return None return data def gather_concat(self,name,type,count): if name: name = name.encode() natoms = self.get_natoms() - if type == 0: - data = ((count*natoms)*c_int)() - self.lib.lammps_gather_concat(self.lmp,name,type,count,data) - elif type == 1: - data = ((count*natoms)*c_double)() - self.lib.lammps_gather_concat(self.lmp,name,type,count,data) - else: return None + with ExceptionCheck(self): + if type == 0: + data = ((count*natoms)*c_int)() + self.lib.lammps_gather_concat(self.lmp,name,type,count,data) + elif type == 1: + data = ((count*natoms)*c_double)() + self.lib.lammps_gather_concat(self.lmp,name,type,count,data) + else: + return None return data def gather_subset(self,name,type,count,ndata,ids): if name: name = name.encode() - if type == 0: - data = ((count*ndata)*c_int)() - self.lib.lammps_gather_subset(self.lmp,name,type,count,ndata,ids,data) - elif type == 1: - data = ((count*ndata)*c_double)() - self.lib.lammps_gather_subset(self.lmp,name,type,count,ndata,ids,data) - else: return None + with ExceptionCheck(self): + if type == 0: + data = ((count*ndata)*c_int)() + self.lib.lammps_gather_subset(self.lmp,name,type,count,ndata,ids,data) + elif type == 1: + data = ((count*ndata)*c_double)() + self.lib.lammps_gather_subset(self.lmp,name,type,count,ndata,ids,data) + else: + return None return data # scatter vector of atom/compute/fix properties across procs @@ -1187,11 +1228,13 @@ class lammps(object): def scatter(self,name,type,count,data): if name: name = name.encode() - self.lib.lammps_scatter(self.lmp,name,type,count,data) + with ExceptionCheck(self): + self.lib.lammps_scatter(self.lmp,name,type,count,data) def scatter_subset(self,name,type,count,ndata,ids,data): if name: name = name.encode() - self.lib.lammps_scatter_subset(self.lmp,name,type,count,ndata,ids,data) + with ExceptionCheck(self): + self.lib.lammps_scatter_subset(self.lmp,name,type,count,ndata,ids,data) # ------------------------------------------------------------------------- @@ -1328,7 +1371,8 @@ class lammps(object): POINTER(c_int*n), POINTER(c_double*three_n), POINTER(c_double*three_n), POINTER(self.c_imageint*n), c_int] - return self.lib.lammps_create_atoms(self.lmp, n, id_lmp, type_lmp, x_lmp, v_lmp, img_lmp, se_lmp) + with ExceptionCheck(self): + return self.lib.lammps_create_atoms(self.lmp, n, id_lmp, type_lmp, x_lmp, v_lmp, img_lmp, se_lmp) # ------------------------------------------------------------------------- @@ -1538,10 +1582,12 @@ class lammps(object): if category not in self._available_styles: self._available_styles[category] = [] - nstyles = self.lib.lammps_style_count(self.lmp, category.encode()) + with ExceptionCheck(self): + nstyles = self.lib.lammps_style_count(self.lmp, category.encode()) sb = create_string_buffer(100) for idx in range(nstyles): - self.lib.lammps_style_name(self.lmp, category.encode(), idx, sb, 100) + with ExceptionCheck(self): + self.lib.lammps_style_name(self.lmp, category.encode(), idx, sb, 100) self._available_styles[category].append(sb.value.decode()) return self._available_styles[category] @@ -1607,7 +1653,8 @@ class lammps(object): cCaller = caller self.callback[fix_name] = { 'function': cFunc, 'caller': caller } - self.lib.lammps_set_fix_external_callback(self.lmp, fix_name.encode(), cFunc, cCaller) + with ExceptionCheck(self): + self.lib.lammps_set_fix_external_callback(self.lmp, fix_name.encode(), cFunc, cCaller) # ------------------------------------------------------------------------- From 4c0efceb1edfc9fe8845b0fda6629aae6bdb759c Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 18 Mar 2021 14:26:52 -0400 Subject: [PATCH 084/257] Remove invalid thermo accesses --- unittest/python/python-commands.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index 4c80e8d227..c82e2fdb26 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -240,17 +240,9 @@ create_atoms 1 single & state = { "step": 0, - "elapsed" : 0.0, - "elaplong": 0, "dt" : 0.005, "time" : 0.0, "atoms" : 2.0, - "temp" : 0, - "press" : 0, - "pe" : 0.0, - "ke" : 0.0, - "etotal" : 0.0, - "enthalpy" : 0.0, "vol" : 8.0, "lx" : 2.0, "ly" : 2.0, From 692802921dfe434abf0d301a7291b9512f46e157 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 18 Mar 2021 14:28:47 -0400 Subject: [PATCH 085/257] Add SYCL output to info command --- src/info.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/info.cpp b/src/info.cpp index fadf87292a..98ad5a3097 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -337,6 +337,7 @@ void Info::command(int narg, char **arg) mesg = "KOKKOS package API:"; if (has_accelerator_feature("KOKKOS","api","cuda")) mesg += " CUDA"; if (has_accelerator_feature("KOKKOS","api","hip")) mesg += " HIP"; + if (has_accelerator_feature("KOKKOS","api","sycl")) mesg += " SYCL"; if (has_accelerator_feature("KOKKOS","api","openmp")) mesg += " OpenMP"; if (has_accelerator_feature("KOKKOS","api","serial")) mesg += " Serial"; if (has_accelerator_feature("KOKKOS","api","pthreads")) mesg += " Pthreads"; @@ -1219,6 +1220,9 @@ bool Info::has_accelerator_feature(const std::string &package, #endif #if defined(KOKKOS_ENABLE_HIP) if (setting == "hip") return true; +#endif +#if defined(KOKKOS_ENABLE_SYCL) + if (setting == "sycl") return true; #endif return false; } From 9b29b1594bd35f32a1d728e6c8d32a355c324665 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 14:40:41 -0400 Subject: [PATCH 086/257] add support for bond/angle/dihedral/improper plugins --- examples/plugins/CMakeLists.txt | 8 +- examples/plugins/Makefile | 28 +--- examples/plugins/Makefile.common | 36 ++++ examples/plugins/Makefile.macos | 30 +--- examples/plugins/Makefile.serial | 28 +--- examples/plugins/angle_zero2.cpp | 152 +++++++++++++++++ examples/plugins/angle_zero2.h | 57 +++++++ examples/plugins/bond_zero2.cpp | 161 ++++++++++++++++++ examples/plugins/bond_zero2.h | 58 +++++++ examples/plugins/dihedral_zero2.cpp | 121 ++++++++++++++ examples/plugins/dihedral_zero2.h | 57 +++++++ examples/plugins/improper_zero2.cpp | 122 ++++++++++++++ examples/plugins/improper_zero2.h | 53 ++++++ examples/plugins/pair_zero2.cpp | 247 ++++++++++++++++++++++++++++ examples/plugins/pair_zero2.h | 77 +++++++++ examples/plugins/zero2plugin.cpp | 78 +++++++++ src/PLUGIN/plugin.cpp | 94 ++++++++++- 17 files changed, 1323 insertions(+), 84 deletions(-) create mode 100644 examples/plugins/Makefile.common create mode 100644 examples/plugins/angle_zero2.cpp create mode 100644 examples/plugins/angle_zero2.h create mode 100644 examples/plugins/bond_zero2.cpp create mode 100644 examples/plugins/bond_zero2.h create mode 100644 examples/plugins/dihedral_zero2.cpp create mode 100644 examples/plugins/dihedral_zero2.h create mode 100644 examples/plugins/improper_zero2.cpp create mode 100644 examples/plugins/improper_zero2.h create mode 100644 examples/plugins/pair_zero2.cpp create mode 100644 examples/plugins/pair_zero2.h create mode 100644 examples/plugins/zero2plugin.cpp diff --git a/examples/plugins/CMakeLists.txt b/examples/plugins/CMakeLists.txt index 74a1cd4e3b..6e29676530 100644 --- a/examples/plugins/CMakeLists.txt +++ b/examples/plugins/CMakeLists.txt @@ -53,12 +53,16 @@ target_link_libraries(nve2plugin PRIVATE lammps) add_library(helloplugin MODULE helloplugin.cpp) target_link_libraries(helloplugin PRIVATE lammps) -set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES +add_library(zero2plugin MODULE zero2plugin.cpp pair_zero2.cpp bond_zero2.cpp + angle_zero2.cpp dihedral_zero2.cpp improper_zero2.cpp) +target_link_libraries(zero2plugin PRIVATE lammps) + +set_target_properties(morse2plugin nve2plugin helloplugin zero2plugin PROPERTIES PREFIX "" LINK_FLAGS "-rdynamic") # MacOS seems to need this if(CMAKE_SYSTEM_NAME STREQUAL Darwin) - set_target_properties(morse2plugin nve2plugin helloplugin PROPERTIES + set_target_properties(morse2plugin nve2plugin helloplugin zero2plugin PROPERTIES LINK_FLAGS "-Wl,-undefined,dynamic_lookup") endif() diff --git a/examples/plugins/Makefile b/examples/plugins/Makefile index dbb0023991..f4d8b41086 100644 --- a/examples/plugins/Makefile +++ b/examples/plugins/Makefile @@ -1,30 +1,6 @@ CXX=mpicxx CXXFLAGS=-I../../src -Wall -Wextra -O3 -fPIC -I../../src/USER-OMP -fopenmp LD=$(CXX) -shared -rdynamic -fopenmp +DSOEXT=.so -default: morse2plugin.so nve2plugin.so helloplugin.so - -helloplugin.so: helloplugin.o - $(LD) -o $@ $^ - -morse2plugin.so: morse2plugin.o pair_morse2.o pair_morse2_omp.o - $(LD) -o $@ $^ - -nve2plugin.so: nve2plugin.o fix_nve2.o - $(LD) -o $@ $^ - -.cpp.o: - $(CXX) -o $@ $(CXXFLAGS) -c $< - -helloplugin.o: helloplugin.cpp - -pair_morse2.o: pair_morse2.cpp pair_morse2.h -pair_morse2_omp.o: pair_morse2_omp.cpp pair_morse2_omp.h pair_morse2.h -morse2plugin.o: morse2plugin.cpp pair_morse2.h pair_morse2_omp.h - -fix_nve2.o: fix_nve2.cpp fix_nve2.h -nve2plugin.o: nve2plugin.cpp fix_nve2.h - -clean: - rm -rf *~ *.so *.dylib *.o log.lammps CMakeCache.txt CMakeFiles - +include Makefile.common diff --git a/examples/plugins/Makefile.common b/examples/plugins/Makefile.common new file mode 100644 index 0000000000..e78fa13feb --- /dev/null +++ b/examples/plugins/Makefile.common @@ -0,0 +1,36 @@ +default: morse2plugin$(DSOEXT) nve2plugin$(DSOEXT) helloplugin$(DSOEXT) zero2plugin$(DSOEXT) + +helloplugin$(DSOEXT): helloplugin.o + $(LD) -o $@ $^ + +morse2plugin$(DSOEXT): morse2plugin.o pair_morse2.o pair_morse2_omp.o + $(LD) -o $@ $^ + +nve2plugin$(DSOEXT): nve2plugin.o fix_nve2.o + $(LD) -o $@ $^ + +zero2plugin$(DSOEXT): zero2plugin.o pair_zero2.o bond_zero2.o angle_zero2.o dihedral_zero2.o improper_zero2.o + $(LD) -o $@ $^ + +.cpp.o: + $(CXX) -o $@ $(CXXFLAGS) -c $< + +helloplugin.o: helloplugin.cpp + +pair_morse2.o: pair_morse2.cpp pair_morse2.h +pair_morse2_omp.o: pair_morse2_omp.cpp pair_morse2_omp.h pair_morse2.h +morse2plugin.o: morse2plugin.cpp pair_morse2.h pair_morse2_omp.h + +fix_nve2.o: fix_nve2.cpp fix_nve2.h +nve2plugin.o: nve2plugin.cpp fix_nve2.h + +pair_zero2.o: pair_zero2.cpp pair_zero2.h +bond_zero2.o: bond_zero2.cpp bond_zero2.h +angle_zero2.o: angle_zero2.cpp angle_zero2.h +dihedral_zero2.o: dihedral_zero2.cpp dihedral_zero2.h +improper_zero2.o: improper_zero2.cpp improper_zero2.h +zero2plugin.o: zero2plugin.cpp pair_zero2.h bond_zero2.h angle_zero2.h dihedral_zero2.h + +clean: + rm -rf *~ *.so *.dylib *.o log.lammps CMakeCache.txt CMakeFiles + diff --git a/examples/plugins/Makefile.macos b/examples/plugins/Makefile.macos index 2490418a09..a7c20ff90f 100644 --- a/examples/plugins/Makefile.macos +++ b/examples/plugins/Makefile.macos @@ -1,30 +1,6 @@ CXX=mpicxx -CXXFLAGS=-I../../src -Wall -Wextra -O3 -fPIC -I../../src/USER-OMP +CXXFLAGS=-I../../src -Wall -Wextra -O3 -fPIC -I../../src/USER-OMP LD=$(CXX) -bundle -rdynamic -Wl,-undefined,dynamic_lookup +DSOEXT=.dylib -default: morse2plugin.dylib nve2plugin.dylib helloplugin.dylib - -helloplugin.dylib: helloplugin.o - $(LD) -o $@ $^ - -morse2plugin.dylib: morse2plugin.o pair_morse2.o pair_morse2_omp.o - $(LD) -o $@ $^ - -nve2plugin.dylib: nve2plugin.o fix_nve2.o - $(LD) -o $@ $^ - -.cpp.o: - $(CXX) -o $@ $(CXXFLAGS) -c $< - -helloplugin.o: helloplugin.cpp - -pair_morse2.o: pair_morse2.cpp pair_morse2.h -pair_morse2_omp.o: pair_morse2_omp.cpp pair_morse2_omp.h pair_morse2.h -morse2plugin.o: morse2plugin.cpp pair_morse2.h pair_morse2_omp.h - -fix_nve2.o: fix_nve2.cpp fix_nve2.h -nve2plugin.o: nve2plugin.cpp fix_nve2.h - -clean: - rm -rf *~ *.dylib *.dylib *.o log.lammps CMakeCache.txt CMakeFiles - +include Makefile.common diff --git a/examples/plugins/Makefile.serial b/examples/plugins/Makefile.serial index feb58bd9b3..ecc7631a05 100644 --- a/examples/plugins/Makefile.serial +++ b/examples/plugins/Makefile.serial @@ -1,30 +1,6 @@ CXX=g++ CXXFLAGS=-I../../src -I../../src/STUBS -Wall -Wextra -O3 -fPIC -I../../src/USER-OMP -fopenmp LD=$(CXX) -shared -rdynamic -fopenmp +DSOEXT=.so -default: morse2plugin.so nve2plugin.so helloplugin.so - -helloplugin.so: helloplugin.o - $(LD) -o $@ $^ - -morse2plugin.so: morse2plugin.o pair_morse2.o pair_morse2_omp.o - $(LD) -o $@ $^ - -nve2plugin.so: nve2plugin.o fix_nve2.o - $(LD) -o $@ $^ - -.cpp.o: - $(CXX) -o $@ $(CXXFLAGS) -c $< - -helloplugin.o: helloplugin.cpp - -pair_morse2.o: pair_morse2.cpp pair_morse2.h -pair_morse2_omp.o: pair_morse2_omp.cpp pair_morse2_omp.h pair_morse2.h -morse2plugin.o: morse2plugin.cpp pair_morse2.h pair_morse2_omp.h - -fix_nve2.o: fix_nve2.cpp fix_nve2.h -nve2plugin.o: nve2plugin.cpp fix_nve2.h - -clean: - rm -rf *~ *.so *.dylib *.o log.lammps CMakeCache.txt CMakeFiles - +include Makefile.common diff --git a/examples/plugins/angle_zero2.cpp b/examples/plugins/angle_zero2.cpp new file mode 100644 index 0000000000..c0d01f14a5 --- /dev/null +++ b/examples/plugins/angle_zero2.cpp @@ -0,0 +1,152 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Carsten Svaneborg (SDU) +------------------------------------------------------------------------- */ + +#include "angle_zero2.h" + +#include "atom.h" +#include "comm.h" +#include "math_const.h" +#include "memory.h" +#include "error.h" + +#include + +using namespace LAMMPS_NS; +using namespace MathConst; + +/* ---------------------------------------------------------------------- */ + +AngleZero2::AngleZero2(LAMMPS *lmp) : Angle(lmp), coeffflag(1) {} + +/* ---------------------------------------------------------------------- */ + +AngleZero2::~AngleZero2() +{ + if (allocated && !copymode) { + memory->destroy(setflag); + memory->destroy(theta0); + } +} + +/* ---------------------------------------------------------------------- */ + +void AngleZero2::compute(int eflag, int vflag) +{ + ev_init(eflag,vflag); +} + +/* ---------------------------------------------------------------------- */ + +void AngleZero2::settings(int narg, char **arg) +{ + if ((narg != 0) && (narg != 1)) + error->all(FLERR,"Illegal angle_style command"); + + if (narg == 1) { + if (strcmp("nocoeff",arg[0]) == 0) coeffflag=0; + else error->all(FLERR,"Illegal angle_style command"); + } +} + +/* ---------------------------------------------------------------------- */ + +void AngleZero2::allocate() +{ + allocated = 1; + int n = atom->nangletypes; + + memory->create(theta0,n+1,"angle:theta0"); + memory->create(setflag,n+1,"angle:setflag"); + for (int i = 1; i <= n; i++) setflag[i] = 0; +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more types +------------------------------------------------------------------------- */ + +void AngleZero2::coeff(int narg, char **arg) +{ + if ((narg < 1) || (coeffflag && narg > 2)) + error->all(FLERR,"Incorrect args for angle coefficients"); + + if (!allocated) allocate(); + + int ilo,ihi; + utils::bounds(FLERR,arg[0],1,atom->nangletypes,ilo,ihi,error); + + double theta0_one = 0.0; + if (coeffflag && (narg == 2)) + theta0_one = utils::numeric(FLERR,arg[1],false,lmp); + + // convert theta0 from degrees to radians + + int count = 0; + for (int i = ilo; i <= ihi; i++) { + setflag[i] = 1; + theta0[i] = theta0_one/180.0 * MY_PI; + count++; + } + + if (count == 0) error->all(FLERR,"Incorrect args for angle coefficients"); +} + +/* ---------------------------------------------------------------------- */ + +double AngleZero2::equilibrium_angle(int i) +{ + return theta0[i]; +} + +/* ---------------------------------------------------------------------- + proc 0 writes out coeffs to restart file +------------------------------------------------------------------------- */ + +void AngleZero2::write_restart(FILE *fp) { + fwrite(&theta0[1],sizeof(double),atom->nangletypes,fp); +} + +/* ---------------------------------------------------------------------- + proc 0 reads coeffs from restart file, bcasts them +------------------------------------------------------------------------- */ + +void AngleZero2::read_restart(FILE *fp) +{ + allocate(); + + if (comm->me == 0) { + utils::sfread(FLERR,&theta0[1],sizeof(double),atom->nangletypes,fp,nullptr,error); + } + MPI_Bcast(&theta0[1],atom->nangletypes,MPI_DOUBLE,0,world); + + for (int i = 1; i <= atom->nangletypes; i++) setflag[i] = 1; +} +/* ---------------------------------------------------------------------- + proc 0 writes to data file +------------------------------------------------------------------------- */ + +void AngleZero2::write_data(FILE *fp) +{ + for (int i = 1; i <= atom->nangletypes; i++) + fprintf(fp,"%d %g\n",i,theta0[i]/MY_PI*180.0); +} + +/* ---------------------------------------------------------------------- */ + +double AngleZero2::single(int /*type*/, int /*i1*/, int /*i2*/, int /*i3*/) +{ + return 0.0; +} diff --git a/examples/plugins/angle_zero2.h b/examples/plugins/angle_zero2.h new file mode 100644 index 0000000000..15a16b197f --- /dev/null +++ b/examples/plugins/angle_zero2.h @@ -0,0 +1,57 @@ +/* -*- 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_ANGLE_ZERO2_H +#define LMP_ANGLE_ZERO2_H + +#include "angle.h" + +namespace LAMMPS_NS { + +class AngleZero2 : public Angle { + public: + AngleZero2(class LAMMPS *); + virtual ~AngleZero2(); + virtual void compute(int, int); + virtual void coeff(int, char **); + virtual void settings(int, char **); + + double equilibrium_angle(int); + void write_restart(FILE *); + void read_restart(FILE *); + void write_data(FILE *); + + double single(int, int, int, int); + + protected: + double *theta0; + int coeffflag; + + void allocate(); +}; + +} + +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +UNDOCUMENTED + +E: Incorrect args for angle coefficients + +Self-explanatory. Check the input script or data file. + +*/ diff --git a/examples/plugins/bond_zero2.cpp b/examples/plugins/bond_zero2.cpp new file mode 100644 index 0000000000..b015a60ed3 --- /dev/null +++ b/examples/plugins/bond_zero2.cpp @@ -0,0 +1,161 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Carsten Svaneborg (SDU) +------------------------------------------------------------------------- */ + +#include "bond_zero2.h" + +#include "atom.h" +#include "comm.h" +#include "error.h" +#include "memory.h" + +#include + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +BondZero2::BondZero2(LAMMPS *lmp) : Bond(lmp), coeffflag(1) {} + +/* ---------------------------------------------------------------------- */ + +BondZero2::~BondZero2() +{ + if (allocated && !copymode) { + memory->destroy(setflag); + memory->destroy(r0); + } +} + +/* ---------------------------------------------------------------------- */ + +void BondZero2::compute(int eflag, int vflag) +{ + ev_init(eflag,vflag); +} + +/* ---------------------------------------------------------------------- */ + +void BondZero2::settings(int narg, char **arg) +{ + if ((narg != 0) && (narg != 1)) + error->all(FLERR,"Illegal bond_style command"); + + if (narg == 1) { + if (strcmp("nocoeff",arg[0]) == 0) coeffflag=0; + else error->all(FLERR,"Illegal bond_style command"); + } +} + +/* ---------------------------------------------------------------------- */ + +void BondZero2::allocate() +{ + allocated = 1; + int n = atom->nbondtypes; + + memory->create(r0,n+1,"bond:r0"); + memory->create(setflag,n+1,"bond:setflag"); + for (int i = 1; i <= n; i++) setflag[i] = 0; +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more types +------------------------------------------------------------------------- */ + +void BondZero2::coeff(int narg, char **arg) +{ + if ((narg < 1) || (coeffflag && narg > 2)) + error->all(FLERR,"Incorrect args for bond coefficients"); + + if (!allocated) allocate(); + + int ilo,ihi; + utils::bounds(FLERR,arg[0],1,atom->nbondtypes,ilo,ihi,error); + + double r0_one = 0.0; + if (coeffflag && (narg == 2)) + r0_one = utils::numeric(FLERR,arg[1],false,lmp); + + int count = 0; + for (int i = ilo; i <= ihi; i++) { + setflag[i] = 1; + r0[i] = r0_one; + count++; + } + + if (count == 0) error->all(FLERR,"Incorrect args for bond coefficients"); +} + +/* ---------------------------------------------------------------------- + return an equilbrium bond length +------------------------------------------------------------------------- */ + +double BondZero2::equilibrium_distance(int i) +{ + return r0[i]; +} + +/* ---------------------------------------------------------------------- + proc 0 writes out coeffs to restart file +------------------------------------------------------------------------- */ + +void BondZero2::write_restart(FILE *fp) { + fwrite(&r0[1],sizeof(double),atom->nbondtypes,fp); +} + +/* ---------------------------------------------------------------------- + proc 0 reads coeffs from restart file, bcasts them +------------------------------------------------------------------------- */ + +void BondZero2::read_restart(FILE *fp) +{ + allocate(); + + if (comm->me == 0) { + utils::sfread(FLERR,&r0[1],sizeof(double),atom->nbondtypes,fp,nullptr,error); + } + MPI_Bcast(&r0[1],atom->nbondtypes,MPI_DOUBLE,0,world); + + for (int i = 1; i <= atom->nbondtypes; i++) setflag[i] = 1; +} + +/* ---------------------------------------------------------------------- + proc 0 writes to data file +------------------------------------------------------------------------- */ + +void BondZero2::write_data(FILE *fp) +{ + for (int i = 1; i <= atom->nbondtypes; i++) + fprintf(fp,"%d %g\n",i,r0[i]); +} + +/* ---------------------------------------------------------------------- */ + +double BondZero2::single(int /*type*/, double /*rsq*/, int /*i*/, int /*j*/, + double & /*fforce*/) +{ + return 0.0; +} + +/* ---------------------------------------------------------------------- */ + +void *BondZero2::extract(const char *str, int &dim) +{ + dim = 1; + if (strcmp(str,"r0")==0) return (void*) r0; + return nullptr; +} diff --git a/examples/plugins/bond_zero2.h b/examples/plugins/bond_zero2.h new file mode 100644 index 0000000000..37609561a7 --- /dev/null +++ b/examples/plugins/bond_zero2.h @@ -0,0 +1,58 @@ +/* -*- 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_BOND_ZERO2_H +#define LMP_BOND_ZERO2_H + +#include "bond.h" + +namespace LAMMPS_NS { + +class BondZero2 : public Bond { + public: + BondZero2(class LAMMPS *); + virtual ~BondZero2(); + virtual void compute(int, int); + virtual void settings(int, char **); + + void coeff(int, char **); + double equilibrium_distance(int); + void write_restart(FILE *); + void read_restart(FILE *); + void write_data(FILE *); + + double single(int, double, int, int, double &); + virtual void *extract(const char *, int &); + + protected: + double *r0; + int coeffflag; + + virtual void allocate(); +}; + +} + +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +UNDOCUMENTED + +E: Incorrect args for bond coefficients + +Self-explanatory. Check the input script or data file. + +*/ diff --git a/examples/plugins/dihedral_zero2.cpp b/examples/plugins/dihedral_zero2.cpp new file mode 100644 index 0000000000..00d9817c96 --- /dev/null +++ b/examples/plugins/dihedral_zero2.cpp @@ -0,0 +1,121 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Carsten Svaneborg (SDU) +------------------------------------------------------------------------- */ + +#include "dihedral_zero2.h" + +#include "atom.h" +#include "error.h" +#include "memory.h" + +#include + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +DihedralZero2::DihedralZero2(LAMMPS *lmp) : Dihedral(lmp), coeffflag(1) +{ + writedata = 1; +} + +/* ---------------------------------------------------------------------- */ + +DihedralZero2::~DihedralZero2() +{ + if (allocated && !copymode) { + memory->destroy(setflag); + } +} + +/* ---------------------------------------------------------------------- */ + +void DihedralZero2::compute(int eflag, int vflag) +{ + ev_init(eflag,vflag); +} + +/* ---------------------------------------------------------------------- */ + +void DihedralZero2::settings(int narg, char **arg) +{ + if ((narg != 0) && (narg != 1)) + error->all(FLERR,"Illegal dihedral_style command"); + + if (narg == 1) { + if (strcmp("nocoeff",arg[0]) == 0) coeffflag=0; + else error->all(FLERR,"Illegal dihedral_style command"); + } +} + +/* ---------------------------------------------------------------------- */ + +void DihedralZero2::allocate() +{ + allocated = 1; + int n = atom->ndihedraltypes; + + memory->create(setflag,n+1,"dihedral:setflag"); + for (int i = 1; i <= n; i++) setflag[i] = 0; +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more types +------------------------------------------------------------------------- */ + +void DihedralZero2::coeff(int narg, char **arg) +{ + if ((narg < 1) || (coeffflag && narg > 1)) + error->all(FLERR,"Incorrect args for dihedral coefficients"); + + if (!allocated) allocate(); + + int ilo,ihi; + utils::bounds(FLERR,arg[0],1,atom->ndihedraltypes,ilo,ihi,error); + + int count = 0; + for (int i = ilo; i <= ihi; i++) { + setflag[i] = 1; + count++; + } + + if (count == 0) error->all(FLERR,"Incorrect args for dihedral coefficients"); +} + +/* ---------------------------------------------------------------------- + proc 0 writes out coeffs to restart file +------------------------------------------------------------------------- */ + +void DihedralZero2::write_restart(FILE * /*fp*/) {} + +/* ---------------------------------------------------------------------- + proc 0 reads coeffs from restart file, bcasts them +------------------------------------------------------------------------- */ + +void DihedralZero2::read_restart(FILE * /*fp*/) +{ + allocate(); + for (int i = 1; i <= atom->ndihedraltypes; i++) setflag[i] = 1; +} + +/* ---------------------------------------------------------------------- + proc 0 writes to data file +------------------------------------------------------------------------- */ + +void DihedralZero2::write_data(FILE *fp) { + for (int i = 1; i <= atom->ndihedraltypes; i++) + fprintf(fp,"%d\n",i); +} diff --git a/examples/plugins/dihedral_zero2.h b/examples/plugins/dihedral_zero2.h new file mode 100644 index 0000000000..510e384340 --- /dev/null +++ b/examples/plugins/dihedral_zero2.h @@ -0,0 +1,57 @@ +/* -*- 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. + + Identical to dihedral harmonic, except if all k's are zero the + force loop is skipped. + +------------------------------------------------------------------------- */ + +#ifndef LMP_DIHEDRAL_ZERO2_H +#define LMP_DIHEDRAL_ZERO2_H + +#include "dihedral.h" + +namespace LAMMPS_NS { + +class DihedralZero2 : public Dihedral { + public: + DihedralZero2(class LAMMPS *); + virtual ~DihedralZero2(); + virtual void compute(int, int); + virtual void coeff(int, char **); + virtual void settings(int, char **); + + void write_restart(FILE *); + void read_restart(FILE *); + void write_data(FILE *); + + protected: + int coeffflag; + + virtual void allocate(); +}; + +} + +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +UNDOCUMENTED + +E: Incorrect args for dihedral coefficients + +UNDOCUMENTED + +*/ diff --git a/examples/plugins/improper_zero2.cpp b/examples/plugins/improper_zero2.cpp new file mode 100644 index 0000000000..2370b32a02 --- /dev/null +++ b/examples/plugins/improper_zero2.cpp @@ -0,0 +1,122 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Carsten Svaneborg (SDU) +------------------------------------------------------------------------- */ + +#include "improper_zero2.h" + +#include "atom.h" +#include "error.h" +#include "memory.h" + +#include + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +ImproperZero2::ImproperZero2(LAMMPS *lmp) : Improper(lmp), coeffflag(1) +{ + writedata = 1; +} + +/* ---------------------------------------------------------------------- */ + +ImproperZero2::~ImproperZero2() +{ + if (allocated && !copymode) { + memory->destroy(setflag); + } +} + +/* ---------------------------------------------------------------------- */ + +void ImproperZero2::compute(int eflag, int vflag) +{ + ev_init(eflag,vflag); +} + +/* ---------------------------------------------------------------------- */ + +void ImproperZero2::settings(int narg, char **arg) +{ + if ((narg != 0) && (narg != 1)) + error->all(FLERR,"Illegal improper_style command"); + + if (narg == 1) { + if (strcmp("nocoeff",arg[0]) == 0) coeffflag=0; + else error->all(FLERR,"Illegal improper_style command"); + } +} + +/* ---------------------------------------------------------------------- */ + +void ImproperZero2::allocate() +{ + allocated = 1; + int n = atom->nimpropertypes; + + memory->create(setflag,n+1,"improper:setflag"); + for (int i = 1; i <= n; i++) setflag[i] = 0; +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more types +------------------------------------------------------------------------- */ + +void ImproperZero2::coeff(int narg, char **arg) +{ + if ((narg < 1) || (coeffflag && narg > 1)) + error->all(FLERR,"Incorrect args for improper coefficients"); + + if (!allocated) allocate(); + + int ilo,ihi; + utils::bounds(FLERR,arg[0],1,atom->nimpropertypes,ilo,ihi,error); + + int count = 0; + for (int i = ilo; i <= ihi; i++) { + setflag[i] = 1; + count++; + } + + if (count == 0) error->all(FLERR,"Incorrect args for improper coefficients"); +} + +/* ---------------------------------------------------------------------- + proc 0 writes out coeffs to restart file +------------------------------------------------------------------------- */ + +void ImproperZero2::write_restart(FILE * /*fp*/) {} + +/* ---------------------------------------------------------------------- + proc 0 reads coeffs from restart file, bcasts them +------------------------------------------------------------------------- */ + +void ImproperZero2::read_restart(FILE * /*fp*/) +{ + allocate(); + for (int i = 1; i <= atom->nimpropertypes; i++) setflag[i] = 1; +} + +/* ---------------------------------------------------------------------- + proc 0 writes to data file +------------------------------------------------------------------------- */ + +void ImproperZero2::write_data(FILE *fp) { + for (int i = 1; i <= atom->nimpropertypes; i++) + fprintf(fp,"%d\n",i); +} + diff --git a/examples/plugins/improper_zero2.h b/examples/plugins/improper_zero2.h new file mode 100644 index 0000000000..64dd94920a --- /dev/null +++ b/examples/plugins/improper_zero2.h @@ -0,0 +1,53 @@ +/* -*- 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_IMPROPER_ZERO2_H +#define LMP_IMPROPER_ZERO2_H + +#include "improper.h" + +namespace LAMMPS_NS { + +class ImproperZero2 : public Improper { + public: + ImproperZero2(class LAMMPS *); + virtual ~ImproperZero2(); + virtual void compute(int, int); + virtual void coeff(int, char **); + virtual void settings(int, char **); + + void write_restart(FILE *); + void read_restart(FILE *); + void write_data(FILE *); + + protected: + int coeffflag; + + virtual void allocate(); +}; + +} + +#endif + +/* ERROR/WARNING messages: + +E: Illegal ... command + +UNDOCUMENTED + +E: Incorrect args for improper coefficients + +Self-explanatory. Check the input script or data file. + +*/ diff --git a/examples/plugins/pair_zero2.cpp b/examples/plugins/pair_zero2.cpp new file mode 100644 index 0000000000..d8e23c902d --- /dev/null +++ b/examples/plugins/pair_zero2.cpp @@ -0,0 +1,247 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + Contributing author: Carsten Svaneborg (SDU) +------------------------------------------------------------------------- */ + +#include "pair_zero2.h" + +#include "atom.h" +#include "comm.h" +#include "memory.h" +#include "error.h" + +#include + +using namespace LAMMPS_NS; + +/* ---------------------------------------------------------------------- */ + +PairZero2::PairZero2(LAMMPS *lmp) : Pair(lmp) { + coeffflag=1; + writedata=1; + single_enable=1; + respa_enable=1; +} + +/* ---------------------------------------------------------------------- */ + +PairZero2::~PairZero2() +{ + if (allocated) { + memory->destroy(setflag); + memory->destroy(cutsq); + memory->destroy(cut); + } +} + +/* ---------------------------------------------------------------------- */ + +void PairZero2::compute(int eflag, int vflag) +{ + ev_init(eflag,vflag); + if (vflag_fdotr) virial_fdotr_compute(); +} + +/* ---------------------------------------------------------------------- */ + +void PairZero2::compute_outer(int eflag, int vflag) +{ + ev_init(eflag,vflag); +} + +/* ---------------------------------------------------------------------- + allocate all arrays +------------------------------------------------------------------------- */ + +void PairZero2::allocate() +{ + allocated = 1; + int n = atom->ntypes; + + memory->create(setflag,n+1,n+1,"pair:setflag"); + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j++) + setflag[i][j] = 0; + + memory->create(cutsq,n+1,n+1,"pair:cutsq"); + memory->create(cut,n+1,n+1,"pair:cut"); +} + +/* ---------------------------------------------------------------------- + global settings +------------------------------------------------------------------------- */ + +void PairZero2::settings(int narg, char **arg) +{ + if ((narg != 1) && (narg != 2)) + error->all(FLERR,"Illegal pair_style command"); + + cut_global = utils::numeric(FLERR,arg[0],false,lmp); + if (narg == 2) { + if (strcmp("nocoeff",arg[1]) == 0) coeffflag=0; + else error->all(FLERR,"Illegal pair_style command"); + } + + // reset cutoffs that have been explicitly set + + if (allocated) { + int i,j; + for (i = 1; i <= atom->ntypes; i++) + for (j = i+1; j <= atom->ntypes; j++) + cut[i][j] = cut_global; + } +} + +/* ---------------------------------------------------------------------- + set coeffs for one or more type pairs +------------------------------------------------------------------------- */ + +void PairZero2::coeff(int narg, char **arg) +{ + if ((narg < 2) || (coeffflag && narg > 3)) + error->all(FLERR,"Incorrect args for pair coefficients"); + + if (!allocated) allocate(); + + int ilo,ihi,jlo,jhi; + utils::bounds(FLERR,arg[0],1,atom->ntypes,ilo,ihi,error); + utils::bounds(FLERR,arg[1],1,atom->ntypes,jlo,jhi,error); + + double cut_one = cut_global; + if (coeffflag && (narg == 3)) cut_one = utils::numeric(FLERR,arg[2],false,lmp); + + int count = 0; + for (int i = ilo; i <= ihi; i++) { + for (int j = MAX(jlo,i); j <= jhi; j++) { + cut[i][j] = cut_one; + setflag[i][j] = 1; + count++; + } + } + + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); +} + +/* ---------------------------------------------------------------------- + init for one type pair i,j and corresponding j,i +------------------------------------------------------------------------- */ + +double PairZero2::init_one(int i, int j) +{ + if (setflag[i][j] == 0) { + cut[i][j] = mix_distance(cut[i][i],cut[j][j]); + } + + return cut[i][j]; +} + +/* ---------------------------------------------------------------------- + proc 0 writes to restart file +------------------------------------------------------------------------- */ + +void PairZero2::write_restart(FILE *fp) +{ + write_restart_settings(fp); + + int i,j; + for (i = 1; i <= atom->ntypes; i++) + for (j = i; j <= atom->ntypes; j++) { + fwrite(&setflag[i][j],sizeof(int),1,fp); + if (setflag[i][j]) { + fwrite(&cut[i][j],sizeof(double),1,fp); + } + } +} + +/* ---------------------------------------------------------------------- + proc 0 reads from restart file, bcasts +------------------------------------------------------------------------- */ + +void PairZero2::read_restart(FILE *fp) +{ + read_restart_settings(fp); + allocate(); + + int i,j; + int me = comm->me; + for (i = 1; i <= atom->ntypes; i++) + for (j = i; j <= atom->ntypes; j++) { + if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,nullptr,error); + MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world); + if (setflag[i][j]) { + if (me == 0) { + utils::sfread(FLERR,&cut[i][j],sizeof(double),1,fp,nullptr,error); + } + MPI_Bcast(&cut[i][j],1,MPI_DOUBLE,0,world); + } + } +} + +/* ---------------------------------------------------------------------- + proc 0 writes to restart file +------------------------------------------------------------------------- */ + +void PairZero2::write_restart_settings(FILE *fp) +{ + fwrite(&cut_global,sizeof(double),1,fp); + fwrite(&coeffflag,sizeof(int),1,fp); +} + +/* ---------------------------------------------------------------------- + proc 0 reads from restart file, bcasts +------------------------------------------------------------------------- */ + +void PairZero2::read_restart_settings(FILE *fp) +{ + int me = comm->me; + if (me == 0) { + utils::sfread(FLERR,&cut_global,sizeof(double),1,fp,nullptr,error); + utils::sfread(FLERR,&coeffflag,sizeof(int),1,fp,nullptr,error); + } + MPI_Bcast(&cut_global,1,MPI_DOUBLE,0,world); + MPI_Bcast(&coeffflag,1,MPI_INT,0,world); +} + +/* ---------------------------------------------------------------------- + proc 0 writes to data file +------------------------------------------------------------------------- */ + +void PairZero2::write_data(FILE *fp) +{ + for (int i = 1; i <= atom->ntypes; i++) + fprintf(fp,"%d\n",i); +} + +/* ---------------------------------------------------------------------- + proc 0 writes all pairs to data file +------------------------------------------------------------------------- */ + +void PairZero2::write_data_all(FILE *fp) +{ + for (int i = 1; i <= atom->ntypes; i++) + for (int j = i; j <= atom->ntypes; j++) + fprintf(fp,"%d %d %g\n",i,j,cut[i][j]); +} + +/* ---------------------------------------------------------------------- */ + +double PairZero2::single(int /*i*/, int /*j*/, int /* itype */, int /* jtype */, + double /* rsq */, double /*factor_coul*/, + double /* factor_lj */, double &fforce) +{ + fforce = 0.0; + return 0.0; +} + diff --git a/examples/plugins/pair_zero2.h b/examples/plugins/pair_zero2.h new file mode 100644 index 0000000000..39aa160913 --- /dev/null +++ b/examples/plugins/pair_zero2.h @@ -0,0 +1,77 @@ +/* -*- 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. + + Pair zero is a dummy pair interaction useful for requiring a + force cutoff distance in the absence of pair-interactions or + with hybrid/overlay if a larger force cutoff distance is required. + + This can be used in conjunction with bond/create to create bonds + that are longer than the cutoff of a given force field, or to + calculate radial distribution functions for models without + pair interactions. + +------------------------------------------------------------------------- */ + +#ifndef LMP_PAIR_ZERO2_H +#define LMP_PAIR_ZERO2_H + +#include "pair.h" + +namespace LAMMPS_NS { + +class PairZero2 : public Pair { + public: + PairZero2(class LAMMPS *); + virtual ~PairZero2(); + virtual void compute(int, int); + virtual void compute_outer(int, int); + void settings(int, char **); + void coeff(int, char **); + double init_one(int, int); + void write_restart(FILE *); + void read_restart(FILE *); + void write_restart_settings(FILE *); + void read_restart_settings(FILE *); + void write_data(FILE *); + void write_data_all(FILE *); + double single(int, int, int, int, double, double, double, double &); + + protected: + double cut_global; + double **cut; + int coeffflag; + + virtual void allocate(); +}; + +} + +#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: Incorrect args for pair coefficients + +Self-explanatory. Check the input script or data file. + +U: Pair cutoff < Respa interior cutoff + +One or more pairwise cutoffs are too short to use with the specified +rRESPA cutoffs. + +*/ diff --git a/examples/plugins/zero2plugin.cpp b/examples/plugins/zero2plugin.cpp new file mode 100644 index 0000000000..f181eae781 --- /dev/null +++ b/examples/plugins/zero2plugin.cpp @@ -0,0 +1,78 @@ + +#include "lammpsplugin.h" +#include "version.h" + +#include + +#include "pair_zero2.h" +#include "bond_zero2.h" +#include "angle_zero2.h" +#include "dihedral_zero2.h" +#include "improper_zero2.h" + +using namespace LAMMPS_NS; + +static Pair *pairzerocreator(LAMMPS *lmp) +{ + return new PairZero2(lmp); +} + +static Bond *bondzerocreator(LAMMPS *lmp) +{ + return new BondZero2(lmp); +} + +static Angle *anglezerocreator(LAMMPS *lmp) +{ + return new AngleZero2(lmp); +} + +static Dihedral *dihedralzerocreator(LAMMPS *lmp) +{ + return new DihedralZero2(lmp); +} + +static Improper *improperzerocreator(LAMMPS *lmp) +{ + return new ImproperZero2(lmp); +} + +extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc) +{ + lammpsplugin_t plugin; + lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc; + + // register zero2 pair style + plugin.version = LAMMPS_VERSION; + plugin.style = "pair"; + plugin.name = "zero2"; + plugin.info = "Zero2 variant pair style v1.0"; + plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)"; + plugin.creator.v1 = (lammpsplugin_factory1 *) &pairzerocreator; + plugin.handle = handle; + (*register_plugin)(&plugin,lmp); + + // register zero2 bond style + plugin.style = "bond"; + plugin.info = "Zero2 variant bond style v1.0"; + plugin.creator.v1 = (lammpsplugin_factory1 *) &bondzerocreator; + (*register_plugin)(&plugin,lmp); + + // register zero2 angle style + plugin.style = "angle"; + plugin.info = "Zero2 variant angle style v1.0"; + plugin.creator.v1 = (lammpsplugin_factory1 *) &anglezerocreator; + (*register_plugin)(&plugin,lmp); + + // register zero2 dihedral style + plugin.style = "dihedral"; + plugin.info = "Zero2 variant dihedral style v1.0"; + plugin.creator.v1 = (lammpsplugin_factory1 *) &dihedralzerocreator; + (*register_plugin)(&plugin,lmp); + + // register zero2 improper style + plugin.style = "improper"; + plugin.info = "Zero2 variant improper style v1.0"; + plugin.creator.v1 = (lammpsplugin_factory1 *) &improperzerocreator; + (*register_plugin)(&plugin,lmp); +} diff --git a/src/PLUGIN/plugin.cpp b/src/PLUGIN/plugin.cpp index 1449d0d90f..91d22b2897 100644 --- a/src/PLUGIN/plugin.cpp +++ b/src/PLUGIN/plugin.cpp @@ -19,7 +19,6 @@ #include "force.h" #include "lammps.h" #include "modify.h" -#include "pair.h" #include #include @@ -179,6 +178,46 @@ namespace LAMMPS_NS } (*pair_map)[plugin->name] = (Force::PairCreator)plugin->creator.v1; + } else if (pstyle == "bond") { + auto bond_map = lmp->force->bond_map; + if (bond_map->find(plugin->name) != bond_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR,fmt::format("Overriding built-in bond " + "style {} from plugin", + plugin->name)); + } + (*bond_map)[plugin->name] = (Force::BondCreator)plugin->creator.v1; + + } else if (pstyle == "angle") { + auto angle_map = lmp->force->angle_map; + if (angle_map->find(plugin->name) != angle_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR,fmt::format("Overriding built-in angle " + "style {} from plugin", + plugin->name)); + } + (*angle_map)[plugin->name] = (Force::AngleCreator)plugin->creator.v1; + + } else if (pstyle == "dihedral") { + auto dihedral_map = lmp->force->dihedral_map; + if (dihedral_map->find(plugin->name) != dihedral_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR,fmt::format("Overriding built-in dihedral " + "style {} from plugin", + plugin->name)); + } + (*dihedral_map)[plugin->name] = (Force::DihedralCreator)plugin->creator.v1; + + } else if (pstyle == "improper") { + auto improper_map = lmp->force->improper_map; + if (improper_map->find(plugin->name) != improper_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR,fmt::format("Overriding built-in improper " + "style {} from plugin", + plugin->name)); + } + (*improper_map)[plugin->name] = (Force::ImproperCreator)plugin->creator.v1; + } else if (pstyle == "fix") { auto fix_map = lmp->modify->fix_map; if (fix_map->find(plugin->name) != fix_map->end()) { @@ -219,8 +258,9 @@ namespace LAMMPS_NS int me = lmp->comm->me; // ignore unload request from unsupported style categories - if ((strcmp(style,"pair") != 0) - && (strcmp(style,"fix") != 0) + if ((strcmp(style,"pair") != 0) && (strcmp(style,"bond") != 0) + && (strcmp(style,"angle") != 0) && (strcmp(style,"dihedral") != 0) + && (strcmp(style,"improper") != 0) && (strcmp(style,"fix") != 0) && (strcmp(style,"command") != 0)) { if (me == 0) utils::logmesg(lmp,fmt::format("Ignoring unload: {} is not a " @@ -269,6 +309,54 @@ namespace LAMMPS_NS } } + } else if (pstyle == "bond") { + + auto found = lmp->force->bond_map->find(name); + if (found != lmp->force->bond_map->end()) + lmp->force->bond_map->erase(found); + + // must delete bond style instance if in use + + if ((lmp->force->bond_style != nullptr) + && (lmp->force->bond_match(name) != nullptr)) + lmp->force->create_bond("none",0); + + } else if (pstyle == "angle") { + + auto found = lmp->force->angle_map->find(name); + if (found != lmp->force->angle_map->end()) + lmp->force->angle_map->erase(found); + + // must delete angle style instance if in use + + if ((lmp->force->angle_style != nullptr) + && (lmp->force->angle_match(name) != nullptr)) + lmp->force->create_angle("none",0); + + } else if (pstyle == "dihedral") { + + auto found = lmp->force->dihedral_map->find(name); + if (found != lmp->force->dihedral_map->end()) + lmp->force->dihedral_map->erase(found); + + // must delete dihedral style instance if in use + + if ((lmp->force->dihedral_style) + && (lmp->force->dihedral_match(name) != nullptr)) + lmp->force->create_dihedral("none",0); + + } else if (pstyle == "improper") { + + auto found = lmp->force->improper_map->find(name); + if (found != lmp->force->improper_map->end()) + lmp->force->improper_map->erase(found); + + // must delete improper style instance if in use + + if ((lmp->force->improper_style != nullptr) + && (lmp->force->improper_match(name) != nullptr)) + lmp->force->create_improper("none",0); + } else if (pstyle == "fix") { auto fix_map = lmp->modify->fix_map; From fbb3bb14af47b7c893ede7cb4dd39f33826946be Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 17:08:49 -0400 Subject: [PATCH 087/257] synchronize interface to managing computes in Modify with that of fixes - add find_compute_by_style() - add delete_compute(int) --- src/modify.cpp | 21 ++++++++++++++++++++- src/modify.h | 11 +++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/modify.cpp b/src/modify.cpp index 2c0fd434d6..9cb90fc36f 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -1326,7 +1326,12 @@ void Modify::delete_compute(const std::string &id) { int icompute = find_compute(id); if (icompute < 0) error->all(FLERR,"Could not find compute ID to delete"); - delete compute[icompute]; + delete_compute(icompute); +} + +void Modify::delete_compute(int icompute) +{ + if (compute[icompute]) delete compute[icompute]; // move other Computes down in list one slot @@ -1347,6 +1352,20 @@ int Modify::find_compute(const std::string &id) return -1; } +/* ---------------------------------------------------------------------- + find a compute by style + return index of compute or -1 if not found +------------------------------------------------------------------------- */ + +int Modify::find_compute_by_style(const char *style) +{ + int icompute; + for (icompute = 0; icompute < ncompute; icompute++) + if (utils::strmatch(compute[icompute]->style,style)) break; + if (icompute == ncompute) return -1; + return icompute; +} + /* ---------------------------------------------------------------------- clear invoked flag of all computes called everywhere that computes are used, before computes are invoked diff --git a/src/modify.h b/src/modify.h index ba8efd6525..0f4f7e32d2 100644 --- a/src/modify.h +++ b/src/modify.h @@ -109,21 +109,24 @@ class Modify : protected Pointers { void delete_fix(int); int find_fix(const std::string &); int find_fix_by_style(const char *); - int check_package(const char *); - int check_rigid_group_overlap(int); - int check_rigid_region_overlap(int, class Region *); - int check_rigid_list_overlap(int *); void add_compute(int, char **, int trysuffix=1); void add_compute(const std::string &, int trysuffix=1); void modify_compute(int, char **); void delete_compute(const std::string &); + void delete_compute(int); int find_compute(const std::string &); + int find_compute_by_style(const char *); void clearstep_compute(); void addstep_compute(bigint); void addstep_compute_all(bigint); + int check_package(const char *); + int check_rigid_group_overlap(int); + int check_rigid_region_overlap(int, class Region *); + int check_rigid_list_overlap(int *); + void write_restart(FILE *); int read_restart(FILE *); void restart_deallocate(int); From b2309f624606a56682282ab48b9b81a154e51eb4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 17:09:08 -0400 Subject: [PATCH 088/257] add support for computes --- src/PLUGIN/plugin.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/PLUGIN/plugin.cpp b/src/PLUGIN/plugin.cpp index 91d22b2897..255202b86b 100644 --- a/src/PLUGIN/plugin.cpp +++ b/src/PLUGIN/plugin.cpp @@ -218,6 +218,16 @@ namespace LAMMPS_NS } (*improper_map)[plugin->name] = (Force::ImproperCreator)plugin->creator.v1; + } else if (pstyle == "compute") { + auto compute_map = lmp->modify->compute_map; + if (compute_map->find(plugin->name) != compute_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR,fmt::format("Overriding built-in compute " + "style {} from plugin", + plugin->name)); + } + (*compute_map)[plugin->name] = (Modify::ComputeCreator)plugin->creator.v2; + } else if (pstyle == "fix") { auto fix_map = lmp->modify->fix_map; if (fix_map->find(plugin->name) != fix_map->end()) { @@ -260,7 +270,8 @@ namespace LAMMPS_NS // ignore unload request from unsupported style categories if ((strcmp(style,"pair") != 0) && (strcmp(style,"bond") != 0) && (strcmp(style,"angle") != 0) && (strcmp(style,"dihedral") != 0) - && (strcmp(style,"improper") != 0) && (strcmp(style,"fix") != 0) + && (strcmp(style,"improper") != 0) && (strcmp(style,"compute") != 0) + && (strcmp(style,"fix") != 0) && (strcmp(style,"command") != 0)) { if (me == 0) utils::logmesg(lmp,fmt::format("Ignoring unload: {} is not a " @@ -357,6 +368,16 @@ namespace LAMMPS_NS && (lmp->force->improper_match(name) != nullptr)) lmp->force->create_improper("none",0); + } else if (pstyle == "compute") { + + auto compute_map = lmp->modify->compute_map; + auto found = compute_map->find(name); + if (found != compute_map->end()) compute_map->erase(name); + + for (int icompute = lmp->modify->find_compute_by_style(name); + icompute >= 0; icompute = lmp->modify->find_compute_by_style(name)) + lmp->modify->delete_compute(icompute); + } else if (pstyle == "fix") { auto fix_map = lmp->modify->fix_map; From 03793d5e4dba32bcce433f32c585dc916e7c4147 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 17:23:25 -0400 Subject: [PATCH 089/257] simplify --- src/modify.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/modify.cpp b/src/modify.cpp index 9cb90fc36f..80cf2667fe 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -1099,11 +1099,9 @@ int Modify::find_fix(const std::string &id) int Modify::find_fix_by_style(const char *style) { - int ifix; - for (ifix = 0; ifix < nfix; ifix++) - if (utils::strmatch(fix[ifix]->style,style)) break; - if (ifix == nfix) return -1; - return ifix; + for (int ifix = 0; ifix < nfix; ifix++) + if (utils::strmatch(fix[ifix]->style,style)) return ifix; + return -1; } /* ---------------------------------------------------------------------- @@ -1359,11 +1357,9 @@ int Modify::find_compute(const std::string &id) int Modify::find_compute_by_style(const char *style) { - int icompute; - for (icompute = 0; icompute < ncompute; icompute++) - if (utils::strmatch(compute[icompute]->style,style)) break; - if (icompute == ncompute) return -1; - return icompute; + for (int icompute = 0; icompute < ncompute; icompute++) + if (utils::strmatch(compute[icompute]->style,style)) return icompute; + return -1; } /* ---------------------------------------------------------------------- From 023d42b5bb90a289c16fbcfefba9dd42063f7635 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 18:03:12 -0400 Subject: [PATCH 090/257] add support for region style plugins --- src/PLUGIN/plugin.cpp | 23 ++++++++++++++++++++++- src/domain.cpp | 24 +++++++++++++++++++++++- src/domain.h | 2 ++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/PLUGIN/plugin.cpp b/src/PLUGIN/plugin.cpp index 255202b86b..b52e1a1959 100644 --- a/src/PLUGIN/plugin.cpp +++ b/src/PLUGIN/plugin.cpp @@ -14,6 +14,7 @@ #include "plugin.h" #include "comm.h" +#include "domain.h" #include "error.h" #include "input.h" #include "force.h" @@ -238,6 +239,16 @@ namespace LAMMPS_NS } (*fix_map)[plugin->name] = (Modify::FixCreator)plugin->creator.v2; + } else if (pstyle == "region") { + auto region_map = lmp->domain->region_map; + if (region_map->find(plugin->name) != region_map->end()) { + if (lmp->comm->me == 0) + lmp->error->warning(FLERR,fmt::format("Overriding built-in region " + "style {} from plugin", + plugin->name)); + } + (*region_map)[plugin->name] = (Domain::RegionCreator)plugin->creator.v2; + } else if (pstyle == "command") { auto command_map = lmp->input->command_map; if (command_map->find(plugin->name) != command_map->end()) { @@ -271,7 +282,7 @@ namespace LAMMPS_NS if ((strcmp(style,"pair") != 0) && (strcmp(style,"bond") != 0) && (strcmp(style,"angle") != 0) && (strcmp(style,"dihedral") != 0) && (strcmp(style,"improper") != 0) && (strcmp(style,"compute") != 0) - && (strcmp(style,"fix") != 0) + && (strcmp(style,"fix") != 0) && (strcmp(style,"region") != 0) && (strcmp(style,"command") != 0)) { if (me == 0) utils::logmesg(lmp,fmt::format("Ignoring unload: {} is not a " @@ -388,6 +399,16 @@ namespace LAMMPS_NS ifix >= 0; ifix = lmp->modify->find_fix_by_style(name)) lmp->modify->delete_fix(ifix); + } else if (pstyle == "region") { + + auto region_map = lmp->domain->region_map; + auto found = region_map->find(name); + if (found != region_map->end()) region_map->erase(name); + + for (int iregion = lmp->domain->find_region_by_style(name); + iregion >= 0; iregion = lmp->domain->find_region_by_style(name)) + lmp->domain->delete_region(iregion); + } else if (pstyle == "command") { auto command_map = lmp->input->command_map; diff --git a/src/domain.cpp b/src/domain.cpp index c6dee63221..abf0d70079 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -1816,8 +1816,18 @@ void Domain::delete_region(int narg, char **arg) int iregion = find_region(arg[0]); if (iregion == -1) error->all(FLERR,"Delete region ID does not exist"); + delete_region(iregion); +} + +void Domain::delete_region(int iregion) +{ + if ((iregion < 0) || (iregion >= nregion)) return; + + // delete and move other Regions down in list one slot + delete regions[iregion]; - regions[iregion] = regions[nregion-1]; + for (int i = iregion+1; iregion < nregion; ++i) + regions[i-1] = regions[i]; nregion--; } @@ -1833,6 +1843,18 @@ int Domain::find_region(const std::string &name) return -1; } +/* ---------------------------------------------------------------------- + return region index if name matches existing region style + return -1 if no such region +------------------------------------------------------------------------- */ + +int Domain::find_region_by_style(const std::string &name) +{ + for (int iregion = 0; iregion < nregion; iregion++) + if (name == regions[iregion]->style) return iregion; + return -1; +} + /* ---------------------------------------------------------------------- (re)set boundary settings flag = 0, called from the input script diff --git a/src/domain.h b/src/domain.h index 99349edb5d..5009a67d28 100644 --- a/src/domain.h +++ b/src/domain.h @@ -130,7 +130,9 @@ class Domain : protected Pointers { void set_lattice(int, char **); void add_region(int, char **); void delete_region(int, char **); + void delete_region(int); int find_region(const std::string &); + int find_region_by_style(const std::string &); void set_boundary(int, char **, int); void set_box(int, char **); void print_box(const std::string &); From a5ce7c1ac9e6758c0d3606913f4d54c71d635f09 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 18:03:26 -0400 Subject: [PATCH 091/257] better checks for valid data --- src/modify.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/modify.cpp b/src/modify.cpp index 80cf2667fe..79a0ecd41f 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -1069,10 +1069,12 @@ void Modify::delete_fix(const std::string &id) void Modify::delete_fix(int ifix) { - if (fix[ifix]) delete fix[ifix]; - atom->update_callback(ifix); + if ((ifix < 0) || (ifix >= nfix)) return; - // move other Fixes and fmask down in list one slot + // delete instance and move other Fixes and fmask down in list one slot + + delete fix[ifix]; + atom->update_callback(ifix); for (int i = ifix+1; i < nfix; i++) fix[i-1] = fix[i]; for (int i = ifix+1; i < nfix; i++) fmask[i-1] = fmask[i]; @@ -1329,10 +1331,11 @@ void Modify::delete_compute(const std::string &id) void Modify::delete_compute(int icompute) { - if (compute[icompute]) delete compute[icompute]; + if ((icompute < 0) || (icompute >= ncompute)) return; - // move other Computes down in list one slot + // delete and move other Computes down in list one slot + delete compute[icompute]; for (int i = icompute+1; i < ncompute; i++) compute[i-1] = compute[i]; ncompute--; } From 024a9600b15df903b614978bf655f56c06e63a26 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 18:04:13 -0400 Subject: [PATCH 092/257] update docs --- doc/src/Developer_plugins.rst | 120 +++++++++++++++----- doc/src/plugin.rst | 2 +- doc/utils/sphinx-config/false_positives.txt | 1 + 3 files changed, 96 insertions(+), 27 deletions(-) diff --git a/doc/src/Developer_plugins.rst b/doc/src/Developer_plugins.rst index 7275c12605..68f1f1387c 100644 --- a/doc/src/Developer_plugins.rst +++ b/doc/src/Developer_plugins.rst @@ -2,36 +2,95 @@ Writing plugins --------------- Plugins provide a mechanism to add functionality to a LAMMPS executable -without recompiling LAMMPS. This uses the operating system's -capability to load dynamic shared object (DSO) files in a way similar -shared libraries and then references specific functions those DSOs. -Any DSO file with plugins has to include an initialization function -with a specific name that has to follow specific rules. When loading -the DSO, this function is called and will then register the contained -plugin(s) with LAMMPS. +without recompiling LAMMPS. The functionality for this and the +:doc:`plugin command ` are implemented in the +:ref:`PLUGIN package ` which must be installed to use plugins. + +Plugins use the operating system's capability to load dynamic shared +object (DSO) files in a way similar shared libraries and then reference +specific functions in those DSOs. Any DSO file with plugins has to include +an initialization function with a specific name, "lammpsplugin_init", that +has to follow specific rules described below. When loading the DSO with +the "plugin" command, this function is looked up and called and will then +register the contained plugin(s) with LAMMPS. From the programmer perspective this can work because of the object -oriented design where all pair style commands are derived from the class -Pair, all fix style commands from the class Fix and so on and only -functions from those base classes are called directly. When a -:doc:`pair_style` command or :doc:`fix` command is issued a new -instance of such a derived class is created. This is done by a -so-called factory function which is mapped to the style name. Thus -when, for example, the LAMMPS processes the command -``pair_style lj/cut 2.5``, LAMMPS will look up the factory function -for creating the ``PairLJCut`` class and then execute it. The return -value of that function is a ``Pair *`` pointer and the pointer will -be assigned to the location for the currently active pair style. +oriented design of LAMMPS where all pair style commands are derived from +the class Pair, all fix style commands from the class Fix and so on and +usually only functions present in those base classes are called +directly. When a :doc:`pair_style` command or :doc:`fix` command is +issued a new instance of such a derived class is created. This is done +by a so-called factory function which is mapped to the style name. Thus +when, for example, the LAMMPS processes the command ``pair_style lj/cut +2.5``, LAMMPS will look up the factory function for creating the +``PairLJCut`` class and then execute it. The return value of that +function is a ``Pair *`` pointer and the pointer will be assigned to the +location for the currently active pair style. -A plugin thus has to implement such a factory function and register it -with LAMMPS so that it gets added to the map of available styles of -the given category. To register a plugin with LAMMPS an initialization -function has to be called that follows specific rules explained below. +A DSO file with a plugin thus has to implement such a factory function +and register it with LAMMPS so that it gets added to the map of available +styles of the given category. To register a plugin with LAMMPS an +initialization function has to be present in the DSO file called +``lammpsplugin_init`` which is called with three ``void *`` arguments: +a pointer to the current LAMMPS instance, a pointer to the opened DSO +handle, and a pointer to the registration function. The registration +function takes two arguments: a pointer to a ``lammpsplugin_t`` struct +with information about the plugin and a pointer to the current LAMMPS +instance. Please see below for an example of how the registration is +done. +Members of ``lammpsplugin_t`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -As an example, for a hypothetical pair style "morse2" implemented in a -class ``PairMorse2`` in the files ``pair_morse2.h`` and -``pair_morse2.cpp`` the file with the factory function and initialization +.. list-table:: + :header-rows: 1 + :widths: auto + + * - Member + - Description + * - version + - LAMMPS Version string the plugin was compiled for + * - style + - Style of the plugin (pair, bond, fix, command, etc.) + * - name + - Name of the plugin style + * - info + - String with information about the plugin + * - author + - String with the name and email of the author + * - creator.v1 + - Pointer to factory function for pair, bond, angle, dihedral, or improper styles + * - creator.v2 + - Pointer to factory function for compute, fix, or region styles + * - creator.v3 + - Pointer to factory function for command styles + * - handle + - Pointer to the open DSO file handle + +Only one of the three alternate creator entries can be used at a time +and which of those is determined by the style of plugin. The "creator.v1" +element is for factory functions of supported styles computing forces (i.e. +pair, bond, angle, dihedral, or improper styles) and the function takes +as single argument the pointer to the LAMMPS instance. The factory function +is cast to the ``lammpsplugin_factory1`` type before assignment. The +"creator.v2" element is for factory functions creating an instance of +a fix, compute, or region style and takes three arguments: a pointer to +the LAMMPS instance, an integer with the length of the argument list and +a ``char **`` pointer to the list of arguments. The factory function pointer +needs to be cast to the ``lammpsplugin_factory2`` type before assignment. +The "creator.v3" element takes the same arguments as "creator.v3" but is +specific to creating command styles: the factory function has to instantiate +the command style locally passing the LAMMPS pointer as argument and then +call its "command" member function with the number and list of arguments. +The factory function pointer needs to be cast to the +``lammpsplugin_factory3`` type before assignment. + +Pair style example +^^^^^^^^^^^^^^^^^^ + +As an example, a hypothetical pair style plugin "morse2" implemented in +a class ``PairMorse2`` in the files ``pair_morse2.h`` and +``pair_morse2.cpp`` with the factory function and initialization function would look like this: .. code-block:: C++ @@ -70,6 +129,10 @@ pointer to the allocated class instance derived from the ``Pair`` class. This function may be declared static to avoid clashes with other plugins. The name of the derived class, ``PairMorse2``, must be unique inside the entire LAMMPS executable. + +Fix style example +^^^^^^^^^^^^^^^^^ + If the factory function would be for a fix or compute, which take three arguments (a pointer to the LAMMPS class, the number of arguments and the list of argument strings), then the pointer type is ``lammpsplugin_factory2`` @@ -104,6 +167,8 @@ Below is an example for that: (*register_plugin)(&plugin,lmp); } +Command style example +^^^^^^^^^^^^^^^^^^^^^ For command styles there is a third variant of factory function as demonstrated in the following example, which also shows that the implementation of the plugin class may also be within the same @@ -158,6 +223,9 @@ file as the plugin interface code: (*register_plugin)(&plugin,lmp); } +Additional Details +^^^^^^^^^^^^^^^^^^ + The initialization function **must** be called ``lammpsplugin_init``, it **must** have C bindings and it takes three void pointers as arguments. The first is a pointer to the LAMMPS class that calls it and it needs to @@ -167,7 +235,7 @@ to the plugin info struct, so that the DSO can be closed and unloaded when all its contained plugins are unloaded. The third argument is a function pointer to the registration function and needs to be stored in a variable of ``lammpsplugin_regfunc`` type and then called with a -pointer to the ``lammpsplugin_`` struct and the pointer to the LAMMPS +pointer to the ``lammpsplugin_t`` struct and the pointer to the LAMMPS instance as arguments to register a single plugin. There may be multiple calls to multiple plugins in the same initialization function. diff --git a/doc/src/plugin.rst b/doc/src/plugin.rst index 48638bf97a..02228636bc 100644 --- a/doc/src/plugin.rst +++ b/doc/src/plugin.rst @@ -17,7 +17,7 @@ Syntax *load* file = load plugin(s) from shared object in *file* *unload* style name = unload plugin *name* of style *style* - *style* = *pair* or *fix* or *command* + *style* = *pair* or *bond* or *angle* or *dihedral* or *improper* or *compute* or *fix* or *region* or *command* *list* = print a list of currently loaded plugins *clear* = unload all currently loaded plugins diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 1d66028621..38a6971f4c 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -1588,6 +1588,7 @@ lammps Lammps LAMMPS lammpsplot +lammpsplugin Lampis Lamoureux Lanczos From 59c0325f0884fc11618967b06c5f52db4c21b843 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 19:58:04 -0400 Subject: [PATCH 093/257] simplify by using utils::strdup() --- src/compute.cpp | 15 ++++----------- src/compute_angle_local.cpp | 8 ++------ src/compute_angmom_chunk.cpp | 4 +--- src/compute_bond_local.cpp | 8 ++------ src/compute_centroid_stress_atom.cpp | 4 +--- src/compute_chunk_atom.cpp | 4 +--- src/compute_chunk_spread_atom.cpp | 4 +--- src/compute_com_chunk.cpp | 4 +--- src/compute_coord_atom.cpp | 4 +--- src/compute_dihedral_local.cpp | 8 ++------ src/compute_dipole_chunk.cpp | 4 +--- src/compute_displace_atom.cpp | 12 ++++-------- src/compute_group_group.cpp | 5 +---- src/compute_gyration_chunk.cpp | 4 +--- src/compute_heat_flux.cpp | 14 +++----------- src/compute_inertia_chunk.cpp | 4 +--- src/compute_msd_chunk.cpp | 12 ++++-------- src/compute_omega_chunk.cpp | 4 +--- src/compute_pair.cpp | 11 +++++------ src/compute_pressure.cpp | 15 ++++++--------- src/compute_property_chunk.cpp | 4 +--- src/compute_reduce.cpp | 4 +--- src/compute_reduce_chunk.cpp | 4 +--- src/compute_stress_atom.cpp | 4 +--- src/compute_temp_chunk.cpp | 8 ++------ src/compute_temp_region.cpp | 4 +--- src/compute_temp_sphere.cpp | 4 +--- src/compute_torque_chunk.cpp | 4 +--- src/compute_vcm_chunk.cpp | 4 +--- 29 files changed, 53 insertions(+), 135 deletions(-) diff --git a/src/compute.cpp b/src/compute.cpp index df2bf9429c..81e317076c 100644 --- a/src/compute.cpp +++ b/src/compute.cpp @@ -49,22 +49,15 @@ Compute::Compute(LAMMPS *lmp, int narg, char **arg) : // compute ID, group, and style // ID must be all alphanumeric chars or underscores - int n = strlen(arg[0]) + 1; - id = new char[n]; - strcpy(id,arg[0]); - - for (int i = 0; i < n-1; i++) - if (!isalnum(id[i]) && id[i] != '_') - error->all(FLERR, - "Compute ID must be alphanumeric or underscore characters"); + id = utils::strdup(arg[0]); + if (!utils::is_id(id)) + error->all(FLERR,"Compute ID must be alphanumeric or underscore characters"); igroup = group->find(arg[1]); if (igroup == -1) error->all(FLERR,"Could not find compute group ID"); groupbit = group->bitmask[igroup]; - n = strlen(arg[2]) + 1; - style = new char[n]; - strcpy(style,arg[2]); + style = utils::strdup(arg[2]); // set child class defaults diff --git a/src/compute_angle_local.cpp b/src/compute_angle_local.cpp index 8e24eccf01..d0630f07eb 100644 --- a/src/compute_angle_local.cpp +++ b/src/compute_angle_local.cpp @@ -67,9 +67,7 @@ ComputeAngleLocal::ComputeAngleLocal(LAMMPS *lmp, int narg, char **arg) : bstyle[nvalues++] = ENG; } else if (strncmp(arg[iarg],"v_",2) == 0) { bstyle[nvalues++] = VARIABLE; - int n = strlen(arg[iarg]); - vstr[nvar] = new char[n]; - strcpy(vstr[nvar],&arg[iarg][2]); + vstr[nvar] = utils::strdup(&arg[iarg][2]); nvar++; } else break; } @@ -85,9 +83,7 @@ ComputeAngleLocal::ComputeAngleLocal(LAMMPS *lmp, int narg, char **arg) : if (iarg+3 > narg) error->all(FLERR,"Illegal compute angle/local command"); if (strcmp(arg[iarg+1],"theta") == 0) { delete [] tstr; - int n = strlen(arg[iarg+2]) + 1; - tstr = new char[n]; - strcpy(tstr,arg[iarg+2]); + tstr = utils::strdup(arg[iarg+2]); tflag = 1; } else error->all(FLERR,"Illegal compute angle/local command"); iarg += 3; diff --git a/src/compute_angmom_chunk.cpp b/src/compute_angmom_chunk.cpp index d35f274d7a..39cae07503 100644 --- a/src/compute_angmom_chunk.cpp +++ b/src/compute_angmom_chunk.cpp @@ -41,9 +41,7 @@ ComputeAngmomChunk::ComputeAngmomChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_bond_local.cpp b/src/compute_bond_local.cpp index d13f313aea..053c4c83dc 100644 --- a/src/compute_bond_local.cpp +++ b/src/compute_bond_local.cpp @@ -74,9 +74,7 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) : else if (strcmp(arg[iarg],"velvib") == 0) bstyle[nvalues++] = VELVIB; else if (strncmp(arg[iarg],"v_",2) == 0) { bstyle[nvalues++] = VARIABLE; - int n = strlen(arg[iarg]); - vstr[nvar] = new char[n]; - strcpy(vstr[nvar],&arg[iarg][2]); + vstr[nvar] = utils::strdup(&arg[iarg][2]); nvar++; } else break; } @@ -92,9 +90,7 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) : if (iarg+3 > narg) error->all(FLERR,"Illegal compute bond/local command"); if (strcmp(arg[iarg+1],"dist") == 0) { delete [] dstr; - int n = strlen(arg[iarg+2]) + 1; - dstr = new char[n]; - strcpy(dstr,arg[iarg+2]); + dstr = utils::strdup(arg[iarg+2]); } else error->all(FLERR,"Illegal compute bond/local command"); iarg += 3; } else error->all(FLERR,"Illegal compute bond/local command"); diff --git a/src/compute_centroid_stress_atom.cpp b/src/compute_centroid_stress_atom.cpp index 9ad871382c..a0abbe8406 100644 --- a/src/compute_centroid_stress_atom.cpp +++ b/src/compute_centroid_stress_atom.cpp @@ -51,9 +51,7 @@ ComputeCentroidStressAtom::ComputeCentroidStressAtom(LAMMPS *lmp, int narg, char if (strcmp(arg[3],"NULL") == 0) id_temp = nullptr; else { - int n = strlen(arg[3]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[3]); + id_temp = utils::strdup(arg[3]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/compute_chunk_atom.cpp b/src/compute_chunk_atom.cpp index 2800c9129b..be1e1e1035 100644 --- a/src/compute_chunk_atom.cpp +++ b/src/compute_chunk_atom.cpp @@ -185,9 +185,7 @@ ComputeChunkAtom::ComputeChunkAtom(LAMMPS *lmp, int narg, char **arg) : int iregion = domain->find_region(arg[iarg+1]); if (iregion == -1) error->all(FLERR,"Region ID for compute chunk/atom does not exist"); - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); regionflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"nchunk") == 0) { diff --git a/src/compute_chunk_spread_atom.cpp b/src/compute_chunk_spread_atom.cpp index 257e5d0960..d817141064 100644 --- a/src/compute_chunk_spread_atom.cpp +++ b/src/compute_chunk_spread_atom.cpp @@ -36,9 +36,7 @@ ComputeChunkSpreadAtom(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init_chunk(); // expand args if any have wildcard character "*" diff --git a/src/compute_com_chunk.cpp b/src/compute_com_chunk.cpp index 54b2354d26..a67b412b9e 100644 --- a/src/compute_com_chunk.cpp +++ b/src/compute_com_chunk.cpp @@ -43,9 +43,7 @@ ComputeCOMChunk::ComputeCOMChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_coord_atom.cpp b/src/compute_coord_atom.cpp index 51a3618d5a..1c56466b36 100644 --- a/src/compute_coord_atom.cpp +++ b/src/compute_coord_atom.cpp @@ -85,9 +85,7 @@ ComputeCoordAtom::ComputeCoordAtom(LAMMPS *lmp, int narg, char **arg) : cstyle = ORIENT; if (narg != 6) error->all(FLERR,"Illegal compute coord/atom command"); - int n = strlen(arg[4]) + 1; - id_orientorder = new char[n]; - strcpy(id_orientorder,arg[4]); + id_orientorder = utils::strdup(arg[4]); int iorientorder = modify->find_compute(id_orientorder); if (iorientorder < 0) diff --git a/src/compute_dihedral_local.cpp b/src/compute_dihedral_local.cpp index d6fa722e26..908acff98c 100644 --- a/src/compute_dihedral_local.cpp +++ b/src/compute_dihedral_local.cpp @@ -64,9 +64,7 @@ ComputeDihedralLocal::ComputeDihedralLocal(LAMMPS *lmp, int narg, char **arg) : bstyle[nvalues++] = PHI; } else if (strncmp(arg[iarg],"v_",2) == 0) { bstyle[nvalues++] = VARIABLE; - int n = strlen(arg[iarg]); - vstr[nvar] = new char[n]; - strcpy(vstr[nvar],&arg[iarg][2]); + vstr[nvar] = utils::strdup(&arg[iarg][2]); nvar++; } else break; } @@ -83,9 +81,7 @@ ComputeDihedralLocal::ComputeDihedralLocal(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Illegal compute dihedral/local command"); if (strcmp(arg[iarg+1],"phi") == 0) { delete [] pstr; - int n = strlen(arg[iarg+2]) + 1; - pstr = new char[n]; - strcpy(pstr,arg[iarg+2]); + pstr = utils::strdup(arg[iarg+2]); } else error->all(FLERR,"Illegal compute dihedral/local command"); iarg += 3; } else error->all(FLERR,"Illegal compute dihedral/local command"); diff --git a/src/compute_dipole_chunk.cpp b/src/compute_dipole_chunk.cpp index 540e533727..708ea3f755 100644 --- a/src/compute_dipole_chunk.cpp +++ b/src/compute_dipole_chunk.cpp @@ -49,9 +49,7 @@ ComputeDipoleChunk::ComputeDipoleChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); usecenter = MASSCENTER; diff --git a/src/compute_displace_atom.cpp b/src/compute_displace_atom.cpp index 445caa15dc..4e4b87f99c 100644 --- a/src/compute_displace_atom.cpp +++ b/src/compute_displace_atom.cpp @@ -53,9 +53,7 @@ ComputeDisplaceAtom::ComputeDisplaceAtom(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Illegal compute displace/atom command"); refreshflag = 1; delete [] rvar; - int n = strlen(arg[iarg+1]) + 1; - rvar = new char[n]; - strcpy(rvar,arg[iarg+1]); + rvar = utils::strdup(arg[iarg+1]); iarg += 2; } else error->all(FLERR,"Illegal compute displace/atom command"); } @@ -74,11 +72,9 @@ ComputeDisplaceAtom::ComputeDisplaceAtom(LAMMPS *lmp, int narg, char **arg) : // create a new fix STORE style // id = compute-ID + COMPUTE_STORE, fix group = compute group - std::string cmd = id + std::string("_COMPUTE_STORE"); - id_fix = new char[cmd.size()+1]; - strcpy(id_fix,cmd.c_str()); - - cmd += fmt::format(" {} STORE peratom 1 3", group->names[igroup]); + id_fix = utils::strdup(std::string(id) + "_COMPUTE_STORE"); + std::string cmd = id_fix + fmt::format(" {} STORE peratom 1 3", + group->names[igroup]); modify->add_fix(cmd); fix = (FixStore *) modify->fix[modify->nfix-1]; diff --git a/src/compute_group_group.cpp b/src/compute_group_group.cpp index be670332de..7912b4e031 100644 --- a/src/compute_group_group.cpp +++ b/src/compute_group_group.cpp @@ -54,10 +54,7 @@ ComputeGroupGroup::ComputeGroupGroup(LAMMPS *lmp, int narg, char **arg) : extscalar = 1; extvector = 1; - int n = strlen(arg[3]) + 1; - group2 = new char[n]; - strcpy(group2,arg[3]); - + group2 = utils::strdup(arg[3]); jgroup = group->find(group2); if (jgroup == -1) error->all(FLERR,"Compute group/group group ID does not exist"); diff --git a/src/compute_gyration_chunk.cpp b/src/compute_gyration_chunk.cpp index d2af181eaf..c2db9fa855 100644 --- a/src/compute_gyration_chunk.cpp +++ b/src/compute_gyration_chunk.cpp @@ -36,9 +36,7 @@ ComputeGyrationChunk::ComputeGyrationChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_heat_flux.cpp b/src/compute_heat_flux.cpp index 91019aef28..b2e5662a6b 100644 --- a/src/compute_heat_flux.cpp +++ b/src/compute_heat_flux.cpp @@ -43,17 +43,9 @@ ComputeHeatFlux::ComputeHeatFlux(LAMMPS *lmp, int narg, char **arg) : // store ke/atom, pe/atom, stress/atom IDs used by heat flux computation // insure they are valid for these computations - int n = strlen(arg[3]) + 1; - id_ke = new char[n]; - strcpy(id_ke,arg[3]); - - n = strlen(arg[4]) + 1; - id_pe = new char[n]; - strcpy(id_pe,arg[4]); - - n = strlen(arg[5]) + 1; - id_stress = new char[n]; - strcpy(id_stress,arg[5]); + id_ke = utils::strdup(arg[3]); + id_pe = utils::strdup(arg[4]); + id_stress = utils::strdup(arg[5]); int ike = modify->find_compute(id_ke); int ipe = modify->find_compute(id_pe); diff --git a/src/compute_inertia_chunk.cpp b/src/compute_inertia_chunk.cpp index d2c6d345ce..9e0084acfb 100644 --- a/src/compute_inertia_chunk.cpp +++ b/src/compute_inertia_chunk.cpp @@ -41,9 +41,7 @@ ComputeInertiaChunk::ComputeInertiaChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_msd_chunk.cpp b/src/compute_msd_chunk.cpp index 9dc3281b78..39ed9d1f1c 100644 --- a/src/compute_msd_chunk.cpp +++ b/src/compute_msd_chunk.cpp @@ -44,9 +44,7 @@ ComputeMSDChunk::ComputeMSDChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); firstflag = 1; init(); @@ -58,11 +56,9 @@ ComputeMSDChunk::ComputeMSDChunk(LAMMPS *lmp, int narg, char **arg) : // potentially re-populate the fix array (and change it to correct size) // otherwise size reset and init will be done in setup() - std::string fixcmd = id + std::string("_COMPUTE_STORE"); - id_fix = new char[fixcmd.size()+1]; - strcpy(id_fix,fixcmd.c_str()); - - fixcmd += fmt::format(" {} STORE global 1 1",group->names[igroup]); + id_fix = utils::strdup(std::string(id) + "_COMPUTE_STORE"); + std::string fixcmd = id_fix + + fmt::format(" {} STORE global 1 1",group->names[igroup]); modify->add_fix(fixcmd); fix = (FixStore *) modify->fix[modify->nfix-1]; } diff --git a/src/compute_omega_chunk.cpp b/src/compute_omega_chunk.cpp index b721f0efb5..da3b482341 100644 --- a/src/compute_omega_chunk.cpp +++ b/src/compute_omega_chunk.cpp @@ -45,9 +45,7 @@ ComputeOmegaChunk::ComputeOmegaChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_pair.cpp b/src/compute_pair.cpp index 4fd7de736d..aa9df260b1 100644 --- a/src/compute_pair.cpp +++ b/src/compute_pair.cpp @@ -37,10 +37,10 @@ ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) : peflag = 1; timeflag = 1; - int n = strlen(arg[3]) + 1; - if (lmp->suffix) n += strlen(lmp->suffix) + 1; - pstyle = new char[n]; - strcpy(pstyle,arg[3]); + // copy with suffix so we can later chop it off, if needed + if (lmp->suffix) + pstyle = utils::strdup(fmt::format("{}/{}",arg[3],lmp->suffix)); + else pstyle = utils::strdup(arg[3]); int iarg = 4; nsub = 0; @@ -67,8 +67,7 @@ ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) : pair = force->pair_match(pstyle,1,nsub); if (!pair && lmp->suffix) { - strcat(pstyle,"/"); - strcat(pstyle,lmp->suffix); + pstyle[strlen(pstyle) - strlen(lmp->suffix) - 1] = '\0'; pair = force->pair_match(pstyle,1,nsub); } diff --git a/src/compute_pressure.cpp b/src/compute_pressure.cpp index 82ddbbb5c5..3bf66f42ce 100644 --- a/src/compute_pressure.cpp +++ b/src/compute_pressure.cpp @@ -53,9 +53,7 @@ ComputePressure::ComputePressure(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[3],"NULL") == 0) id_temp = nullptr; else { - int n = strlen(arg[3]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[3]); + id_temp = utils::strdup(arg[3]); int icompute = modify->find_compute(id_temp); if (icompute < 0) @@ -82,10 +80,10 @@ ComputePressure::ComputePressure(LAMMPS *lmp, int narg, char **arg) : while (iarg < narg) { if (strcmp(arg[iarg],"ke") == 0) keflag = 1; else if (strcmp(arg[iarg],"pair/hybrid") == 0) { - int n = strlen(arg[++iarg]) + 1; - if (lmp->suffix) n += strlen(lmp->suffix) + 1; - pstyle = new char[n]; - strcpy(pstyle,arg[iarg++]); + if (lmp->suffix) + pstyle = utils::strdup(fmt::format("{}/{}",arg[++iarg],lmp->suffix)); + else + pstyle = utils::strdup(arg[++iarg]); nsub = 0; @@ -102,8 +100,7 @@ ComputePressure::ComputePressure(LAMMPS *lmp, int narg, char **arg) : pairhybrid = (Pair *) force->pair_match(pstyle,1,nsub); if (!pairhybrid && lmp->suffix) { - strcat(pstyle,"/"); - strcat(pstyle,lmp->suffix); + pstyle[strlen(pstyle) - strlen(lmp->suffix) - 1] = '\0'; pairhybrid = (Pair *) force->pair_match(pstyle,1,nsub); } diff --git a/src/compute_property_chunk.cpp b/src/compute_property_chunk.cpp index d1588b61a3..72e9831b0c 100644 --- a/src/compute_property_chunk.cpp +++ b/src/compute_property_chunk.cpp @@ -33,9 +33,7 @@ ComputePropertyChunk::ComputePropertyChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_reduce.cpp b/src/compute_reduce.cpp index bc9aeefe7b..30b4fcb98a 100644 --- a/src/compute_reduce.cpp +++ b/src/compute_reduce.cpp @@ -47,9 +47,7 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : iregion = domain->find_region(arg[3]); if (iregion == -1) error->all(FLERR,"Region ID for compute reduce/region does not exist"); - int n = strlen(arg[3]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[3]); + idregion = utils::strdup(arg[3]); iarg = 4; } diff --git a/src/compute_reduce_chunk.cpp b/src/compute_reduce_chunk.cpp index a09d37b9d8..e895a13b18 100644 --- a/src/compute_reduce_chunk.cpp +++ b/src/compute_reduce_chunk.cpp @@ -45,9 +45,7 @@ ComputeReduceChunk::ComputeReduceChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init_chunk(); // mode diff --git a/src/compute_stress_atom.cpp b/src/compute_stress_atom.cpp index 28abc13453..0d27031326 100644 --- a/src/compute_stress_atom.cpp +++ b/src/compute_stress_atom.cpp @@ -51,9 +51,7 @@ ComputeStressAtom::ComputeStressAtom(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[3],"NULL") == 0) id_temp = nullptr; else { - int n = strlen(arg[3]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[3]); + id_temp = utils::strdup(arg[3]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/compute_temp_chunk.cpp b/src/compute_temp_chunk.cpp index 765effa6c0..31f955fcb5 100644 --- a/src/compute_temp_chunk.cpp +++ b/src/compute_temp_chunk.cpp @@ -44,9 +44,7 @@ ComputeTempChunk::ComputeTempChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); biasflag = 0; init(); @@ -87,9 +85,7 @@ ComputeTempChunk::ComputeTempChunk(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal compute temp/chunk command"); biasflag = 1; - int n = strlen(arg[iarg+1]) + 1; - id_bias = new char[n]; - strcpy(id_bias,arg[iarg+1]); + id_bias = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"adof") == 0) { if (iarg+2 > narg) diff --git a/src/compute_temp_region.cpp b/src/compute_temp_region.cpp index e1ce4e024b..036f118a30 100644 --- a/src/compute_temp_region.cpp +++ b/src/compute_temp_region.cpp @@ -36,9 +36,7 @@ ComputeTempRegion::ComputeTempRegion(LAMMPS *lmp, int narg, char **arg) : iregion = domain->find_region(arg[3]); if (iregion == -1) error->all(FLERR,"Region ID for compute temp/region does not exist"); - int n = strlen(arg[3]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[3]); + idregion = utils::strdup(arg[3]); scalar_flag = vector_flag = 1; size_vector = 6; diff --git a/src/compute_temp_sphere.cpp b/src/compute_temp_sphere.cpp index 8ffb1b2d6f..b8ac7cf566 100644 --- a/src/compute_temp_sphere.cpp +++ b/src/compute_temp_sphere.cpp @@ -51,9 +51,7 @@ ComputeTempSphere::ComputeTempSphere(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal compute temp/sphere command"); tempbias = 1; - int n = strlen(arg[iarg+1]) + 1; - id_bias = new char[n]; - strcpy(id_bias,arg[iarg+1]); + id_bias = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"dof") == 0) { if (iarg+2 > narg) diff --git a/src/compute_torque_chunk.cpp b/src/compute_torque_chunk.cpp index d961c914e8..9aea024114 100644 --- a/src/compute_torque_chunk.cpp +++ b/src/compute_torque_chunk.cpp @@ -40,9 +40,7 @@ ComputeTorqueChunk::ComputeTorqueChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); diff --git a/src/compute_vcm_chunk.cpp b/src/compute_vcm_chunk.cpp index 182e8191cb..dd4bac208f 100644 --- a/src/compute_vcm_chunk.cpp +++ b/src/compute_vcm_chunk.cpp @@ -41,9 +41,7 @@ ComputeVCMChunk::ComputeVCMChunk(LAMMPS *lmp, int narg, char **arg) : // ID of compute chunk/atom - int n = strlen(arg[3]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[3]); + idchunk = utils::strdup(arg[3]); init(); From 1710fb86d392eb84696f021589dad8b621e3ea5f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 20:33:36 -0400 Subject: [PATCH 094/257] when using INTEL_LR_THREADS from C++11 we must add the threads library --- cmake/Modules/Packages/USER-INTEL.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/Packages/USER-INTEL.cmake b/cmake/Modules/Packages/USER-INTEL.cmake index ff0858f0ff..90ab6167a3 100644 --- a/cmake/Modules/Packages/USER-INTEL.cmake +++ b/cmake/Modules/Packages/USER-INTEL.cmake @@ -30,7 +30,12 @@ if(INTEL_LRT_MODE STREQUAL "THREADS") endif() endif() if(INTEL_LRT_MODE STREQUAL "C++11") - target_compile_definitions(lammps PRIVATE -DLMP_INTEL_USELRT -DLMP_INTEL_LRT11) + if(Threads_FOUND) + target_compile_definitions(lammps PRIVATE -DLMP_INTEL_USELRT -DLMP_INTEL_LRT11) + target_link_libraries(lammps PRIVATE Threads::Threads) + else() + message(FATAL_ERROR "Must have working threads library for Long-range thread support") + endif() endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") From a5563e8d0445f48b0ea4fd3ab4268d71bf9c86ad Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 18 Mar 2021 20:56:04 -0400 Subject: [PATCH 095/257] simplify using utils::strdup() --- src/fix.cpp | 14 ++++---------- src/fix_ave_chunk.cpp | 24 ++++++------------------ src/fix_ave_correlate.cpp | 12 +++--------- src/fix_ave_histo.cpp | 12 +++--------- src/fix_ave_time.cpp | 16 ++++------------ src/fix_box_relax.cpp | 8 ++------ src/fix_controller.cpp | 4 +--- src/fix_deform.cpp | 16 ++++------------ src/fix_group.cpp | 23 +++++++---------------- src/fix_nh.cpp | 12 +++--------- src/fix_press_berendsen.cpp | 8 ++------ src/fix_spring.cpp | 4 +--- src/fix_spring_chunk.cpp | 9 ++------- src/fix_temp_berendsen.cpp | 4 +--- src/fix_temp_csld.cpp | 4 +--- src/fix_temp_csvr.cpp | 4 +--- src/fix_temp_rescale.cpp | 4 +--- src/fix_wall_region.cpp | 4 +--- 18 files changed, 47 insertions(+), 135 deletions(-) diff --git a/src/fix.cpp b/src/fix.cpp index 8cf13f6f1d..b9d9fb3969 100644 --- a/src/fix.cpp +++ b/src/fix.cpp @@ -42,21 +42,15 @@ Fix::Fix(LAMMPS *lmp, int /*narg*/, char **arg) : // fix ID, group, and style // ID must be all alphanumeric chars or underscores - int n = strlen(arg[0]) + 1; - id = new char[n]; - strcpy(id,arg[0]); - - for (int i = 0; i < n-1; i++) - if (!isalnum(id[i]) && id[i] != '_') - error->all(FLERR,"Fix ID must be alphanumeric or underscore characters"); + id = utils::strdup(arg[0]); + if (!utils::is_id(id)) + error->all(FLERR,"Fix ID must be alphanumeric or underscore characters"); igroup = group->find(arg[1]); if (igroup == -1) error->all(FLERR,"Could not find fix group ID"); groupbit = group->bitmask[igroup]; - n = strlen(arg[2]) + 1; - style = new char[n]; - strcpy(style,arg[2]); + style = utils::strdup(arg[2]); restart_global = restart_peratom = restart_file = 0; force_reneighbor = 0; diff --git a/src/fix_ave_chunk.cpp b/src/fix_ave_chunk.cpp index 3b612aeb73..d3220dd9df 100644 --- a/src/fix_ave_chunk.cpp +++ b/src/fix_ave_chunk.cpp @@ -57,9 +57,7 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) : nrepeat = utils::inumeric(FLERR,arg[4],false,lmp); nfreq = utils::inumeric(FLERR,arg[5],false,lmp); - int n = strlen(arg[6]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[6]); + idchunk = utils::strdup(arg[6]); global_freq = nfreq; no_change_box = 1; @@ -190,9 +188,7 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command"); biasflag = 1; - int n = strlen(arg[iarg+1]) + 1; - id_bias = new char[n]; - strcpy(id_bias,arg[iarg+1]); + id_bias = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"adof") == 0) { if (iarg+2 > narg) @@ -220,31 +216,23 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) : } else if (strcmp(arg[iarg],"format") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command"); delete [] format_user; - int n = strlen(arg[iarg+1]) + 2; - format_user = new char[n]; - sprintf(format_user," %s",arg[iarg+1]); + format_user = utils::strdup(arg[iarg+1]); format = format_user; iarg += 2; } else if (strcmp(arg[iarg],"title1") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command"); delete [] title1; - int n = strlen(arg[iarg+1]) + 1; - title1 = new char[n]; - strcpy(title1,arg[iarg+1]); + title1 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title2") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command"); delete [] title2; - int n = strlen(arg[iarg+1]) + 1; - title2 = new char[n]; - strcpy(title2,arg[iarg+1]); + title2 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title3") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command"); delete [] title3; - int n = strlen(arg[iarg+1]) + 1; - title3 = new char[n]; - strcpy(title3,arg[iarg+1]); + title3 = utils::strdup(arg[iarg+1]); iarg += 2; } else error->all(FLERR,"Illegal fix ave/chunk command"); } diff --git a/src/fix_ave_correlate.cpp b/src/fix_ave_correlate.cpp index efd06a182a..81ca94cdc8 100644 --- a/src/fix_ave_correlate.cpp +++ b/src/fix_ave_correlate.cpp @@ -139,23 +139,17 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg): } else if (strcmp(arg[iarg],"title1") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command"); delete [] title1; - int n = strlen(arg[iarg+1]) + 1; - title1 = new char[n]; - strcpy(title1,arg[iarg+1]); + title1 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title2") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command"); delete [] title2; - int n = strlen(arg[iarg+1]) + 1; - title2 = new char[n]; - strcpy(title2,arg[iarg+1]); + title2 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title3") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command"); delete [] title3; - int n = strlen(arg[iarg+1]) + 1; - title3 = new char[n]; - strcpy(title3,arg[iarg+1]); + title3 = utils::strdup(arg[iarg+1]); iarg += 2; } else error->all(FLERR,"Illegal fix ave/correlate command"); } diff --git a/src/fix_ave_histo.cpp b/src/fix_ave_histo.cpp index 0d82fd6b04..0f6943ac31 100644 --- a/src/fix_ave_histo.cpp +++ b/src/fix_ave_histo.cpp @@ -993,23 +993,17 @@ void FixAveHisto::options(int iarg, int narg, char **arg) } else if (strcmp(arg[iarg],"title1") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command"); delete [] title1; - int n = strlen(arg[iarg+1]) + 1; - title1 = new char[n]; - strcpy(title1,arg[iarg+1]); + title1 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title2") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command"); delete [] title2; - int n = strlen(arg[iarg+1]) + 1; - title2 = new char[n]; - strcpy(title2,arg[iarg+1]); + title2 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title3") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command"); delete [] title3; - int n = strlen(arg[iarg+1]) + 1; - title3 = new char[n]; - strcpy(title3,arg[iarg+1]); + title3 = utils::strdup(arg[iarg+1]); iarg += 2; } else error->all(FLERR,"Illegal fix ave/histo command"); } diff --git a/src/fix_ave_time.cpp b/src/fix_ave_time.cpp index e51c86a5e1..7ecb88ddab 100644 --- a/src/fix_ave_time.cpp +++ b/src/fix_ave_time.cpp @@ -1067,31 +1067,23 @@ void FixAveTime::options(int iarg, int narg, char **arg) } else if (strcmp(arg[iarg],"format") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/time command"); delete [] format_user; - int n = strlen(arg[iarg+1]) + 2; - format_user = new char[n]; - sprintf(format_user," %s",arg[iarg+1]); + format_user = utils::strdup(arg[iarg+1]); format = format_user; iarg += 2; } else if (strcmp(arg[iarg],"title1") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command"); delete [] title1; - int n = strlen(arg[iarg+1]) + 1; - title1 = new char[n]; - strcpy(title1,arg[iarg+1]); + title1 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title2") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command"); delete [] title2; - int n = strlen(arg[iarg+1]) + 1; - title2 = new char[n]; - strcpy(title2,arg[iarg+1]); + title2 = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"title3") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/spatial command"); delete [] title3; - int n = strlen(arg[iarg+1]) + 1; - title3 = new char[n]; - strcpy(title3,arg[iarg+1]); + title3 = utils::strdup(arg[iarg+1]); iarg += 2; } else error->all(FLERR,"Illegal fix ave/time command"); } diff --git a/src/fix_box_relax.cpp b/src/fix_box_relax.cpp index ef3032fe0c..ef576e96f6 100644 --- a/src/fix_box_relax.cpp +++ b/src/fix_box_relax.cpp @@ -761,9 +761,7 @@ int FixBoxRelax::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) @@ -792,9 +790,7 @@ int FixBoxRelax::modify_param(int narg, char **arg) pflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/fix_controller.cpp b/src/fix_controller.cpp index 0e2530de41..21d1ccf751 100644 --- a/src/fix_controller.cpp +++ b/src/fix_controller.cpp @@ -67,9 +67,7 @@ FixController::FixController(LAMMPS *lmp, int narg, char **arg) : // control variable arg - int n = strlen(arg[iarg]) + 1; - cvID = new char[n]; - strcpy(cvID,arg[iarg]); + cvID = utils::strdup(arg[iarg]); // error check diff --git a/src/fix_deform.cpp b/src/fix_deform.cpp index 4aec94fc32..b3e5722ee1 100644 --- a/src/fix_deform.cpp +++ b/src/fix_deform.cpp @@ -126,12 +126,8 @@ rfix(nullptr), irregular(nullptr), set(nullptr) error->all(FLERR,"Illegal fix deform command"); delete [] set[index].hstr; delete [] set[index].hratestr; - int n = strlen(&arg[iarg+2][2]) + 1; - set[index].hstr = new char[n]; - strcpy(set[index].hstr,&arg[iarg+2][2]); - n = strlen(&arg[iarg+3][2]) + 1; - set[index].hratestr = new char[n]; - strcpy(set[index].hratestr,&arg[iarg+3][2]); + set[index].hstr = utils::strdup(&arg[iarg+2][2]); + set[index].hratestr = utils::strdup(&arg[iarg+3][2]); iarg += 4; } else error->all(FLERR,"Illegal fix deform command"); @@ -188,12 +184,8 @@ rfix(nullptr), irregular(nullptr), set(nullptr) error->all(FLERR,"Illegal fix deform command"); delete [] set[index].hstr; delete [] set[index].hratestr; - int n = strlen(&arg[iarg+2][2]) + 1; - set[index].hstr = new char[n]; - strcpy(set[index].hstr,&arg[iarg+2][2]); - n = strlen(&arg[iarg+3][2]) + 1; - set[index].hratestr = new char[n]; - strcpy(set[index].hratestr,&arg[iarg+3][2]); + set[index].hstr = utils::strdup(&arg[iarg+2][2]); + set[index].hratestr = utils::strdup(&arg[iarg+3][2]); iarg += 4; } else error->all(FLERR,"Illegal fix deform command"); diff --git a/src/fix_group.cpp b/src/fix_group.cpp index 903eb1b23b..ebd729c737 100644 --- a/src/fix_group.cpp +++ b/src/fix_group.cpp @@ -39,12 +39,9 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr) // dgroupbit = bitmask of dynamic group // group ID is last part of fix ID - int n = strlen(id) - strlen("GROUP_") + 1; - char *dgroup = new char[n]; - strcpy(dgroup,&id[strlen("GROUP_")]); - gbit = group->bitmask[group->find(dgroup)]; - gbitinverse = group->inversemask[group->find(dgroup)]; - delete [] dgroup; + auto dgroupid = std::string(id).substr(strlen("GROUP_")); + gbit = group->bitmask[group->find(dgroupid)]; + gbitinverse = group->inversemask[group->find(dgroupid)]; // process optional args @@ -61,9 +58,7 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr) error->all(FLERR,"Region ID for group dynamic does not exist"); regionflag = 1; delete [] idregion; - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"var") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal group command"); @@ -71,9 +66,7 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr) error->all(FLERR,"Variable name for group dynamic does not exist"); varflag = 1; delete [] idvar; - int n = strlen(arg[iarg+1]) + 1; - idvar = new char[n]; - strcpy(idvar,arg[iarg+1]); + idvar = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"property") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal group command"); @@ -81,9 +74,7 @@ idregion(nullptr), idvar(nullptr), idprop(nullptr) error->all(FLERR,"Per atom property for group dynamic does not exist"); propflag = 1; delete [] idprop; - int n = strlen(arg[iarg+1]) + 1; - idprop = new char[n]; - strcpy(idprop,arg[iarg+1]); + idprop = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"every") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal group command"); @@ -123,7 +114,7 @@ void FixGroup::init() if (group->dynamic[igroup]) error->all(FLERR,"Group dynamic parent group cannot be dynamic"); - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; // set current indices for region and variable diff --git a/src/fix_nh.cpp b/src/fix_nh.cpp index 49a469d296..120aeeb7de 100644 --- a/src/fix_nh.cpp +++ b/src/fix_nh.cpp @@ -275,9 +275,7 @@ FixNH::FixNH(LAMMPS *lmp, int narg, char **arg) : else { allremap = 0; delete [] id_dilate; - int n = strlen(arg[iarg+1]) + 1; - id_dilate = new char[n]; - strcpy(id_dilate,arg[iarg+1]); + id_dilate = utils::strdup(arg[iarg+1]); int idilate = group->find(id_dilate); if (idilate == -1) error->all(FLERR,"Fix nvt/npt/nph dilate group ID does not exist"); @@ -1414,9 +1412,7 @@ int FixNH::modify_param(int narg, char **arg) tcomputeflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) @@ -1448,9 +1444,7 @@ int FixNH::modify_param(int narg, char **arg) pcomputeflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/fix_press_berendsen.cpp b/src/fix_press_berendsen.cpp index d83262e9dd..d929ca6f28 100644 --- a/src/fix_press_berendsen.cpp +++ b/src/fix_press_berendsen.cpp @@ -467,9 +467,7 @@ int FixPressBerendsen::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify temperature ID"); @@ -496,9 +494,7 @@ int FixPressBerendsen::modify_param(int narg, char **arg) pflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/fix_spring.cpp b/src/fix_spring.cpp index 4bbaf594bd..89d569fc8b 100644 --- a/src/fix_spring.cpp +++ b/src/fix_spring.cpp @@ -70,9 +70,7 @@ FixSpring::FixSpring(LAMMPS *lmp, int narg, char **arg) : if (narg != 10) error->all(FLERR,"Illegal fix spring command"); styleflag = COUPLE; - int n = strlen(arg[4]) + 1; - group2 = new char[n]; - strcpy(group2,arg[4]); + group2 = utils::strdup(arg[4]); igroup2 = group->find(arg[4]); if (igroup2 == -1) error->all(FLERR,"Fix spring couple group ID does not exist"); diff --git a/src/fix_spring_chunk.cpp b/src/fix_spring_chunk.cpp index 9ae4ee4632..8eb35e74aa 100644 --- a/src/fix_spring_chunk.cpp +++ b/src/fix_spring_chunk.cpp @@ -49,13 +49,8 @@ FixSpringChunk::FixSpringChunk(LAMMPS *lmp, int narg, char **arg) : k_spring = utils::numeric(FLERR,arg[3],false,lmp); - int n = strlen(arg[4]) + 1; - idchunk = new char[n]; - strcpy(idchunk,arg[4]); - - n = strlen(arg[5]) + 1; - idcom = new char[n]; - strcpy(idcom,arg[5]); + idchunk = utils::strdup(arg[4]); + idcom = utils::strdup(arg[5]); esprings = 0.0; nchunk = 0; diff --git a/src/fix_temp_berendsen.cpp b/src/fix_temp_berendsen.cpp index f951975937..39b8a5fefd 100644 --- a/src/fix_temp_berendsen.cpp +++ b/src/fix_temp_berendsen.cpp @@ -205,9 +205,7 @@ int FixTempBerendsen::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/fix_temp_csld.cpp b/src/fix_temp_csld.cpp index 2ee2044639..787b4dd34e 100644 --- a/src/fix_temp_csld.cpp +++ b/src/fix_temp_csld.cpp @@ -261,9 +261,7 @@ int FixTempCSLD::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/fix_temp_csvr.cpp b/src/fix_temp_csvr.cpp index cdce9175d6..525cf5b74a 100644 --- a/src/fix_temp_csvr.cpp +++ b/src/fix_temp_csvr.cpp @@ -216,9 +216,7 @@ int FixTempCSVR::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/fix_temp_rescale.cpp b/src/fix_temp_rescale.cpp index fa4c87a256..b57f6c238c 100644 --- a/src/fix_temp_rescale.cpp +++ b/src/fix_temp_rescale.cpp @@ -202,9 +202,7 @@ int FixTempRescale::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/fix_wall_region.cpp b/src/fix_wall_region.cpp index 4d976373a5..7e30fe2361 100644 --- a/src/fix_wall_region.cpp +++ b/src/fix_wall_region.cpp @@ -54,9 +54,7 @@ FixWallRegion::FixWallRegion(LAMMPS *lmp, int narg, char **arg) : iregion = domain->find_region(arg[3]); if (iregion == -1) error->all(FLERR,"Region ID for fix wall/region does not exist"); - int n = strlen(arg[3]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[3]); + idregion = utils::strdup(arg[3]); if (strcmp(arg[4],"lj93") == 0) style = LJ93; else if (strcmp(arg[4],"lj126") == 0) style = LJ126; From 2e7e5aeac4b90ad13d034c34771e170863ad532e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 19 Mar 2021 10:04:28 -0400 Subject: [PATCH 096/257] make fix gcmc and fix widom compatible with USER-INTEL this fixes #2672 --- src/MC/fix_gcmc.cpp | 2 ++ src/MC/fix_widom.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index e8087f1344..b8eecf95ca 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -2330,7 +2330,9 @@ double FixGCMC::energy_full() // unlike Verlet, not performing a reverse_comm() or forces here // b/c GCMC does not care about forces // don't think it will mess up energy due to any post_force() fixes + // but Modify::pre_reverse() is needed for USER-INTEL + if (modify->n_pre_reverse) modify->pre_reverse(eflag,vflag); if (modify->n_post_force) modify->post_force(vflag); if (modify->n_end_of_step) modify->end_of_step(); diff --git a/src/MC/fix_widom.cpp b/src/MC/fix_widom.cpp index 4a06dbafbd..a1bdc32515 100644 --- a/src/MC/fix_widom.cpp +++ b/src/MC/fix_widom.cpp @@ -1057,7 +1057,9 @@ double FixWidom::energy_full() // unlike Verlet, not performing a reverse_comm() or forces here // b/c Widom does not care about forces // don't think it will mess up energy due to any post_force() fixes + // but Modify::pre_reverse() is needed for USER-INTEL + if (modify->n_pre_reverse) modify->pre_reverse(eflag,vflag); if (modify->n_pre_force) modify->pre_force(vflag); if (modify->n_end_of_step) modify->end_of_step(); From b9bc226e391b7e35f412a2813507979f11a685cb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 19 Mar 2021 10:06:02 -0400 Subject: [PATCH 097/257] save style names alongside the classes when using read_data nocoeff this fixes #2673 --- src/neighbor.cpp | 3 ++- src/read_data.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/neighbor.cpp b/src/neighbor.cpp index a76bf78c24..0055678f41 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -1479,7 +1479,8 @@ void Neighbor::print_pairwise_info() rq = requests[i]; if (rq->pair) { char *pname = force->pair_match_ptr((Pair *) rq->requestor); - out += fmt::format(" ({}) pair {}",i+1,pname); + if (pname) out += fmt::format(" ({}) pair {}",i+1,pname); + else out += fmt::format(" ({}) pair (none)",i+1); } else if (rq->fix) { out += fmt::format(" ({}) fix {}",i+1,((Fix *) rq->requestor)->style); } else if (rq->compute) { diff --git a/src/read_data.cpp b/src/read_data.cpp index 1d8b7a516a..90aafd4b98 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -337,6 +337,12 @@ void ReadData::command(int narg, char **arg) Dihedral *saved_dihedral = nullptr; Improper *saved_improper = nullptr; KSpace *saved_kspace = nullptr; + char *saved_pair_style = nullptr; + char *saved_bond_style = nullptr; + char *saved_angle_style = nullptr; + char *saved_dihedral_style = nullptr; + char *saved_improper_style = nullptr; + char *saved_kspace_style = nullptr; if (coeffflag == 0) { char *coeffs[2]; @@ -344,33 +350,45 @@ void ReadData::command(int narg, char **arg) coeffs[1] = (char *) "nocoeff"; saved_pair = force->pair; + saved_pair_style = force->pair_style; force->pair = nullptr; + force->pair_style = nullptr; force->create_pair("zero",0); if (force->pair) force->pair->settings(2,coeffs); coeffs[0] = coeffs[1]; saved_bond = force->bond; + saved_bond_style = force->bond_style; force->bond = nullptr; + force->bond_style = nullptr; force->create_bond("zero",0); if (force->bond) force->bond->settings(1,coeffs); saved_angle = force->angle; + saved_angle_style = force->angle_style; force->angle = nullptr; + force->angle_style = nullptr; force->create_angle("zero",0); if (force->angle) force->angle->settings(1,coeffs); saved_dihedral = force->dihedral; + saved_dihedral_style = force->dihedral_style; force->dihedral = nullptr; + force->dihedral_style = nullptr; force->create_dihedral("zero",0); if (force->dihedral) force->dihedral->settings(1,coeffs); saved_improper = force->improper; + saved_improper_style = force->improper_style; force->improper = nullptr; + force->improper_style = nullptr; force->create_improper("zero",0); if (force->improper) force->improper->settings(1,coeffs); saved_kspace = force->kspace; + saved_kspace_style = force->kspace_style; force->kspace = nullptr; + force->kspace_style = nullptr; } // ----------------------------------------------------------------- @@ -873,20 +891,26 @@ void ReadData::command(int narg, char **arg) if (coeffflag == 0) { if (force->pair) delete force->pair; force->pair = saved_pair; + force->pair_style = saved_pair_style; if (force->bond) delete force->bond; force->bond = saved_bond; + force->bond_style = saved_bond_style; if (force->angle) delete force->angle; force->angle = saved_angle; + force->angle_style = saved_angle_style; if (force->dihedral) delete force->dihedral; force->dihedral = saved_dihedral; + force->dihedral_style = saved_dihedral_style; if (force->improper) delete force->improper; force->improper = saved_improper; + force->improper_style = saved_improper_style; force->kspace = saved_kspace; + force->kspace_style = saved_kspace_style; } // total time From ca102e4920ac288539a6908555765d9d0285f52c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 19 Mar 2021 11:20:32 -0400 Subject: [PATCH 098/257] remove dead code --- src/tokenizer.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 18ed64e0ac..8467d07b95 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -201,7 +201,6 @@ std::string ValueTokenizer::next_string() { std::string value = tokens.next(); return value; } throw TokenizerException("Not enough tokens",""); - return ""; } /*! Retrieve next token and convert to int @@ -217,7 +216,6 @@ int ValueTokenizer::next_int() { int value = atoi(current.c_str()); return value; } throw TokenizerException("Not enough tokens",""); - return 0; } /*! Retrieve next token and convert to bigint @@ -233,7 +231,6 @@ bigint ValueTokenizer::next_bigint() { bigint value = ATOBIGINT(current.c_str()); return value; } throw TokenizerException("Not enough tokens",""); - return 0; } /*! Retrieve next token and convert to tagint @@ -249,7 +246,6 @@ tagint ValueTokenizer::next_tagint() { tagint value = ATOTAGINT(current.c_str()); return value; } throw TokenizerException("Not enough tokens",""); - return 0; } /*! Retrieve next token and convert to double @@ -265,7 +261,6 @@ double ValueTokenizer::next_double() { double value = atof(current.c_str()); return value; } throw TokenizerException("Not enough tokens",""); - return 0.0; } /*! Skip over a given number of tokens From 154b8cb4012653787d19b3c4ef40b76b2c91de7f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 19 Mar 2021 11:33:32 -0400 Subject: [PATCH 099/257] remove dead code --- src/USER-OMP/pair_comb_omp.cpp | 8 ++++---- unittest/commands/test_reset_ids.cpp | 4 ---- unittest/force-styles/test_angle_style.cpp | 2 -- unittest/force-styles/test_bond_style.cpp | 2 -- unittest/force-styles/test_dihedral_style.cpp | 2 -- unittest/force-styles/test_improper_style.cpp | 2 -- unittest/force-styles/test_pair_style.cpp | 2 -- 7 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/USER-OMP/pair_comb_omp.cpp b/src/USER-OMP/pair_comb_omp.cpp index ea8307eda7..cfde8ff905 100644 --- a/src/USER-OMP/pair_comb_omp.cpp +++ b/src/USER-OMP/pair_comb_omp.cpp @@ -88,7 +88,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) int i,j,k,ii,jj,kk,jnum,iparam_i; tagint itag,jtag; int itype,jtype,ktype,iparam_ij,iparam_ijk; - double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,ecoul,fpair; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; double rsq,rsq1,rsq2; double delr1[3],delr2[3],fi[3],fj[3],fk[3]; double zeta_ij,prefactor; @@ -102,7 +102,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) double vionij,fvionij,sr1,sr2,sr3,Eov,Fov; int sht_jnum, *sht_jlist, nj; - evdwl = ecoul = 0.0; + evdwl = 0.0; const double * const * const x = atom->x; double * const * const f = thr->get_f(); @@ -419,7 +419,7 @@ double PairCombOMP::yasu_char(double *qf_fix, int &igroup) #pragma omp parallel for private(ii) LMP_DEFAULT_NONE LMP_SHARED(potal,fac11e) #endif for (ii = 0; ii < inum; ii ++) { - double fqi,fqj,fqij,fqji,fqjj,delr1[3]; + double fqi,fqij,fqji,fqjj,delr1[3]; double sr1,sr2,sr3; int mr1,mr2,mr3; @@ -428,7 +428,7 @@ double PairCombOMP::yasu_char(double *qf_fix, int &igroup) int nj = 0; if (mask[i] & groupbit) { - fqi = fqj = fqij = fqji = fqjj = 0.0; // should not be needed. + fqi = fqij = fqji = fqjj = 0.0; // should not be needed. int itype = map[type[i]]; const double xtmp = x[i][0]; const double ytmp = x[i][1]; diff --git a/unittest/commands/test_reset_ids.cpp b/unittest/commands/test_reset_ids.cpp index 71a68a0a00..3ea2f26cef 100644 --- a/unittest/commands/test_reset_ids.cpp +++ b/unittest/commands/test_reset_ids.cpp @@ -482,8 +482,6 @@ TEST_F(ResetIDsTest, TopologyData) auto num_bond = lmp->atom->num_bond; auto num_angle = lmp->atom->num_angle; - auto num_dihedral = lmp->atom->num_dihedral; - auto num_improper = lmp->atom->num_improper; auto bond_atom = lmp->atom->bond_atom; auto angle_atom1 = lmp->atom->angle_atom1; auto angle_atom2 = lmp->atom->angle_atom2; @@ -568,8 +566,6 @@ TEST_F(ResetIDsTest, TopologyData) num_bond = lmp->atom->num_bond; num_angle = lmp->atom->num_angle; - num_dihedral = lmp->atom->num_dihedral; - num_improper = lmp->atom->num_improper; bond_atom = lmp->atom->bond_atom; angle_atom1 = lmp->atom->angle_atom1; angle_atom2 = lmp->atom->angle_atom2; diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index 833aa69174..7f07052b3d 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -308,7 +308,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); auto f = lmp->atom->f; - auto tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -329,7 +328,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) block.clear(); f = lmp->atom->f; - tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index 0d20a0bb62..a4956006f5 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -308,7 +308,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); auto f = lmp->atom->f; - auto tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -329,7 +328,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) block.clear(); f = lmp->atom->f; - tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index e60968bb0a..6dd6a3f205 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -311,7 +311,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); auto f = lmp->atom->f; - auto tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -332,7 +331,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) block.clear(); f = lmp->atom->f; - tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index 858db0fb65..1b97f38faf 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -302,7 +302,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); auto f = lmp->atom->f; - auto tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -323,7 +322,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) block.clear(); f = lmp->atom->f; - tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index c5d1c1b42a..fd8d306538 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -308,7 +308,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); auto f = lmp->atom->f; - auto tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -332,7 +331,6 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) block.clear(); f = lmp->atom->f; - tag = lmp->atom->tag; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); From 945ecd1f1cdcec1c7d5d0d76bb1aac470c7b8bb0 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 19 Mar 2021 13:23:15 -0400 Subject: [PATCH 100/257] Update kim commands --- python/examples/pylammps/elastic/elastic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/examples/pylammps/elastic/elastic.py b/python/examples/pylammps/elastic/elastic.py index e4cad11736..48f97925da 100644 --- a/python/examples/pylammps/elastic/elastic.py +++ b/python/examples/pylammps/elastic/elastic.py @@ -6,7 +6,7 @@ def potential(lmp, args): """ set up potential and minimization """ ff_string = ' ' ff_string = ff_string.join(args.elements) # merge all element string to one string - lmp.kim_interactions(ff_string) + lmp.kim("interactions", ff_string) # Setup neighbor style lmp.neighbor(1.0, "nsq") @@ -36,7 +36,7 @@ def displace(lmp, args, idir): # Reset box and simulation parameters lmp.clear() lmp.box("tilt large") - lmp.kim_init(args.kim_model, "metal", "unit_conversion_mode") + lmp.kim("init", args.kim_model, "metal", "unit_conversion_mode") lmp.read_restart("restart.equil") lmp.change_box("all triclinic") potential(lmp, args) @@ -83,7 +83,7 @@ def displace(lmp, args, idir): # Reset box and simulation parameters lmp.clear() lmp.box("tilt large") - lmp.kim_init(args.kim_model, "metal", "unit_conversion_mode") + lmp.kim("init", args.kim_model, "metal", "unit_conversion_mode") lmp.read_restart("restart.equil") lmp.change_box("all triclinic") potential(lmp, args) From 5d4614b6260a4a9e7a27f8565326d5c86bc72b21 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 19 Mar 2021 14:10:20 -0400 Subject: [PATCH 101/257] Correct vformat for bigint in dump_custom.cpp --- src/dump_custom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index 53bc9449a0..6f4d7c50b0 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -285,7 +285,7 @@ void DumpCustom::init_style() else if (vtype[i] == Dump::DOUBLE && format_float_user) vformat[i] = utils::strdup(std::string(format_float_user) + " "); else if (vtype[i] == Dump::BIGINT && format_bigint_user) - vformat[i] = utils::strdup(std::string(format_int_user) + " "); + vformat[i] = utils::strdup(std::string(format_bigint_user) + " "); else vformat[i] = utils::strdup(word + " "); // remove trailing blank on last column's format From a33a04a39297bcb38c48ee7f809e76ed9d1fd508 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 19 Mar 2021 14:12:09 -0400 Subject: [PATCH 102/257] Remove redundant has_next() check in Tokenizer --- src/tokenizer.cpp | 70 ++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 8467d07b95..03fe06080b 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -197,70 +197,60 @@ bool ValueTokenizer::contains(const std::string &value) const { * * \return string with next token */ std::string ValueTokenizer::next_string() { - if (has_next()) { - std::string value = tokens.next(); - return value; - } throw TokenizerException("Not enough tokens",""); + std::string value = tokens.next(); + return value; } /*! Retrieve next token and convert to int * * \return value of next token */ int ValueTokenizer::next_int() { - if (has_next()) { - std::string current = tokens.next(); - if (utils::has_utf8(current)) current = utils::utf8_subst(current); - if (!utils::is_integer(current)) { - throw InvalidIntegerException(current); - } - int value = atoi(current.c_str()); - return value; - } throw TokenizerException("Not enough tokens",""); + std::string current = tokens.next(); + if (utils::has_utf8(current)) current = utils::utf8_subst(current); + if (!utils::is_integer(current)) { + throw InvalidIntegerException(current); + } + int value = atoi(current.c_str()); + return value; } /*! Retrieve next token and convert to bigint * * \return value of next token */ bigint ValueTokenizer::next_bigint() { - if (has_next()) { - std::string current = tokens.next(); - if (utils::has_utf8(current)) current = utils::utf8_subst(current); - if (!utils::is_integer(current)) { - throw InvalidIntegerException(current); - } - bigint value = ATOBIGINT(current.c_str()); - return value; - } throw TokenizerException("Not enough tokens",""); + std::string current = tokens.next(); + if (utils::has_utf8(current)) current = utils::utf8_subst(current); + if (!utils::is_integer(current)) { + throw InvalidIntegerException(current); + } + bigint value = ATOBIGINT(current.c_str()); + return value; } /*! Retrieve next token and convert to tagint * * \return value of next token */ tagint ValueTokenizer::next_tagint() { - if (has_next()) { - std::string current = tokens.next(); - if (utils::has_utf8(current)) current = utils::utf8_subst(current); - if (!utils::is_integer(current)) { - throw InvalidIntegerException(current); - } - tagint value = ATOTAGINT(current.c_str()); - return value; - } throw TokenizerException("Not enough tokens",""); + std::string current = tokens.next(); + if (utils::has_utf8(current)) current = utils::utf8_subst(current); + if (!utils::is_integer(current)) { + throw InvalidIntegerException(current); + } + tagint value = ATOTAGINT(current.c_str()); + return value; } /*! Retrieve next token and convert to double * * \return value of next token */ double ValueTokenizer::next_double() { - if (has_next()) { - std::string current = tokens.next(); - if (utils::has_utf8(current)) current = utils::utf8_subst(current); - if (!utils::is_double(current)) { - throw InvalidFloatException(current); - } - double value = atof(current.c_str()); - return value; - } throw TokenizerException("Not enough tokens",""); + std::string current = tokens.next(); + if (utils::has_utf8(current)) current = utils::utf8_subst(current); + if (!utils::is_double(current)) { + throw InvalidFloatException(current); + } + double value = atof(current.c_str()); + return value; } /*! Skip over a given number of tokens From 1f50557b38b232a5bf12c132802a98c44b4d9f33 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 19 Mar 2021 15:33:00 -0400 Subject: [PATCH 103/257] Adopt utils::strdup in dump styles --- src/COMPRESS/dump_atom_gz.cpp | 6 ++--- src/COMPRESS/dump_atom_zstd.cpp | 6 ++--- src/COMPRESS/dump_cfg_gz.cpp | 6 ++--- src/COMPRESS/dump_cfg_zstd.cpp | 6 ++--- src/COMPRESS/dump_custom_gz.cpp | 6 ++--- src/COMPRESS/dump_custom_zstd.cpp | 6 ++--- src/COMPRESS/dump_local_gz.cpp | 6 ++--- src/COMPRESS/dump_local_zstd.cpp | 6 ++--- src/COMPRESS/dump_xyz_gz.cpp | 6 ++--- src/COMPRESS/dump_xyz_zstd.cpp | 6 ++--- src/dump.cpp | 35 ++++++++------------------ src/dump_cfg.cpp | 10 +++----- src/dump_custom.cpp | 41 +++++++++---------------------- src/dump_local.cpp | 8 ++---- src/dump_xyz.cpp | 20 +++++---------- 15 files changed, 52 insertions(+), 122 deletions(-) diff --git a/src/COMPRESS/dump_atom_gz.cpp b/src/COMPRESS/dump_atom_gz.cpp index 7c30d7c101..f252e32064 100644 --- a/src/COMPRESS/dump_atom_gz.cpp +++ b/src/COMPRESS/dump_atom_gz.cpp @@ -77,14 +77,12 @@ void DumpAtomGZ::openfile() *ptr = '*'; if (maxfiles > 0) { if (numfiles < maxfiles) { - nameslist[numfiles] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[numfiles],filecurrent); + nameslist[numfiles] = utils::strdup(filecurrent); ++numfiles; } else { remove(nameslist[fileidx]); delete[] nameslist[fileidx]; - nameslist[fileidx] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[fileidx],filecurrent); + nameslist[fileidx] = utils::strdup(filecurrent); fileidx = (fileidx + 1) % maxfiles; } } diff --git a/src/COMPRESS/dump_atom_zstd.cpp b/src/COMPRESS/dump_atom_zstd.cpp index f51a8b393b..3dde07bbf4 100644 --- a/src/COMPRESS/dump_atom_zstd.cpp +++ b/src/COMPRESS/dump_atom_zstd.cpp @@ -76,14 +76,12 @@ void DumpAtomZstd::openfile() *ptr = '*'; if (maxfiles > 0) { if (numfiles < maxfiles) { - nameslist[numfiles] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[numfiles],filecurrent); + nameslist[numfiles] = utils::strdup(filecurrent); ++numfiles; } else { remove(nameslist[fileidx]); delete[] nameslist[fileidx]; - nameslist[fileidx] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[fileidx],filecurrent); + nameslist[fileidx] = utils::strdup(filecurrent); fileidx = (fileidx + 1) % maxfiles; } } diff --git a/src/COMPRESS/dump_cfg_gz.cpp b/src/COMPRESS/dump_cfg_gz.cpp index 9beb606b24..378baf502f 100644 --- a/src/COMPRESS/dump_cfg_gz.cpp +++ b/src/COMPRESS/dump_cfg_gz.cpp @@ -81,14 +81,12 @@ void DumpCFGGZ::openfile() *ptr = '*'; if (maxfiles > 0) { if (numfiles < maxfiles) { - nameslist[numfiles] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[numfiles],filecurrent); + nameslist[numfiles] = utils::strdup(filecurrent); ++numfiles; } else { remove(nameslist[fileidx]); delete[] nameslist[fileidx]; - nameslist[fileidx] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[fileidx],filecurrent); + nameslist[fileidx] = utils::strdup(filecurrent); fileidx = (fileidx + 1) % maxfiles; } } diff --git a/src/COMPRESS/dump_cfg_zstd.cpp b/src/COMPRESS/dump_cfg_zstd.cpp index 13890334ba..459649c70a 100644 --- a/src/COMPRESS/dump_cfg_zstd.cpp +++ b/src/COMPRESS/dump_cfg_zstd.cpp @@ -79,14 +79,12 @@ void DumpCFGZstd::openfile() *ptr = '*'; if (maxfiles > 0) { if (numfiles < maxfiles) { - nameslist[numfiles] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[numfiles],filecurrent); + nameslist[numfiles] = utils::strdup(filecurrent); ++numfiles; } else { remove(nameslist[fileidx]); delete[] nameslist[fileidx]; - nameslist[fileidx] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[fileidx],filecurrent); + nameslist[fileidx] = utils::strdup(filecurrent); fileidx = (fileidx + 1) % maxfiles; } } diff --git a/src/COMPRESS/dump_custom_gz.cpp b/src/COMPRESS/dump_custom_gz.cpp index f345f4b111..4f03a4a232 100644 --- a/src/COMPRESS/dump_custom_gz.cpp +++ b/src/COMPRESS/dump_custom_gz.cpp @@ -79,14 +79,12 @@ void DumpCustomGZ::openfile() *ptr = '*'; if (maxfiles > 0) { if (numfiles < maxfiles) { - nameslist[numfiles] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[numfiles],filecurrent); + nameslist[numfiles] = utils::strdup(filecurrent); ++numfiles; } else { remove(nameslist[fileidx]); delete[] nameslist[fileidx]; - nameslist[fileidx] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[fileidx],filecurrent); + nameslist[fileidx] = utils::strdup(filecurrent); fileidx = (fileidx + 1) % maxfiles; } } diff --git a/src/COMPRESS/dump_custom_zstd.cpp b/src/COMPRESS/dump_custom_zstd.cpp index 81ace6172f..3aa3f874ea 100644 --- a/src/COMPRESS/dump_custom_zstd.cpp +++ b/src/COMPRESS/dump_custom_zstd.cpp @@ -76,14 +76,12 @@ void DumpCustomZstd::openfile() *ptr = '*'; if (maxfiles > 0) { if (numfiles < maxfiles) { - nameslist[numfiles] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[numfiles],filecurrent); + nameslist[numfiles] = utils::strdup(filecurrent); ++numfiles; } else { remove(nameslist[fileidx]); delete[] nameslist[fileidx]; - nameslist[fileidx] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[fileidx],filecurrent); + nameslist[fileidx] = utils::strdup(filecurrent); fileidx = (fileidx + 1) % maxfiles; } } diff --git a/src/COMPRESS/dump_local_gz.cpp b/src/COMPRESS/dump_local_gz.cpp index e0d2f0d2dd..e8065a848a 100644 --- a/src/COMPRESS/dump_local_gz.cpp +++ b/src/COMPRESS/dump_local_gz.cpp @@ -79,14 +79,12 @@ void DumpLocalGZ::openfile() *ptr = '*'; if (maxfiles > 0) { if (numfiles < maxfiles) { - nameslist[numfiles] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[numfiles],filecurrent); + nameslist[numfiles] = utils::strdup(filecurrent); ++numfiles; } else { remove(nameslist[fileidx]); delete[] nameslist[fileidx]; - nameslist[fileidx] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[fileidx],filecurrent); + nameslist[fileidx] = utils::strdup(filecurrent); fileidx = (fileidx + 1) % maxfiles; } } diff --git a/src/COMPRESS/dump_local_zstd.cpp b/src/COMPRESS/dump_local_zstd.cpp index c03670ffba..d26555d282 100644 --- a/src/COMPRESS/dump_local_zstd.cpp +++ b/src/COMPRESS/dump_local_zstd.cpp @@ -78,14 +78,12 @@ void DumpLocalZstd::openfile() *ptr = '*'; if (maxfiles > 0) { if (numfiles < maxfiles) { - nameslist[numfiles] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[numfiles],filecurrent); + nameslist[numfiles] = utils::strdup(filecurrent); ++numfiles; } else { remove(nameslist[fileidx]); delete[] nameslist[fileidx]; - nameslist[fileidx] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[fileidx],filecurrent); + nameslist[fileidx] = utils::strdup(filecurrent); fileidx = (fileidx + 1) % maxfiles; } } diff --git a/src/COMPRESS/dump_xyz_gz.cpp b/src/COMPRESS/dump_xyz_gz.cpp index 21a55f6b07..c63d354e80 100644 --- a/src/COMPRESS/dump_xyz_gz.cpp +++ b/src/COMPRESS/dump_xyz_gz.cpp @@ -78,14 +78,12 @@ void DumpXYZGZ::openfile() *ptr = '*'; if (maxfiles > 0) { if (numfiles < maxfiles) { - nameslist[numfiles] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[numfiles],filecurrent); + nameslist[numfiles] = utils::strdup(filecurrent); ++numfiles; } else { remove(nameslist[fileidx]); delete[] nameslist[fileidx]; - nameslist[fileidx] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[fileidx],filecurrent); + nameslist[fileidx] = utils::strdup(filecurrent); fileidx = (fileidx + 1) % maxfiles; } } diff --git a/src/COMPRESS/dump_xyz_zstd.cpp b/src/COMPRESS/dump_xyz_zstd.cpp index 9c220bdca7..7c5b73d0ba 100644 --- a/src/COMPRESS/dump_xyz_zstd.cpp +++ b/src/COMPRESS/dump_xyz_zstd.cpp @@ -76,14 +76,12 @@ void DumpXYZZstd::openfile() *ptr = '*'; if (maxfiles > 0) { if (numfiles < maxfiles) { - nameslist[numfiles] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[numfiles],filecurrent); + nameslist[numfiles] = utils::strdup(filecurrent); ++numfiles; } else { remove(nameslist[fileidx]); delete[] nameslist[fileidx]; - nameslist[fileidx] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[fileidx],filecurrent); + nameslist[fileidx] = utils::strdup(filecurrent); fileidx = (fileidx + 1) % maxfiles; } } diff --git a/src/dump.cpp b/src/dump.cpp index ab2a84ab22..031364dada 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -46,20 +46,14 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp) MPI_Comm_rank(world,&me); MPI_Comm_size(world,&nprocs); - int n = strlen(arg[0]) + 1; - id = new char[n]; - strcpy(id,arg[0]); + id = utils::strdup(arg[0]); igroup = group->find(arg[1]); groupbit = group->bitmask[igroup]; - n = strlen(arg[2]) + 1; - style = new char[n]; - strcpy(style,arg[2]); + style = utils::strdup(arg[2]); - n = strlen(arg[4]) + 1; - filename = new char[n]; - strcpy(filename,arg[4]); + filename = utils::strdup(arg[4]); comm_forward = comm_reverse = 0; @@ -140,9 +134,8 @@ Dump::Dump(LAMMPS *lmp, int /*narg*/, char **arg) : Pointers(lmp) filewriter = 1; fileproc = me; MPI_Comm_split(world,me,0,&clustercomm); - multiname = new char[strlen(filename) + 16]; *ptr = '\0'; - sprintf(multiname,"%s%d%s",filename,me,ptr+1); + multiname = utils::strdup(fmt::format("{}{}{}", filename, me, ptr+1)); *ptr = '%'; } @@ -573,14 +566,12 @@ void Dump::openfile() *ptr = '*'; if (maxfiles > 0) { if (numfiles < maxfiles) { - nameslist[numfiles] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[numfiles],filecurrent); + nameslist[numfiles] = utils::strdup(filecurrent); ++numfiles; } else { remove(nameslist[fileidx]); delete[] nameslist[fileidx]; - nameslist[fileidx] = new char[strlen(filecurrent)+1]; - strcpy(nameslist[fileidx],filecurrent); + nameslist[fileidx] = utils::strdup(filecurrent); fileidx = (fileidx + 1) % maxfiles; } } @@ -952,9 +943,7 @@ void Dump::modify_params(int narg, char **arg) int n; if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) { delete [] output->var_dump[idump]; - n = strlen(&arg[iarg+1][2]) + 1; - output->var_dump[idump] = new char[n]; - strcpy(output->var_dump[idump],&arg[iarg+1][2]); + output->var_dump[idump] = utils::strdup(&arg[iarg+1][2]); n = 0; } else { n = utils::inumeric(FLERR,arg[iarg+1],false,lmp); @@ -984,10 +973,9 @@ void Dump::modify_params(int narg, char **arg) MPI_Comm_split(world,icluster,0,&clustercomm); delete [] multiname; - multiname = new char[strlen(filename) + 16]; char *ptr = strchr(filename,'%'); *ptr = '\0'; - sprintf(multiname,"%s%d%s",filename,icluster,ptr+1); + multiname = utils::strdup(fmt::format("{}{}{}", filename, icluster, ptr+1)); *ptr = '%'; iarg += 2; @@ -1028,9 +1016,7 @@ void Dump::modify_params(int narg, char **arg) if (strcmp(arg[iarg+1],"line") == 0) { delete [] format_line_user; - int n = strlen(arg[iarg+2]) + 1; - format_line_user = new char[n]; - strcpy(format_line_user,arg[iarg+2]); + format_line_user = utils::strdup(arg[iarg+2]); iarg += 3; } else { // pass other format options to child classes int n = modify_param(narg-iarg,&arg[iarg]); @@ -1085,10 +1071,9 @@ void Dump::modify_params(int narg, char **arg) MPI_Comm_split(world,icluster,0,&clustercomm); delete [] multiname; - multiname = new char[strlen(filename) + 16]; char *ptr = strchr(filename,'%'); *ptr = '\0'; - sprintf(multiname,"%s%d%s",filename,icluster,ptr+1); + multiname = utils::strdup(fmt::format("{}{}{}", filename, icluster, ptr+1)); *ptr = '%'; iarg += 2; diff --git a/src/dump_cfg.cpp b/src/dump_cfg.cpp index b4e6af90cf..0ff32720d4 100644 --- a/src/dump_cfg.cpp +++ b/src/dump_cfg.cpp @@ -74,14 +74,10 @@ DumpCFG::DumpCFG(LAMMPS *lmp, int narg, char **arg) : |ArgInfo::DNAME|ArgInfo::INAME); if (argi.get_dim() == 1) { - std::string newarg(std::to_string(earg[iarg][0])); - newarg += std::string("_") + argi.get_name(); - newarg += std::string("_") + std::to_string(argi.get_index1()); - auxname[i] = new char[newarg.size()+1]; - strcpy(auxname[i],newarg.c_str()); + std::string newarg = fmt::format("{}_{}_{}", earg[iarg][0], argi.get_name(), argi.get_index1()); + auxname[i] = utils::strdup(newarg); } else { - auxname[i] = new char[strlen(earg[iarg]) + 1]; - strcpy(auxname[i],earg[iarg]); + auxname[i] = utils::strdup(earg[iarg]); } } } diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index 6f4d7c50b0..53094849ac 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -1562,9 +1562,7 @@ int DumpCustom::add_compute(const char *id) delete [] compute; compute = new Compute*[ncompute+1]; - int n = strlen(id) + 1; - id_compute[ncompute] = new char[n]; - strcpy(id_compute[ncompute],id); + id_compute[ncompute] = utils::strdup(id); ncompute++; return ncompute-1; } @@ -1587,9 +1585,7 @@ int DumpCustom::add_fix(const char *id) delete [] fix; fix = new Fix*[nfix+1]; - int n = strlen(id) + 1; - id_fix[nfix] = new char[n]; - strcpy(id_fix[nfix],id); + id_fix[nfix] = utils::strdup(id); nfix++; return nfix-1; } @@ -1616,9 +1612,7 @@ int DumpCustom::add_variable(const char *id) vbuf = new double*[nvariable+1]; for (int i = 0; i <= nvariable; i++) vbuf[i] = nullptr; - int n = strlen(id) + 1; - id_variable[nvariable] = new char[n]; - strcpy(id_variable[nvariable],id); + id_variable[nvariable] = utils::strdup(id); nvariable++; return nvariable-1; } @@ -1642,9 +1636,7 @@ int DumpCustom::add_custom(const char *id, int flag) flag_custom = (int *) memory->srealloc(flag_custom,(ncustom+1)*sizeof(int),"dump:flag_custom"); - int n = strlen(id) + 1; - id_custom[ncustom] = new char[n]; - strcpy(id_custom[ncustom],id); + id_custom[ncustom] = utils::strdup(id); flag_custom[ncustom] = flag; ncustom++; @@ -1663,9 +1655,7 @@ int DumpCustom::modify_param(int narg, char **arg) if (iregion == -1) error->all(FLERR,"Dump_modify region ID does not exist"); delete [] idregion; - int n = strlen(arg[1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[1]); + idregion = utils::strdup(arg[1]); } return 2; } @@ -1686,11 +1676,9 @@ int DumpCustom::modify_param(int narg, char **arg) if (strcmp(arg[1],"int") == 0) { delete [] format_int_user; - int n = strlen(arg[2]) + 1; - format_int_user = new char[n]; - strcpy(format_int_user,arg[2]); + format_int_user = utils::strdup(arg[2]); delete [] format_bigint_user; - n = strlen(format_int_user) + 8; + int n = strlen(format_int_user) + 8; format_bigint_user = new char[n]; // replace "d" in format_int_user with bigint format specifier // use of &str[1] removes leading '%' from BIGINT_FORMAT string @@ -1706,18 +1694,14 @@ int DumpCustom::modify_param(int narg, char **arg) } else if (strcmp(arg[1],"float") == 0) { delete [] format_float_user; - int n = strlen(arg[2]) + 1; - format_float_user = new char[n]; - strcpy(format_float_user,arg[2]); + format_float_user = utils::strdup(arg[2]); } else { int i = utils::inumeric(FLERR,arg[1],false,lmp) - 1; if (i < 0 || i >= nfield) error->all(FLERR,"Illegal dump_modify command"); if (format_column_user[i]) delete [] format_column_user[i]; - int n = strlen(arg[2]) + 1; - format_column_user[i] = new char[n]; - strcpy(format_column_user[i],arg[2]); + format_column_user[i] = utils::strdup(arg[2]); } return 3; } @@ -1730,9 +1714,7 @@ int DumpCustom::modify_param(int narg, char **arg) delete [] typenames; typenames = new char*[ntypes+1]; for (int itype = 1; itype <= ntypes; itype++) { - int n = strlen(arg[itype]) + 1; - typenames[itype] = new char[n]; - strcpy(typenames[itype],arg[itype]); + typenames[itype] = utils::strdup(arg[itype]); } return ntypes+1; } @@ -1998,8 +1980,7 @@ int DumpCustom::modify_param(int narg, char **arg) memory->grow(thresh_first,(nthreshlast+1),"dump:thresh_first"); std::string threshid = fmt::format("{}{}_DUMP_STORE",id,nthreshlast); - thresh_fixID[nthreshlast] = new char[threshid.size()+1]; - strcpy(thresh_fixID[nthreshlast],threshid.c_str()); + thresh_fixID[nthreshlast] = utils::strdup(threshid); modify->add_fix(fmt::format("{} {} STORE peratom 1 1",threshid, group->names[igroup])); thresh_fix[nthreshlast] = (FixStore *) modify->fix[modify->nfix-1]; diff --git a/src/dump_local.cpp b/src/dump_local.cpp index beb9236d63..53a82b496f 100644 --- a/src/dump_local.cpp +++ b/src/dump_local.cpp @@ -472,9 +472,7 @@ int DumpLocal::add_compute(const char *id) delete [] compute; compute = new Compute*[ncompute+1]; - int n = strlen(id) + 1; - id_compute[ncompute] = new char[n]; - strcpy(id_compute[ncompute],id); + id_compute[ncompute] = utils::strdup(id); ncompute++; return ncompute-1; } @@ -497,9 +495,7 @@ int DumpLocal::add_fix(const char *id) delete [] fix; fix = new Fix*[nfix+1]; - int n = strlen(id) + 1; - id_fix[nfix] = new char[n]; - strcpy(id_fix[nfix],id); + id_fix[nfix] = utils::strdup(id); nfix++; return nfix-1; } diff --git a/src/dump_xyz.cpp b/src/dump_xyz.cpp index 108ea6f4d6..5f478a2443 100644 --- a/src/dump_xyz.cpp +++ b/src/dump_xyz.cpp @@ -40,10 +40,7 @@ DumpXYZ::DumpXYZ(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg), if (format_default) delete [] format_default; - char *str = (char *) "%s %g %g %g"; - int n = strlen(str) + 1; - format_default = new char[n]; - strcpy(format_default,str); + format_default = utils::strdup("%s %g %g %g"); ntypes = atom->ntypes; typenames = nullptr; @@ -71,14 +68,11 @@ void DumpXYZ::init_style() // format = copy of default or user-specified line format delete [] format; - char *str; - if (format_line_user) str = format_line_user; - else str = format_default; - int n = strlen(str) + 2; - format = new char[n]; - strcpy(format,str); - strcat(format,"\n"); + if (format_line_user) + format = utils::strdup(fmt::format("{}\n", format_line_user)); + else + format = utils::strdup(fmt::format("{}\n", format_default)); // initialize typenames array to be backward compatible by default // a 32-bit int can be maximally 10 digits plus sign @@ -119,9 +113,7 @@ int DumpXYZ::modify_param(int narg, char **arg) typenames = new char*[ntypes+1]; for (int itype = 1; itype <= ntypes; itype++) { - int n = strlen(arg[itype]) + 1; - typenames[itype] = new char[n]; - strcpy(typenames[itype],arg[itype]); + typenames[itype] = utils::strdup(arg[itype]); } return ntypes+1; From 6503a7c3bab1e5b37ba6680e1e60a5ca0cc7cca1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 19 Mar 2021 15:52:27 -0400 Subject: [PATCH 104/257] skip explicit temporaries --- src/tokenizer.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 03fe06080b..0954a4a4cd 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -197,8 +197,7 @@ bool ValueTokenizer::contains(const std::string &value) const { * * \return string with next token */ std::string ValueTokenizer::next_string() { - std::string value = tokens.next(); - return value; + return tokens.next(); } /*! Retrieve next token and convert to int @@ -210,8 +209,7 @@ int ValueTokenizer::next_int() { if (!utils::is_integer(current)) { throw InvalidIntegerException(current); } - int value = atoi(current.c_str()); - return value; + return atoi(current.c_str()); } /*! Retrieve next token and convert to bigint @@ -223,8 +221,7 @@ bigint ValueTokenizer::next_bigint() { if (!utils::is_integer(current)) { throw InvalidIntegerException(current); } - bigint value = ATOBIGINT(current.c_str()); - return value; + return ATOBIGINT(current.c_str()); } /*! Retrieve next token and convert to tagint @@ -236,8 +233,7 @@ tagint ValueTokenizer::next_tagint() { if (!utils::is_integer(current)) { throw InvalidIntegerException(current); } - tagint value = ATOTAGINT(current.c_str()); - return value; + return ATOTAGINT(current.c_str()); } /*! Retrieve next token and convert to double @@ -249,8 +245,7 @@ double ValueTokenizer::next_double() { if (!utils::is_double(current)) { throw InvalidFloatException(current); } - double value = atof(current.c_str()); - return value; + return atof(current.c_str()); } /*! Skip over a given number of tokens From 9707771f1c50827ea21ebcdc51153b5f0c4844ef Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 19 Mar 2021 16:10:37 -0400 Subject: [PATCH 105/257] apply UTF-8 character replacement before creating tokens --- src/tokenizer.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 0954a4a4cd..d26a5199f9 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -35,12 +35,14 @@ TokenizerException::TokenizerException(const std::string &msg, const std::string /** Class for splitting text into words * * This tokenizer will break down a string into sub-strings (i.e words) - * separated by the given separator characters. + * separated by the given separator characters. If the string contains + * certain known UTF-8 characters they will be replaced by their ASCII + * equivalents processing the string. * \verbatim embed:rst *See also* - :cpp:class:`ValueTokenizer`, :cpp:func:`utils::split_words` + :cpp:class:`ValueTokenizer`, :cpp:func:`utils::split_words`, :cpp:func:`utils::utf8_subst` \endverbatim * @@ -50,6 +52,8 @@ TokenizerException::TokenizerException(const std::string &msg, const std::string Tokenizer::Tokenizer(const std::string &str, const std::string &separators) : text(str), separators(separators), start(0), ntokens(std::string::npos) { + // replace known UTF-8 characters with ASCII equivalents + if (utils::has_utf8(text)) text = utils::utf8_subst(text); reset(); } @@ -205,7 +209,6 @@ std::string ValueTokenizer::next_string() { * \return value of next token */ int ValueTokenizer::next_int() { std::string current = tokens.next(); - if (utils::has_utf8(current)) current = utils::utf8_subst(current); if (!utils::is_integer(current)) { throw InvalidIntegerException(current); } @@ -217,7 +220,6 @@ int ValueTokenizer::next_int() { * \return value of next token */ bigint ValueTokenizer::next_bigint() { std::string current = tokens.next(); - if (utils::has_utf8(current)) current = utils::utf8_subst(current); if (!utils::is_integer(current)) { throw InvalidIntegerException(current); } @@ -229,7 +231,6 @@ bigint ValueTokenizer::next_bigint() { * \return value of next token */ tagint ValueTokenizer::next_tagint() { std::string current = tokens.next(); - if (utils::has_utf8(current)) current = utils::utf8_subst(current); if (!utils::is_integer(current)) { throw InvalidIntegerException(current); } @@ -241,7 +242,6 @@ tagint ValueTokenizer::next_tagint() { * \return value of next token */ double ValueTokenizer::next_double() { std::string current = tokens.next(); - if (utils::has_utf8(current)) current = utils::utf8_subst(current); if (!utils::is_double(current)) { throw InvalidFloatException(current); } From 4269eeeef7fadc8e9f53dd4efd58afb793778356 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Fri, 19 Mar 2021 17:22:40 -0400 Subject: [PATCH 106/257] Optimize quadratic Kokkos SNAP, pointed out by @weinbe2 --- src/KOKKOS/pair_snap_kokkos.h | 4 +++ src/KOKKOS/pair_snap_kokkos_impl.h | 31 ++++++++++++----- src/KOKKOS/sna_kokkos.h | 3 ++ src/KOKKOS/sna_kokkos_impl.h | 53 ++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 8 deletions(-) diff --git a/src/KOKKOS/pair_snap_kokkos.h b/src/KOKKOS/pair_snap_kokkos.h index 9acf3011ce..b792b85e2b 100644 --- a/src/KOKKOS/pair_snap_kokkos.h +++ b/src/KOKKOS/pair_snap_kokkos.h @@ -50,6 +50,7 @@ struct TagPairSNAPBeta{}; struct TagPairSNAPComputeBi{}; struct TagPairSNAPTransformBi{}; // re-order blist from AoSoA to AoS struct TagPairSNAPComputeYi{}; +struct TagPairSNAPComputeYiWithZlist{}; template struct TagPairSNAPComputeFusedDeidrj{}; @@ -161,6 +162,9 @@ public: KOKKOS_INLINE_FUNCTION void operator() (TagPairSNAPComputeYi,const int iatom_mod, const int idxz, const int iatom_div) const; + KOKKOS_INLINE_FUNCTION + void operator() (TagPairSNAPComputeYiWithZlist,const int iatom_mod, const int idxz, const int iatom_div) const; + template KOKKOS_INLINE_FUNCTION void operator() (TagPairSNAPComputeFusedDeidrj,const typename Kokkos::TeamPolicy >::member_type& team) const; diff --git a/src/KOKKOS/pair_snap_kokkos_impl.h b/src/KOKKOS/pair_snap_kokkos_impl.h index 2578f3d47c..3ccc5cec36 100644 --- a/src/KOKKOS/pair_snap_kokkos_impl.h +++ b/src/KOKKOS/pair_snap_kokkos_impl.h @@ -373,16 +373,18 @@ void PairSNAPKokkos::compute(int eflag_in, //Compute beta = dE_i/dB_i for all i in list typename Kokkos::RangePolicy policy_beta(0,chunk_size); Kokkos::parallel_for("ComputeBeta",policy_beta,*this); - - //ComputeYi - // team_size_compute_yi is defined in `pair_snap_kokkos.h` const int idxz_max = snaKK.idxz_max; - Snap3DRangePolicy - policy_compute_yi({0,0,0},{vector_length,idxz_max,chunk_size_div},{vector_length,tile_size_compute_yi,1}); - Kokkos::parallel_for("ComputeYi",policy_compute_yi,*this); - + if (quadraticflag || eflag) { + Snap3DRangePolicy + policy_compute_yi({0,0,0},{vector_length,idxz_max,chunk_size_div},{vector_length,tile_size_compute_yi,1}); + Kokkos::parallel_for("ComputeYiWithZlist",policy_compute_yi,*this); + } else { + Snap3DRangePolicy + policy_compute_yi({0,0,0},{vector_length,idxz_max,chunk_size_div},{vector_length,tile_size_compute_yi,1}); + Kokkos::parallel_for("ComputeYi",policy_compute_yi,*this); + } } - + // Fused ComputeDuidrj, ComputeDeidrj { // team_size_compute_fused_deidrj is defined in `pair_snap_kokkos.h` @@ -796,6 +798,19 @@ void PairSNAPKokkos::operator() (TagPairSN my_sna.compute_yi(iatom_mod,jjz,iatom_div,d_beta_pack); } +template +KOKKOS_INLINE_FUNCTION +void PairSNAPKokkos::operator() (TagPairSNAPComputeYiWithZlist,const int iatom_mod, const int jjz, const int iatom_div) const { + SNAKokkos my_sna = snaKK; + + const int iatom = iatom_mod + iatom_div * vector_length; + if (iatom >= chunk_size) return; + + if (jjz >= my_sna.idxz_max) return; + + my_sna.compute_yi_with_zlist(iatom_mod,jjz,iatom_div,d_beta_pack); +} + template KOKKOS_INLINE_FUNCTION void PairSNAPKokkos::operator() (TagPairSNAPComputeZi,const int iatom_mod, const int jjz, const int iatom_div) const { diff --git a/src/KOKKOS/sna_kokkos.h b/src/KOKKOS/sna_kokkos.h index 55983f2a90..33ef37ca98 100644 --- a/src/KOKKOS/sna_kokkos.h +++ b/src/KOKKOS/sna_kokkos.h @@ -125,6 +125,9 @@ inline void compute_yi(int,int,int, const Kokkos::View &beta_pack); // ForceSNAP KOKKOS_INLINE_FUNCTION + void compute_yi_with_zlist(int,int,int, + const Kokkos::View &beta_pack); // ForceSNAP + KOKKOS_INLINE_FUNCTION void compute_bi(const int&, const int&, const int&); // ForceSNAP // functions for bispectrum coefficients, CPU only diff --git a/src/KOKKOS/sna_kokkos_impl.h b/src/KOKKOS/sna_kokkos_impl.h index 2a44f943d3..2b55f97c30 100644 --- a/src/KOKKOS/sna_kokkos_impl.h +++ b/src/KOKKOS/sna_kokkos_impl.h @@ -880,6 +880,59 @@ void SNAKokkos::compute_yi(int iatom_mod, } // end loop over elem1 } +/* ---------------------------------------------------------------------- + compute Yi from Ui without storing Zi, looping over zlist indices. + AoSoA data layout to take advantage of coalescing, avoiding warp + divergence. GPU version. +------------------------------------------------------------------------- */ + +template +KOKKOS_INLINE_FUNCTION +void SNAKokkos::compute_yi_with_zlist(int iatom_mod, int jjz, int iatom_div, + const Kokkos::View &beta_pack) +{ + real_type betaj; + const int j1 = idxz(jjz, 0); + const int j2 = idxz(jjz, 1); + const int j = idxz(jjz, 2); + const int jju_half = idxz(jjz, 9); + int idouble = 0; + for (int elem1 = 0; elem1 < nelements; elem1++) { + for (int elem2 = 0; elem2 < nelements; elem2++) { + auto ztmp = zlist_pack(iatom_mod,jjz,idouble,iatom_div); + // apply to z(j1,j2,j,ma,mb) to unique element of y(j) + // find right y_list[jju] and beta(iatom,jjb) entries + // multiply and divide by j+1 factors + // account for multiplicity of 1, 2, or 3 + // pick out right beta value + for (int elem3 = 0; elem3 < nelements; elem3++) { + if (j >= j1) { + const int jjb = idxb_block(j1, j2, j); + const auto itriple = ((elem1 * nelements + elem2) * nelements + elem3) * idxb_max + jjb; + if (j1 == j) { + if (j2 == j) betaj = 3 * beta_pack(iatom_mod, itriple, iatom_div); + else betaj = 2 * beta_pack(iatom_mod, itriple, iatom_div); + } else betaj = beta_pack(iatom_mod, itriple, iatom_div); + } else if (j >= j2) { + const int jjb = idxb_block(j, j2, j1); + const auto itriple = ((elem3 * nelements + elem2) * nelements + elem1) * idxb_max + jjb; + if (j2 == j) betaj = 2 * beta_pack(iatom_mod, itriple, iatom_div); + else betaj = beta_pack(iatom_mod, itriple, iatom_div); + } else { + const int jjb = idxb_block(j2, j, j1); + const auto itriple = ((elem2 * nelements + elem3) * nelements + elem1) * idxb_max + jjb; + betaj = beta_pack(iatom_mod, itriple, iatom_div); + } + if (!bnorm_flag && j1 > j) + betaj *= (j1 + 1) / (j + 1.0); + Kokkos::atomic_add(&(ylist_pack_re(iatom_mod, jju_half, elem3, iatom_div)), betaj*ztmp.re); + Kokkos::atomic_add(&(ylist_pack_im(iatom_mod, jju_half, elem3, iatom_div)), betaj*ztmp.im); + } // end loop over elem3 + idouble++; + } // end loop over elem2 + } // end loop over elem1 +} + /* ---------------------------------------------------------------------- Fused calculation of the derivative of Ui w.r.t. atom j and accumulation into dEidRj. GPU only. From 06ee5be2cef23eb23273c7f3fd64ee935178a13b Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 19 Mar 2021 18:51:21 -0400 Subject: [PATCH 107/257] Fix unhandled cases in docs LAMMPS syntax highlighting --- doc/src/fix_rigid_meso.rst | 4 ++-- doc/src/group.rst | 8 ++++---- doc/src/kim_commands.rst | 2 +- doc/utils/sphinx-config/LAMMPSLexer.py | 6 ++++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/doc/src/fix_rigid_meso.rst b/doc/src/fix_rigid_meso.rst index 2acd81a268..dea2354bad 100644 --- a/doc/src/fix_rigid_meso.rst +++ b/doc/src/fix_rigid_meso.rst @@ -48,8 +48,8 @@ Examples fix 1 ellipsoid rigid/meso single fix 1 rods rigid/meso molecule fix 1 spheres rigid/meso single force 1 off off on - fix 1 particles rigid/meso molecule force 1\*5 off off off force 6\*10 off off on - fix 2 spheres rigid/meso group 3 sphere1 sphere2 sphere3 torque \* off off off + fix 1 particles rigid/meso molecule force 1*5 off off off force 6*10 off off on + fix 2 spheres rigid/meso group 3 sphere1 sphere2 sphere3 torque * off off off Description """"""""""" diff --git a/doc/src/group.rst b/doc/src/group.rst index 6371a030ee..3ce885bdc5 100644 --- a/doc/src/group.rst +++ b/doc/src/group.rst @@ -120,12 +120,12 @@ specified atom types, atom IDs, or molecule IDs into the group. These The first format is a list of values (types or IDs). For example, the second command in the examples above puts all atoms of type 3 or 4 into the group named *water*\ . Each entry in the list can be a -colon-separated sequence A:B or A:B:C, as in two of the examples +colon-separated sequence ``A:B`` or ``A:B:C``, as in two of the examples above. A "sequence" generates a sequence of values (types or IDs), -with an optional increment. The first example with 500:1000 has the +with an optional increment. The first example with ``500:1000`` has the default increment of 1 and would add all atom IDs from 500 to 1000 (inclusive) to the group sub, along with 10,25,50 since they also -appear in the list of values. The second example with 100:10000:10 +appear in the list of values. The second example with ``100:10000:10`` uses an increment of 10 and would thus would add atoms IDs 100,110,120, ... 9990,10000 to the group sub. @@ -269,7 +269,7 @@ group and running further. .. code-block:: LAMMPS variable nsteps equal 5000 - variable rad equal 18-(step/v_nsteps)\*(18-5) + variable rad equal 18-(step/v_nsteps)*(18-5) region ss sphere 20 20 0 v_rad group mobile dynamic all region ss fix 1 mobile nve diff --git a/doc/src/kim_commands.rst b/doc/src/kim_commands.rst index 295c6a5e40..f116a70922 100644 --- a/doc/src/kim_commands.rst +++ b/doc/src/kim_commands.rst @@ -1205,7 +1205,7 @@ coordinates of atoms in the unit cell of the cubic crystal. In the case of, e.g. a conventional fcc unit cell, the "source-value" key in the map associated with this key should be assigned the following value: -.. code-block:: LAMMPS +.. code-block:: text [[0.0, 0.0, 0.0], [0.5, 0.5, 0.0], diff --git a/doc/utils/sphinx-config/LAMMPSLexer.py b/doc/utils/sphinx-config/LAMMPSLexer.py index ae40b094c2..6e611f9f74 100644 --- a/doc/utils/sphinx-config/LAMMPSLexer.py +++ b/doc/utils/sphinx-config/LAMMPSLexer.py @@ -40,7 +40,7 @@ class LAMMPSLexer(RegexLexer): (r'compute\s+', Keyword, 'compute'), (r'dump\s+', Keyword, 'dump'), (r'region\s+', Keyword, 'region'), - (r'variable\s+', Keyword, 'variable'), + (r'^\s*variable\s+', Keyword, 'variable_cmd'), (r'group\s+', Keyword, 'group'), (r'change_box\s+', Keyword, 'change_box'), (r'uncompute\s+', Keyword, 'uncompute'), @@ -51,6 +51,7 @@ class LAMMPSLexer(RegexLexer): (r'#.*?\n', Comment), ('"', String, 'string'), ('\'', String, 'single_quote_string'), + (r'[0-9]+:[0-9]+(:[0-9]+)?', Number), (r'[0-9]+(\.[0-9]+)?([eE]\-?[0-9]+)?', Number), ('\$?\(', Name.Variable, 'expression'), ('\$\{', Name.Variable, 'variable'), @@ -58,6 +59,7 @@ class LAMMPSLexer(RegexLexer): (r'\$[\w_]+', Name.Variable), (r'\s+', Whitespace), (r'[\+\-\*\^\|\/\!%&=<>]', Operator), + (r'[\~\.\w_:,@\-\/\\0-9]+', Text), ], 'keywords' : [ (words(LAMMPS_COMMANDS, suffix=r'\b', prefix=r'^'), Keyword) @@ -99,7 +101,7 @@ class LAMMPSLexer(RegexLexer): (r'[\w_\-\.\[\]]+', Name.Variable.Identifier), default('#pop') ], - 'variable' : [ + 'variable_cmd' : [ (r'[\w_\-\.\[\]]+', Name.Variable.Identifier), default('#pop') ], From 012cdf3763f5687bf3044070214942daa126537d Mon Sep 17 00:00:00 2001 From: jrgissing Date: Sat, 20 Mar 2021 16:20:57 -0400 Subject: [PATCH 108/257] performance improvement bugfix --- src/USER-REACTION/fix_bond_react.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/USER-REACTION/fix_bond_react.cpp b/src/USER-REACTION/fix_bond_react.cpp index 91354506d1..46c55f4199 100644 --- a/src/USER-REACTION/fix_bond_react.cpp +++ b/src/USER-REACTION/fix_bond_react.cpp @@ -2566,6 +2566,7 @@ void FixBondReact::unlimit_bond() } // really should only communicate this per-atom property, not entire reneighboring + MPI_Allreduce(MPI_IN_PLACE,&unlimitflag,1,MPI_INT,MPI_MAX,world); if (unlimitflag) next_reneighbor = update->ntimestep; } From b3f465babe387fe8299d50b5bf003e6baf1adbf9 Mon Sep 17 00:00:00 2001 From: jrgissing Date: Sat, 20 Mar 2021 16:34:55 -0400 Subject: [PATCH 109/257] decrease foward_comm nsize due to new placement of probability evaluation --- src/USER-REACTION/fix_bond_react.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/USER-REACTION/fix_bond_react.cpp b/src/USER-REACTION/fix_bond_react.cpp index 46c55f4199..94d1a596f8 100644 --- a/src/USER-REACTION/fix_bond_react.cpp +++ b/src/USER-REACTION/fix_bond_react.cpp @@ -965,7 +965,7 @@ void FixBondReact::post_integrate() // forward comm of partner, so ghosts have it commflag = 2; - comm->forward_comm_fix(this,2); + comm->forward_comm_fix(this,1); // consider for reaction: // only if both atoms list each other as winning bond partner From 2bab4808b62b366a6478cf88a8a8679f8db414b5 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Mon, 22 Mar 2021 08:28:43 -0600 Subject: [PATCH 110/257] Improve memory coalescing in Kokkos snap force computation, pointed out by @weinbe2 --- src/KOKKOS/pair_snap_kokkos.h | 4 +- src/KOKKOS/pair_snap_kokkos_impl.h | 130 ++++++++++++----------------- 2 files changed, 56 insertions(+), 78 deletions(-) diff --git a/src/KOKKOS/pair_snap_kokkos.h b/src/KOKKOS/pair_snap_kokkos.h index b792b85e2b..b7208a577c 100644 --- a/src/KOKKOS/pair_snap_kokkos.h +++ b/src/KOKKOS/pair_snap_kokkos.h @@ -122,11 +122,11 @@ public: template KOKKOS_INLINE_FUNCTION - void operator() (TagPairSNAPComputeForce,const typename Kokkos::TeamPolicy >::member_type& team) const; + void operator() (TagPairSNAPComputeForce,const int& ii) const; template KOKKOS_INLINE_FUNCTION - void operator() (TagPairSNAPComputeForce,const typename Kokkos::TeamPolicy >::member_type& team, EV_FLOAT&) const; + void operator() (TagPairSNAPComputeForce,const int& ii, EV_FLOAT&) const; KOKKOS_INLINE_FUNCTION void operator() (TagPairSNAPBetaCPU,const int& ii) const; diff --git a/src/KOKKOS/pair_snap_kokkos_impl.h b/src/KOKKOS/pair_snap_kokkos_impl.h index 3ccc5cec36..f624131377 100644 --- a/src/KOKKOS/pair_snap_kokkos_impl.h +++ b/src/KOKKOS/pair_snap_kokkos_impl.h @@ -384,7 +384,7 @@ void PairSNAPKokkos::compute(int eflag_in, Kokkos::parallel_for("ComputeYi",policy_compute_yi,*this); } } - + // Fused ComputeDuidrj, ComputeDeidrj { // team_size_compute_fused_deidrj is defined in `pair_snap_kokkos.h` @@ -420,30 +420,21 @@ void PairSNAPKokkos::compute(int eflag_in, //ComputeForce { - int team_size = team_size_default; if (evflag) { if (neighflag == HALF) { - check_team_size_reduce >(chunk_size,team_size); - typename Kokkos::TeamPolicy > policy_force(chunk_size,team_size,vector_length); - Kokkos::parallel_reduce(policy_force - ,*this,ev_tmp); + typename Kokkos::RangePolicy > policy_force(0,chunk_size); + Kokkos::parallel_reduce(policy_force, *this, ev_tmp); } else if (neighflag == HALFTHREAD) { - check_team_size_reduce >(chunk_size,team_size); - typename Kokkos::TeamPolicy > policy_force(chunk_size,team_size,vector_length); - Kokkos::parallel_reduce(policy_force - ,*this,ev_tmp); + typename Kokkos::RangePolicy > policy_force(0,chunk_size); + Kokkos::parallel_reduce(policy_force, *this, ev_tmp); } } else { if (neighflag == HALF) { - check_team_size_for >(chunk_size,team_size); - typename Kokkos::TeamPolicy > policy_force(chunk_size,team_size,vector_length); - Kokkos::parallel_for(policy_force - ,*this); + typename Kokkos::RangePolicy > policy_force(0,chunk_size); + Kokkos::parallel_for(policy_force, *this); } else if (neighflag == HALFTHREAD) { - check_team_size_for >(chunk_size,team_size); - typename Kokkos::TeamPolicy > policy_force(chunk_size,team_size,vector_length); - Kokkos::parallel_for(policy_force - ,*this); + typename Kokkos::RangePolicy > policy_force(0,chunk_size); + Kokkos::parallel_for(policy_force, *this); } } } @@ -1152,20 +1143,19 @@ void PairSNAPKokkos::operator() (TagPairSN template template KOKKOS_INLINE_FUNCTION -void PairSNAPKokkos::operator() (TagPairSNAPComputeForce,const typename Kokkos::TeamPolicy >::member_type& team, EV_FLOAT& ev) const { +void PairSNAPKokkos::operator() (TagPairSNAPComputeForce, const int& ii, EV_FLOAT& ev) const { // The f array is duplicated for OpenMP, atomic for CUDA, and neither for Serial - auto v_f = ScatterViewHelper::value,decltype(dup_f),decltype(ndup_f)>::get(dup_f,ndup_f); auto a_f = v_f.template access::value>(); - int ii = team.league_rank(); const int i = d_ilist[ii + chunk_offset]; + SNAKokkos my_sna = snaKK; + const int ninside = d_ninside(ii); - Kokkos::parallel_for (Kokkos::TeamThreadRange(team,ninside), - [&] (const int jj) { + for (int jj = 0; jj < ninside; jj++) { int j = my_sna.inside(ii,jj); F_FLOAT fij[3]; @@ -1173,28 +1163,23 @@ void PairSNAPKokkos::operator() (TagPairSN fij[1] = my_sna.dedr(ii,jj,1); fij[2] = my_sna.dedr(ii,jj,2); - Kokkos::single(Kokkos::PerThread(team), [&] () { - a_f(i,0) += fij[0]; - a_f(i,1) += fij[1]; - a_f(i,2) += fij[2]; - a_f(j,0) -= fij[0]; - a_f(j,1) -= fij[1]; - a_f(j,2) -= fij[2]; - - // tally global and per-atom virial contribution - - if (EVFLAG) { - if (vflag_either) { - v_tally_xyz(ev,i,j, - fij[0],fij[1],fij[2], - -my_sna.rij(ii,jj,0),-my_sna.rij(ii,jj,1), - -my_sna.rij(ii,jj,2)); - } + a_f(i,0) += fij[0]; + a_f(i,1) += fij[1]; + a_f(i,2) += fij[2]; + a_f(j,0) -= fij[0]; + a_f(j,1) -= fij[1]; + a_f(j,2) -= fij[2]; + // tally global and per-atom virial contribution + if (EVFLAG) { + if (vflag_either) { + v_tally_xyz(ev,i,j, + fij[0],fij[1],fij[2], + -my_sna.rij(ii,jj,0),-my_sna.rij(ii,jj,1), + -my_sna.rij(ii,jj,2)); } + } - }); - }); - + } // tally energy contribution if (EVFLAG) { @@ -1204,48 +1189,41 @@ void PairSNAPKokkos::operator() (TagPairSN const int ielem = d_map[itype]; auto d_coeffi = Kokkos::subview(d_coeffelem, ielem, Kokkos::ALL); - Kokkos::single(Kokkos::PerTeam(team), [&] () { + // evdwl = energy of atom I, sum over coeffs_k * Bi_k - // evdwl = energy of atom I, sum over coeffs_k * Bi_k + auto evdwl = d_coeffi[0]; - auto evdwl = d_coeffi[0]; + // E = beta.B + 0.5*B^t.alpha.B - // E = beta.B + 0.5*B^t.alpha.B + const auto idxb_max = snaKK.idxb_max; - const auto idxb_max = snaKK.idxb_max; + // linear contributions - // linear contributions + for (int icoeff = 0; icoeff < ncoeff; icoeff++) { + const auto idxb = icoeff % idxb_max; + const auto idx_chem = icoeff / idxb_max; + evdwl += d_coeffi[icoeff+1]*my_sna.blist(idxb,idx_chem,ii); + } + // quadratic contributions + if (quadraticflag) { + int k = ncoeff+1; for (int icoeff = 0; icoeff < ncoeff; icoeff++) { const auto idxb = icoeff % idxb_max; const auto idx_chem = icoeff / idxb_max; - evdwl += d_coeffi[icoeff+1]*my_sna.blist(idxb,idx_chem,ii); - } - - // quadratic contributions - - if (quadraticflag) { - int k = ncoeff+1; - for (int icoeff = 0; icoeff < ncoeff; icoeff++) { - const auto idxb = icoeff % idxb_max; - const auto idx_chem = icoeff / idxb_max; - auto bveci = my_sna.blist(idxb,idx_chem,ii); - - evdwl += 0.5*d_coeffi[k++]*bveci*bveci; - for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) { - auto jdxb = jcoeff % idxb_max; - auto jdx_chem = jcoeff / idxb_max; - auto bvecj = my_sna.blist(jdxb,jdx_chem,ii); - - evdwl += d_coeffi[k++]*bveci*bvecj; - } + auto bveci = my_sna.blist(idxb,idx_chem,ii); + evdwl += 0.5*d_coeffi[k++]*bveci*bveci; + for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) { + auto jdxb = jcoeff % idxb_max; + auto jdx_chem = jcoeff / idxb_max; + auto bvecj = my_sna.blist(jdxb,jdx_chem,ii); + evdwl += d_coeffi[k++]*bveci*bvecj; } } - - //ev_tally_full(i,2.0*evdwl,0.0,0.0,0.0,0.0,0.0); - if (eflag_global) ev.evdwl += evdwl; - if (eflag_atom) d_eatom[i] += evdwl; - }); + } + //ev_tally_full(i,2.0*evdwl,0.0,0.0,0.0,0.0,0.0); + if (eflag_global) ev.evdwl += evdwl; + if (eflag_atom) d_eatom[i] += evdwl; } } } @@ -1253,9 +1231,9 @@ void PairSNAPKokkos::operator() (TagPairSN template template KOKKOS_INLINE_FUNCTION -void PairSNAPKokkos::operator() (TagPairSNAPComputeForce,const typename Kokkos::TeamPolicy >::member_type& team) const { +void PairSNAPKokkos::operator() (TagPairSNAPComputeForce,const int& ii) const { EV_FLOAT ev; - this->template operator()(TagPairSNAPComputeForce(), team, ev); + this->template operator()(TagPairSNAPComputeForce(), ii, ev); } /* ---------------------------------------------------------------------- */ From b8f606357842967f84e7dad3c10b871d3fc66e42 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 10:47:49 -0400 Subject: [PATCH 111/257] correct documentation of angle style cosine/periodic --- doc/src/angle_cosine_periodic.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/src/angle_cosine_periodic.rst b/doc/src/angle_cosine_periodic.rst index 71c2caa3f0..61b6407eb9 100644 --- a/doc/src/angle_cosine_periodic.rst +++ b/doc/src/angle_cosine_periodic.rst @@ -32,7 +32,7 @@ center: .. math:: - E = C \left[ 1 - B(-1)^n\cos\left( n\theta\right) \right] + E = 2.0*C \left[ 1 - B(-1)^n\cos\left( n\theta\right) \right] where :math:`C`, :math:`B` and :math:`n` are coefficients defined for each angle type. @@ -47,10 +47,9 @@ or :doc:`read_restart ` commands: * :math:`B` = 1 or -1 * :math:`n` = 1, 2, 3, 4, 5 or 6 for periodicity -Note that the prefactor :math:`C` is specified and not the overall force +Note that the prefactor :math:`C` is specified as coefficient and not the overall force constant :math:`K = \frac{C}{n^2}`. When :math:`B = 1`, it leads to a minimum for the -linear geometry. When :math:`B = -1`, it leads to a maximum for the linear -geometry. +linear geometry. When :math:`B = -1`, it leads to a maximum for the linear geometry. ---------- From e8c8ceaf81a0bc7621a6f033545ddcfd1d41bb80 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 11:28:22 -0400 Subject: [PATCH 112/257] correct attribution of angle style cosine/squared with DREIDING --- doc/src/Howto_bioFF.rst | 1 + doc/src/angle_cosine_periodic.rst | 7 ++----- doc/src/angle_cosine_squared.rst | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/src/Howto_bioFF.rst b/doc/src/Howto_bioFF.rst index bac1b566e1..9bffe5d4c9 100644 --- a/doc/src/Howto_bioFF.rst +++ b/doc/src/Howto_bioFF.rst @@ -91,6 +91,7 @@ documentation for the formula it computes. * :doc:`bond_style ` harmonic * :doc:`bond_style ` morse +* :doc:`angle_style ` cosine/squared * :doc:`angle_style ` harmonic * :doc:`angle_style ` cosine * :doc:`angle_style ` cosine/periodic diff --git a/doc/src/angle_cosine_periodic.rst b/doc/src/angle_cosine_periodic.rst index 61b6407eb9..ec2426154d 100644 --- a/doc/src/angle_cosine_periodic.rst +++ b/doc/src/angle_cosine_periodic.rst @@ -24,9 +24,8 @@ Examples Description """"""""""" -The *cosine/periodic* angle style uses the following potential, which -is commonly used in the :doc:`DREIDING ` force field, -particularly for organometallic systems where :math:`n` = 4 might be used +The *cosine/periodic* angle style uses the following potential, which may be +particularly used for organometallic systems where :math:`n` = 4 might be used for an octahedral complex and :math:`n` = 3 might be used for a trigonal center: @@ -36,8 +35,6 @@ center: where :math:`C`, :math:`B` and :math:`n` are coefficients defined for each angle type. -See :ref:`(Mayo) ` for a description of the DREIDING force field - The following coefficients must be defined for each angle type via the :doc:`angle_coeff ` command as in the example above, or in the data file or restart files read by the :doc:`read_data ` diff --git a/doc/src/angle_cosine_squared.rst b/doc/src/angle_cosine_squared.rst index 4a6a1debe9..d674eb61d8 100644 --- a/doc/src/angle_cosine_squared.rst +++ b/doc/src/angle_cosine_squared.rst @@ -30,8 +30,11 @@ The *cosine/squared* angle style uses the potential E = K [\cos(\theta) - \cos(\theta_0)]^2 -where :math:`\theta_0` is the equilibrium value of the angle, and :math:`K` is a -prefactor. Note that the usual 1/2 factor is included in :math:`K`. +, which is commonly used in the :doc:`DREIDING ` force field, +where :math:`\theta_0` is the equilibrium value of the angle, and :math:`K` +is a prefactor. Note that the usual 1/2 factor is included in :math:`K`. + +See :ref:`(Mayo) ` for a description of the DREIDING force field. The following coefficients must be defined for each angle type via the :doc:`angle_coeff ` command as in the example above, or in @@ -66,3 +69,10 @@ Default """"""" none + +---------- + +.. _cosine-Mayo: + +**(Mayo)** Mayo, Olfason, Goddard III, J Phys Chem, 94, 8897-8909 +(1990). From aabfe40ad3341d0676a875ccbee3c2443748126b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 15:10:45 -0400 Subject: [PATCH 113/257] add missing 1/n**2 term to pair style cosine/periodic energy function --- doc/src/angle_cosine_periodic.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/angle_cosine_periodic.rst b/doc/src/angle_cosine_periodic.rst index ec2426154d..5e13c98cfc 100644 --- a/doc/src/angle_cosine_periodic.rst +++ b/doc/src/angle_cosine_periodic.rst @@ -31,7 +31,7 @@ center: .. math:: - E = 2.0*C \left[ 1 - B(-1)^n\cos\left( n\theta\right) \right] + E = \frac{2.0}{n^2} * C \left[ 1 - B(-1)^n\cos\left( n\theta\right) \right] where :math:`C`, :math:`B` and :math:`n` are coefficients defined for each angle type. From 58744f0a4926a0d9a1991da4718837eb48dff463 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 15:32:24 -0400 Subject: [PATCH 114/257] correct expression for K --- doc/src/angle_cosine_periodic.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/angle_cosine_periodic.rst b/doc/src/angle_cosine_periodic.rst index 5e13c98cfc..8c60ac1ebb 100644 --- a/doc/src/angle_cosine_periodic.rst +++ b/doc/src/angle_cosine_periodic.rst @@ -45,7 +45,7 @@ or :doc:`read_restart ` commands: * :math:`n` = 1, 2, 3, 4, 5 or 6 for periodicity Note that the prefactor :math:`C` is specified as coefficient and not the overall force -constant :math:`K = \frac{C}{n^2}`. When :math:`B = 1`, it leads to a minimum for the +constant :math:`K = \frac{2 C}{n^2}`. When :math:`B = 1`, it leads to a minimum for the linear geometry. When :math:`B = -1`, it leads to a maximum for the linear geometry. ---------- From 56121a524c97ca1606be03ac9243e4b47026412d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 16:26:50 -0400 Subject: [PATCH 115/257] correct equilibrium angle computation for angle style cosine/periodic if b < 0 --- src/MOLECULE/angle_cosine_periodic.cpp | 4 ++-- unittest/force-styles/tests/angle-cosine_periodic.yaml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MOLECULE/angle_cosine_periodic.cpp b/src/MOLECULE/angle_cosine_periodic.cpp index f72a196b41..0df103c333 100644 --- a/src/MOLECULE/angle_cosine_periodic.cpp +++ b/src/MOLECULE/angle_cosine_periodic.cpp @@ -222,9 +222,9 @@ void AngleCosinePeriodic::coeff(int narg, char **arg) /* ---------------------------------------------------------------------- */ -double AngleCosinePeriodic::equilibrium_angle(int /*i*/) +double AngleCosinePeriodic::equilibrium_angle(int i) { - return MY_PI; + return MY_PI*(1.0 - (b[i]>0)?0.0:1.0/static_cast(multiplicity[i])); } /* ---------------------------------------------------------------------- diff --git a/unittest/force-styles/tests/angle-cosine_periodic.yaml b/unittest/force-styles/tests/angle-cosine_periodic.yaml index 814c837dcd..d8fba5c6ee 100644 --- a/unittest/force-styles/tests/angle-cosine_periodic.yaml +++ b/unittest/force-styles/tests/angle-cosine_periodic.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 24 Aug 2020 -date_generated: Tue Sep 15 09:44:34 202 +lammps_version: 10 Mar 2021 +date_generated: Mon Mar 22 16:25:49 202 epsilon: 2.5e-13 prerequisites: ! | atom full @@ -14,7 +14,7 @@ angle_coeff: ! | 2 45.0 1 2 3 50.0 -1 3 4 100.0 -1 4 -equilibrium: 4 3.141592653589793 3.141592653589793 3.141592653589793 3.141592653589793 +equilibrium: 4 1.5707963267948966 1.5707963267948966 0 0 extract: ! "" natoms: 29 init_energy: 946.676664091363 From ca1496e02848265aa0930002479f996fa4c8f3e1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 21:36:25 -0400 Subject: [PATCH 116/257] simplify --- src/KIM/pair_kim.cpp | 49 ++++++++----------- src/USER-MANIFOLD/fix_manifoldforce.cpp | 18 +++---- src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp | 20 +++----- src/USER-MISC/dihedral_table.cpp | 6 +-- 4 files changed, 34 insertions(+), 59 deletions(-) diff --git a/src/KIM/pair_kim.cpp b/src/KIM/pair_kim.cpp index 1b709a65c2..cf6374ab2d 100644 --- a/src/KIM/pair_kim.cpp +++ b/src/KIM/pair_kim.cpp @@ -477,12 +477,10 @@ void PairKIM::coeff(int narg, char **arg) if (paramname == str_name_str) break; } - if (param_index >= numberOfParameters) { - auto msg = fmt::format("Wrong argument for pair coefficients.\n" - "This Model does not have the requested " - "'{}' parameter", paramname); - error->all(FLERR,msg); - } + if (param_index >= numberOfParameters) + error->all(FLERR,fmt::format("Wrong argument for pair coefficients.\n" + "This Model does not have the requested " + "'{}' parameter", paramname)); // Get the index_range for the requested parameter int nlbound(0); @@ -492,12 +490,10 @@ void PairKIM::coeff(int narg, char **arg) std::string argtostr(arg[i++]); // Check to see if the indices range contains only integer numbers & : - if (argtostr.find_first_not_of("0123456789:") != std::string::npos) { - auto msg = fmt::format("Illegal index_range.\nExpected integer " - "parameter(s) instead of '{}' in " - "index_range", argtostr); - error->all(FLERR,msg); - } + if (argtostr.find_first_not_of("0123456789:") != std::string::npos) + error->all(FLERR,fmt::format("Illegal index_range.\nExpected integer" + " parameter(s) instead of '{}' in " + "index_range", argtostr)); std::string::size_type npos = argtostr.find(':'); if (npos != std::string::npos) { @@ -507,21 +503,17 @@ void PairKIM::coeff(int narg, char **arg) nubound = atoi(words[1].c_str()); if (nubound < 1 || nubound > extent || - nlbound < 1 || nlbound > nubound) { - auto msg = fmt::format("Illegal index_range '{}-{}' for '{}' " - "parameter with the extent of '{}'", - nlbound, nubound, paramname, extent); - error->all(FLERR,msg); - } + nlbound < 1 || nlbound > nubound) + error->all(FLERR,fmt::format("Illegal index_range '{}-{}' for '{}' " + "parameter with the extent of '{}'", + nlbound, nubound, paramname, extent)); } else { nlbound = atoi(argtostr.c_str()); - if (nlbound < 1 || nlbound > extent) { - auto msg = fmt::format("Illegal index '{}' for '{}' parameter " - "with the extent of '{}'", nlbound, - paramname, extent); - error->all(FLERR,msg); - } + if (nlbound < 1 || nlbound > extent) + error->all(FLERR,fmt::format("Illegal index '{}' for '{}' parameter " + "with the extent of '{}'", nlbound, + paramname, extent)); nubound = nlbound; } @@ -551,11 +543,10 @@ void PairKIM::coeff(int narg, char **arg) } else error->all(FLERR,"Wrong parameter type to update"); } else { - auto msg = fmt::format("Wrong number of variable values for pair " - "coefficients.\n'{}' values are requested " - "for '{}' parameter", nubound - nlbound + 1, - paramname); - error->all(FLERR,msg); + error->all(FLERR,fmt::format("Wrong number of variable values for pair " + "coefficients.\n'{}' values are requested " + "for '{}' parameter", nubound - nlbound + 1, + paramname)); } } diff --git a/src/USER-MANIFOLD/fix_manifoldforce.cpp b/src/USER-MANIFOLD/fix_manifoldforce.cpp index d389b9787e..26d209e7a9 100644 --- a/src/USER-MANIFOLD/fix_manifoldforce.cpp +++ b/src/USER-MANIFOLD/fix_manifoldforce.cpp @@ -58,22 +58,16 @@ FixManifoldForce::FixManifoldForce(LAMMPS *lmp, int narg, char **arg) : ptr_m = create_manifold(m_name,lmp,narg,arg); // Construct manifold from factory: - if (!ptr_m) { - char msg[2048]; - snprintf(msg,2048,"Manifold pointer for manifold '%s' was NULL for some reason", arg[3]); - error->all(FLERR,msg); - } - + if (!ptr_m) + error->all(FLERR,fmt::format("Manifold pointer for manifold '{}' " + "was NULL for some reason", arg[3])); // After constructing the manifold, you can safely make // room for the parameters nvars = ptr_m->nparams(); - if (narg < nvars+4) { - char msg[2048]; - sprintf(msg,"Manifold %s needs at least %d argument(s)!", - m_name, nvars); - error->all(FLERR,msg); - } + if (narg < nvars+4) + error->all(FLERR,fmt::format("Manifold {} needs at least {} " + "argument(s)!", m_name, nvars)); ptr_m->params = new double[nvars]; if (ptr_m->params == nullptr) { diff --git a/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp b/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp index 5d5bdea156..a45d62a588 100644 --- a/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp +++ b/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp @@ -95,9 +95,7 @@ FixNVEManifoldRattle::FixNVEManifoldRattle( LAMMPS *lmp, int &narg, char **arg, max_iter = utils::numeric( FLERR, arg[4] ,false,lmp); ptr_m = create_manifold(arg[5], lmp, narg, arg); - if (!ptr_m) { - error->all(FLERR,"Error creating manifold pointer"); - } + if (!ptr_m) error->all(FLERR,"Error creating manifold pointer"); nvars = ptr_m->nparams(); tstrs = new char*[nvars]; @@ -105,17 +103,13 @@ FixNVEManifoldRattle::FixNVEManifoldRattle( LAMMPS *lmp, int &narg, char **arg, tstyle = new int[nvars]; is_var = new int[nvars]; - if (!tstrs || !tvars || !tstyle || !is_var) { + if (!tstrs || !tvars || !tstyle || !is_var) error->all(FLERR, "Error creating manifold arg arrays"); - } // Check if you have enough args: - if (6 + nvars > narg) { - char msg[2048]; - sprintf(msg, "Not enough args for manifold %s, %d expected but got %d\n", - ptr_m->id(), nvars, narg - 6); - error->all(FLERR, msg); - } + if (6 + nvars > narg) + error->all(FLERR,fmt::format("Not enough args for manifold {}, {} expected " + "but got {}\n",ptr_m->id(),nvars, narg - 6)); // Loop over manifold args: for (int i = 0; i < nvars; ++i) { int len = 0, offset = 0; @@ -154,9 +148,7 @@ FixNVEManifoldRattle::FixNVEManifoldRattle( LAMMPS *lmp, int &narg, char **arg, } argi += 2; } else if (error_on_unknown_keyword) { - char msg[2048]; - sprintf(msg,"Error parsing arg \"%s\".\n", arg[argi]); - error->all(FLERR, msg); + error->all(FLERR,fmt::format("Error parsing arg \"{}\".\n",arg[argi])); } else { argi += 1; } diff --git a/src/USER-MISC/dihedral_table.cpp b/src/USER-MISC/dihedral_table.cpp index 30e6192275..a81037cad6 100644 --- a/src/USER-MISC/dihedral_table.cpp +++ b/src/USER-MISC/dihedral_table.cpp @@ -1183,10 +1183,8 @@ void DihedralTable::spline_table(Table *tb) } } // for (int i=0; ininput; i++) - if ((num_disagreements > tb->ninput/2) && (num_disagreements > 2)) { - std::string msg("Dihedral table has inconsistent forces and energies. (Try \"NOF\".)\n"); - error->all(FLERR, msg); - } + if ((num_disagreements > tb->ninput/2) && (num_disagreements > 2)) + error->all(FLERR,"Dihedral table has inconsistent forces and energies. (Try \"NOF\".)\n"); } // check for consistency if (! tb->f_unspecified) From 4b076e01bec603acb1b7eac8343a669eecaf38ea Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 22 Mar 2021 21:36:33 -0400 Subject: [PATCH 117/257] silence compiler warning --- src/fix_property_atom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fix_property_atom.cpp b/src/fix_property_atom.cpp index 56add7a0d1..6ce5b6360b 100644 --- a/src/fix_property_atom.cpp +++ b/src/fix_property_atom.cpp @@ -227,7 +227,7 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, try { ValueTokenizer values(buf); - if (values.count() != nvalue+1) + if ((int)values.count() != nvalue+1) error->all(FLERR,fmt::format("Incorrect format in {} section " "of data file: {}",keyword,buf)); From 875327117bd4e9d76d39e3548013d2c47b9e5956 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 23 Mar 2021 07:36:12 -0400 Subject: [PATCH 118/257] add unit test for dihedral styles table and table/cut --- .../tests/dihedral-table_cut_linear.yaml | 86 + .../tests/dihedral-table_cut_spline.yaml | 86 + .../tests/dihedral-table_linear.yaml | 86 + .../tests/dihedral-table_spline.yaml | 86 + .../force-styles/tests/harmonic_dihedral.txt | 3621 +++++++++++++++++ 5 files changed, 3965 insertions(+) create mode 100644 unittest/force-styles/tests/dihedral-table_cut_linear.yaml create mode 100644 unittest/force-styles/tests/dihedral-table_cut_spline.yaml create mode 100644 unittest/force-styles/tests/dihedral-table_linear.yaml create mode 100644 unittest/force-styles/tests/dihedral-table_spline.yaml create mode 100644 unittest/force-styles/tests/harmonic_dihedral.txt diff --git a/unittest/force-styles/tests/dihedral-table_cut_linear.yaml b/unittest/force-styles/tests/dihedral-table_cut_linear.yaml new file mode 100644 index 0000000000..c34c6269de --- /dev/null +++ b/unittest/force-styles/tests/dihedral-table_cut_linear.yaml @@ -0,0 +1,86 @@ +--- +lammps_version: 10 Mar 2021 +date_generated: Tue Mar 23 08:05:02 202 +epsilon: 1e-14 +prerequisites: ! | + atom full + dihedral table/cut +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +dihedral_style: table/cut linear 3600 +dihedral_coeff: ! | + 1 aat 1.00 170 180 ${input_dir}/harmonic_dihedral.txt HARMONIC_1 + 2 aat 1.00 170 180 ${input_dir}/harmonic_dihedral.txt HARMONIC_2 + 3 aat 0.50 175 180 ${input_dir}/harmonic_dihedral.txt HARMONIC_3 + 4 aat 1.00 170 180 ${input_dir}/harmonic_dihedral.txt HARMONIC_4 + 5 aat 0.25 170 175 ${input_dir}/harmonic_dihedral.txt HARMONIC_5 +extract: ! "" +natoms: 29 +init_energy: 552.225725624496 +init_stress: ! |- + -7.4008882268909986e+01 1.3648518393804071e+02 -6.2476301669130748e+01 3.4620215707793108e+01 1.3017899329318067e+02 1.9706621502063012e+02 +init_forces: ! |2 + 1 -8.1198888996808620e+01 7.1073378215839497e+01 -1.1918247546822441e+02 + 2 3.8575810899979956e+01 -1.9920126773772417e+01 1.8847596663648414e+01 + 3 1.0913741754895571e+02 -7.1292512160682776e+01 7.5572753355603993e+01 + 4 -4.7848742793736733e+01 -7.5245295675494663e+00 6.4464643610526949e+01 + 5 -1.5539692023725792e+01 5.7172364237479494e+00 -1.3226941634858840e+00 + 6 -1.1355716924924745e+02 -8.6143836335725510e+01 -5.7299648623432482e+00 + 7 4.1372375526613887e+01 4.5139121695653614e+01 -7.4310043691848229e+00 + 8 2.1399043677828325e+02 1.8625470581545247e+02 -3.3675100353189755e+00 + 9 5.2653582674682809e+01 5.6583201775589529e+01 -2.5669664860295835e+01 + 10 -4.7984520275438535e+02 -5.1382692638722949e+02 -1.3749287390453020e+02 + 11 1.6539670687119863e+02 1.4091972117987351e+02 -1.2657881071783035e+02 + 12 3.4200742496423310e+01 1.2794076077133660e+02 2.3610219433759886e+02 + 13 1.8270592580559917e+00 4.1997746033241778e+00 8.8146411631557697e+00 + 14 1.8694466162959706e+01 -2.6013807510038696e+01 -9.2498849040619788e+00 + 15 -6.2869548680867373e+00 2.1284514172388507e+00 -6.4318098210331209e+00 + 16 -1.0694908795819050e+02 -5.9251517113768401e+01 1.0405679351593225e+01 + 17 1.7537714042702788e+02 1.4401690395071051e+02 2.8249184624181581e+01 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_energy: 549.782031215547 +run_stress: ! |- + -7.5056949042919044e+01 1.3698944188847955e+02 -6.1932492845560127e+01 3.3581673544215263e+01 1.2888596290133776e+02 1.9565093507759894e+02 +run_forces: ! |2 + 1 -8.1850261118769851e+01 7.1565857666082792e+01 -1.1998194154132169e+02 + 2 3.8942730288029111e+01 -2.0139091742218607e+01 1.9096837462073495e+01 + 3 1.0933304895917627e+02 -7.1974713700542679e+01 7.7222647280784500e+01 + 4 -4.7578796179763913e+01 -7.4260553823873163e+00 6.4056709071407184e+01 + 5 -1.5573770424692153e+01 5.7360778752676689e+00 -1.3292716784107659e+00 + 6 -1.1205401245818740e+02 -8.3930835846975214e+01 -6.4629873083122060e+00 + 7 4.1368235883807785e+01 4.5098977123947911e+01 -7.4207495093494247e+00 + 8 2.1112963982593271e+02 1.8319846795829790e+02 -4.5077247269703236e+00 + 9 5.2596180125216748e+01 5.6303309547815658e+01 -2.5556604563933746e+01 + 10 -4.8079664429997507e+02 -5.1197713825609452e+02 -1.3418905325289452e+02 + 11 1.6804796981040414e+02 1.4157399298542791e+02 -1.2667138198231208e+02 + 12 3.3945852325507303e+01 1.2661718822016165e+02 2.3437614824953252e+02 + 13 1.8225699822433148e+00 4.1983174055270061e+00 8.8273571873798709e+00 + 14 1.8256498023781354e+01 -2.5354302062650923e+01 -8.9739201991677255e+00 + 15 -6.2761226111239754e+00 2.1261045368019413e+00 -6.4368032911012207e+00 + 16 -1.0841619930894663e+02 -6.1089982213467948e+01 9.6877249595793860e+00 + 17 1.7710308117736014e+02 1.4547382588500676e+02 2.8263013843016775e+01 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +... diff --git a/unittest/force-styles/tests/dihedral-table_cut_spline.yaml b/unittest/force-styles/tests/dihedral-table_cut_spline.yaml new file mode 100644 index 0000000000..9148e0a80d --- /dev/null +++ b/unittest/force-styles/tests/dihedral-table_cut_spline.yaml @@ -0,0 +1,86 @@ +--- +lammps_version: 10 Mar 2021 +date_generated: Tue Mar 23 08:06:45 202 +epsilon: 1e-14 +prerequisites: ! | + atom full + dihedral table/cut +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +dihedral_style: table/cut spline 3600 +dihedral_coeff: ! | + 1 aat 1.00 170 180 ${input_dir}/harmonic_dihedral.txt HARMONIC_1 + 2 aat 1.00 170 180 ${input_dir}/harmonic_dihedral.txt HARMONIC_2 + 3 aat 0.50 175 180 ${input_dir}/harmonic_dihedral.txt HARMONIC_3 + 4 aat 1.00 170 180 ${input_dir}/harmonic_dihedral.txt HARMONIC_4 + 5 aat 0.25 170 175 ${input_dir}/harmonic_dihedral.txt HARMONIC_5 +extract: ! "" +natoms: 29 +init_energy: 552.218725263499 +init_stress: ! |- + -7.4019824552159534e+01 1.3649499111894895e+02 -6.2475166566789284e+01 3.4617375151088808e+01 1.3019745657214429e+02 1.9709007795400348e+02 +init_forces: ! |2 + 1 -8.1213286444115909e+01 7.1080525227994045e+01 -1.1918872501604099e+02 + 2 3.8585732128399350e+01 -1.9925249987601369e+01 1.8852444035804549e+01 + 3 1.0914957240045973e+02 -7.1293677289031876e+01 7.5564572526931997e+01 + 4 -4.7856039321211888e+01 -7.5256880640368262e+00 6.4474469548287303e+01 + 5 -1.5540068306011690e+01 5.7173997377718440e+00 -1.3227187051350375e+00 + 6 -1.1356202282295826e+02 -8.6148464023143134e+01 -5.7287967059654719e+00 + 7 4.1373182001548223e+01 4.5140001882310173e+01 -7.4311492797065428e+00 + 8 2.1400860040790070e+02 1.8627156816363441e+02 -3.3695416437372394e+00 + 9 5.2656207239745335e+01 5.6586006420025306e+01 -2.5670940543260770e+01 + 10 -4.7989294342864497e+02 -5.1388484267202580e+02 -1.3749831844924219e+02 + 11 1.6541995228367492e+02 1.4093778373411678e+02 -1.2659553837843652e+02 + 12 3.4200230035629019e+01 1.2795430859179336e+02 2.3612094879489862e+02 + 13 1.8271828366360419e+00 4.2000586675545639e+00 8.8152373675940172e+00 + 14 1.8695088969660507e+01 -2.6014674160815950e+01 -9.2501930642549315e+00 + 15 -6.2873518284233292e+00 2.1285858083405422e+00 -6.4322159275576647e+00 + 16 -1.0696654386912348e+02 -5.9261377200437906e+01 1.0407194734343612e+01 + 17 1.7540250771683571e+02 1.4403773516355190e+02 2.8253270705477313e+01 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_energy: 549.770211120194 +run_stress: ! |- + -7.5054671721636595e+01 1.3699895801893166e+02 -6.1944286297295179e+01 3.3587137063275613e+01 1.2891678447538322e+02 1.9568224888755336e+02 +run_forces: ! |2 + 1 -8.1862157367941563e+01 7.1571534225465314e+01 -1.1998648925690665e+02 + 2 3.8950856557592253e+01 -2.0143295233943885e+01 1.9100831488650599e+01 + 3 1.0934424273562679e+02 -7.1974764063434151e+01 7.7213177208305225e+01 + 4 -4.7585717040630072e+01 -7.4272048534134285e+00 6.4066017644735453e+01 + 5 -1.5574231365780285e+01 5.7363230482123928e+00 -1.3292888747698781e+00 + 6 -1.1207625383797915e+02 -8.3953260935523502e+01 -6.4560404254467478e+00 + 7 4.1369305653963607e+01 4.5100137884474947e+01 -7.4209393875477607e+00 + 8 2.1117769556228862e+02 1.8324468258252551e+02 -4.5178766251241402e+00 + 9 5.2599757474211380e+01 5.6307064747883963e+01 -2.5558323416528047e+01 + 10 -4.8085705384233728e+02 -5.1205238742034794e+02 -1.3420522978505346e+02 + 11 1.6806394787511115e+02 1.4159239612328381e+02 -1.2668631632096621e+02 + 12 3.3951439786882119e+01 1.2663190154365350e+02 2.3440594816333368e+02 + 13 1.8227069769227078e+00 4.1986314416593373e+00 8.8280212719479678e+00 + 14 1.8256647570003278e+01 -2.5354504765353397e+01 -8.9739916559242712e+00 + 15 -6.2764595167862440e+00 2.1262187967343880e+00 -6.4371500960467092e+00 + 16 -1.0842617323615015e+02 -6.1092389588080550e+01 9.6917320121684938e+00 + 17 1.7712144601500279e+02 1.4548891646620359e+02 2.8265918055172548e+01 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +... diff --git a/unittest/force-styles/tests/dihedral-table_linear.yaml b/unittest/force-styles/tests/dihedral-table_linear.yaml new file mode 100644 index 0000000000..7e2a7d55c1 --- /dev/null +++ b/unittest/force-styles/tests/dihedral-table_linear.yaml @@ -0,0 +1,86 @@ +--- +lammps_version: 10 Mar 2021 +date_generated: Mon Mar 22 21:19:05 202 +epsilon: 1e-14 +prerequisites: ! | + atom full + dihedral table +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +dihedral_style: table linear 3600 +dihedral_coeff: ! | + 1 ${input_dir}/harmonic_dihedral.txt HARMONIC_1 + 2 ${input_dir}/harmonic_dihedral.txt HARMONIC_2 + 3 ${input_dir}/harmonic_dihedral.txt HARMONIC_3 + 4 ${input_dir}/harmonic_dihedral.txt HARMONIC_4 + 5 ${input_dir}/harmonic_dihedral.txt HARMONIC_5 +extract: ! "" +natoms: 29 +init_energy: 789.184256783584 +init_stress: ! |- + -1.6165501104216639e+02 -7.4114380315441565e+01 2.3576939135760787e+02 -2.3488521541598647e+02 3.4341737187983938e+02 -1.5959461001900144e+02 +init_forces: ! |2 + 1 -2.1498835469576278e+01 4.0242705861631180e+01 -9.0007821437717382e+01 + 2 -8.2018888113291979e+00 4.2353656629457461e+00 -4.0073270940910781e+00 + 3 9.1203773212580060e+01 -1.3765900530865244e+02 8.1977349479812418e+01 + 4 -4.8195100042546727e+01 -8.0451084249021534e+00 6.4747111681716376e+01 + 5 -6.2251242080533295e+01 2.2803637398534534e+01 -5.3285420895267421e+00 + 6 9.1265646559106216e+01 1.3743040689865262e+02 -3.9343488033831335e+01 + 7 -4.7432736093120091e+01 -5.1202947877496094e+01 8.4096202947719512e+00 + 8 2.2566883016909227e+02 1.6219571012359663e+02 5.7664673263129927e+01 + 9 -2.0799357954651114e+00 5.0308583175017674e+00 -7.5442843674616533e-01 + 10 -4.0472227269030174e+02 -4.7265020465440665e+02 -9.9994880868353093e+01 + 11 3.9893735247972799e+01 2.0808487532188158e+02 -1.3663466833430391e+02 + 12 6.2491147091194719e+01 7.0245646325825419e+01 1.9568453298435855e+02 + 13 2.9232948128895806e+01 6.7196393653186874e+01 1.4103425861049234e+02 + 14 7.2097046578806413e+01 -1.0032480603588586e+02 -3.5673090473056490e+01 + 15 -1.0059127788938771e+02 3.4055222675821568e+01 -1.0290895713652986e+02 + 16 -9.2256978542416007e+01 -1.2565565388894508e+02 -6.3113527034307076e+01 + 17 1.7537714042702783e+02 1.4401690395071046e+02 2.8249184624181567e+01 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_energy: 786.199103735512 +run_stress: ! |- + -1.5979555001643004e+02 -7.4781079673606996e+01 2.3457662969003690e+02 -2.3349637150864024e+02 3.4159374485946643e+02 -1.5956254217954015e+02 +run_forces: ! |2 + 1 -2.2291107377203105e+01 4.0666970718627333e+01 -9.0497211256380396e+01 + 2 -7.6875363073287559e+00 3.9737486142840055e+00 -3.7620801734312614e+00 + 3 9.2103819928191996e+01 -1.3743335232167533e+02 8.2431881459386020e+01 + 4 -4.8290666517219691e+01 -8.1170776132331781e+00 6.4779991104261541e+01 + 5 -6.2246983418905813e+01 2.2813785810311227e+01 -5.3751809499241965e+00 + 6 9.1087481738151070e+01 1.3760819705271160e+02 -3.9500650484032505e+01 + 7 -4.6891554381909977e+01 -5.0621074446115216e+01 8.3775716071879351e+00 + 8 2.2268693398316259e+02 1.5891760123847899e+02 5.7199245600838793e+01 + 9 -1.3435027007714808e+00 5.5949363550589339e+00 -1.0517595721340651e+00 + 10 -4.0565110153193677e+02 -4.7084401363160805e+02 -9.7618847422734831e+01 + 11 4.2251495153612957e+01 2.0872309038043886e+02 -1.3675117078222070e+02 + 12 6.2352820175292266e+01 6.8729440749361473e+01 1.9366789701210121e+02 + 13 2.9032540154457664e+01 6.7387205615336427e+01 1.4127076790322786e+02 + 14 7.1580926568596425e+01 -9.9385928393915108e+01 -3.5110636800452511e+01 + 15 -1.0011174024358218e+02 3.3796455380232061e+01 -1.0280446675457922e+02 + 16 -9.3357186802666320e+01 -1.2692958041908989e+02 -6.3465822450651899e+01 + 17 1.7677536158005910e+02 1.4511959491079591e+02 2.8210471959538260e+01 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +... diff --git a/unittest/force-styles/tests/dihedral-table_spline.yaml b/unittest/force-styles/tests/dihedral-table_spline.yaml new file mode 100644 index 0000000000..90aab98fba --- /dev/null +++ b/unittest/force-styles/tests/dihedral-table_spline.yaml @@ -0,0 +1,86 @@ +--- +lammps_version: 10 Mar 2021 +date_generated: Mon Mar 22 21:19:05 202 +epsilon: 1e-14 +prerequisites: ! | + atom full + dihedral table +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +dihedral_style: table spline 3600 +dihedral_coeff: ! | + 1 ${input_dir}/harmonic_dihedral.txt HARMONIC_1 + 2 ${input_dir}/harmonic_dihedral.txt HARMONIC_2 + 3 ${input_dir}/harmonic_dihedral.txt HARMONIC_3 + 4 ${input_dir}/harmonic_dihedral.txt HARMONIC_4 + 5 ${input_dir}/harmonic_dihedral.txt HARMONIC_5 +extract: ! "" +natoms: 29 +init_energy: 789.17395865366 +init_stress: ! |- + -1.6167160198618581e+02 -7.4120077515581954e+01 2.3579167950176785e+02 -2.3490764576822448e+02 3.4342184840668585e+02 -1.5962456212434762e+02 +init_forces: ! |2 + 1 -2.1511698354927645e+01 4.0249060385771472e+01 -9.0013321064696271e+01 + 2 -8.1931699818042816e+00 4.2308633547530370e+00 -4.0030671970615401e+00 + 3 9.1213724085941266e+01 -1.3766351443388791e+02 8.1969246814730084e+01 + 4 -4.8202572709944334e+01 -8.0465316616826055e+00 6.4757081268568328e+01 + 5 -6.2252471687916213e+01 2.2804485237535822e+01 -5.3285277358374286e+00 + 6 9.1271091175285207e+01 1.3743691094855717e+02 -3.9344000146381845e+01 + 7 -4.7435622491834799e+01 -5.1206081227011012e+01 8.4101355534202042e+00 + 8 2.2568717307036252e+02 1.6221073791401761e+02 5.7667169771245945e+01 + 9 -2.0794865262354030e+00 5.0314964866185363e+00 -7.5468527912272698e-01 + 10 -4.0476567716026062e+02 -4.7270660864081441e+02 -9.9999223852109083e+01 + 11 3.9909170153607846e+01 2.0810704891869841e+02 -1.3665197982219311e+02 + 12 6.2493704712199360e+01 7.0253447706808217e+01 1.9569964315907762e+02 + 13 2.9234925386176613e+01 6.7200938680873065e+01 1.4104379788150430e+02 + 14 7.2099736473223771e+01 -1.0032854908984555e+02 -3.5674421413108355e+01 + 15 -1.0059762925477315e+02 3.4057372933448626e+01 -1.0291545484092256e+02 + 16 -9.2273704605935819e+01 -1.2566881267739232e+02 -6.3115663802590909e+01 + 17 1.7540250771683569e+02 1.4403773516355182e+02 2.8253270705477295e+01 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_energy: 786.186636054773 +run_stress: ! |- + -1.5982910389343505e+02 -7.4774149450379937e+01 2.3460325334381506e+02 -2.3353349487854388e+02 3.4161194489304893e+02 -1.5958869300328692e+02 +run_forces: ! |2 + 1 -2.2302877568136338e+01 4.0672550148970281e+01 -9.0501596555606994e+01 + 2 -7.6795596366469354e+00 3.9696255711631245e+00 -3.7581781934774909e+00 + 3 9.2113037896352481e+01 -1.3743858578373496e+02 8.2424527928857074e+01 + 4 -4.8297128431903225e+01 -8.1171172458509702e+00 6.4789088257516795e+01 + 5 -6.2249945655197145e+01 2.2813353706915890e+01 -5.3758960971523750e+00 + 6 9.1082266941280153e+01 1.3760435384789912e+02 -3.9497610389853719e+01 + 7 -4.6896901941201634e+01 -5.0626903993409201e+01 8.3785409954385486e+00 + 8 2.2272760597411565e+02 1.5895499661752211e+02 5.7194518486415930e+01 + 9 -1.3424389468966993e+00 5.5961120653727576e+00 -1.0522843110369067e+00 + 10 -4.0569661746613480e+02 -4.7090645573337184e+02 -9.7628440089732422e+01 + 11 4.2260633619776542e+01 2.0874271121537350e+02 -1.3676519708069108e+02 + 12 6.2351939732772273e+01 6.8740733319529681e+01 1.9368291661547465e+02 + 13 2.9034913906341565e+01 6.7392732862315881e+01 1.4128237934676201e+02 + 14 7.1584708176938221e+01 -9.9391162142709391e+01 -3.5112483055478720e+01 + 15 -1.0011391207749671e+02 3.3797184006896543e+01 -1.0280672266200776e+02 + 16 -9.3370883891440556e+01 -1.2693997492906119e+02 -6.3467168010540369e+01 + 17 1.7679515936747723e+02 1.4513584646617855e+02 2.8213604815112788e+01 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +... diff --git a/unittest/force-styles/tests/harmonic_dihedral.txt b/unittest/force-styles/tests/harmonic_dihedral.txt new file mode 100644 index 0000000000..3f99f1663c --- /dev/null +++ b/unittest/force-styles/tests/harmonic_dihedral.txt @@ -0,0 +1,3621 @@ +# UNITS: real Dihedral table + +HARMONIC_1 +N 720 RADIANS + +0 0.0 150.0 -0.0 +1 0.008726646259971648 149.98857713672933 2.6178609655925102 +2 0.017453292519943295 149.95431202643218 5.234924505375115 +3 0.02617993877991494 149.89721510659302 7.850393436441557 +4 0.03490658503988659 149.81730376948678 10.463471061618776 +5 0.04363323129985824 149.71460235688093 13.073361412148756 +6 0.05235987755982988 149.58914215262052 15.679269490147995 +7 0.061086523819801536 149.44096137309916 18.280401510772094 +8 0.06981317007977318 149.27010515561776 20.875965144009786 +9 0.07853981633974483 149.07662554463536 23.46516975603466 +10 0.08726646259971647 148.86058147591564 26.047226650039544 +11 0.09599310885968812 148.62203875857477 28.62134930648175 +12 0.10471975511965977 148.36107005503544 31.186753622663918 +13 0.11344640137963141 148.07775485889266 33.74265815157973 +14 0.12217304763960307 147.77217947069977 36.288284339950145 +15 0.1308996938995747 147.44443697168012 38.82285676537811 +16 0.13962634015954636 147.0946271953739 41.34560337254987 +17 0.148352986419518 146.72285669722766 43.85575570841053 +18 0.15707963267948966 146.32923872213652 46.35254915624214 +19 0.16580627893946132 145.91389316994875 48.83522316857347 +20 0.17453292519943295 145.47694655894313 51.3030214988503 +21 0.1832595714594046 145.01853198729015 53.755192431795045 +22 0.19198621771937624 144.53878909250906 56.19098901238682 +23 0.20071286397934787 144.03786400893304 58.60966927339109 +24 0.20943951023931953 143.51590932319507 61.01049646137005 +25 0.2181661564992912 142.97308402774874 63.392739261104914 +26 0.22689280275926282 142.40955347243755 65.75567201836158 +27 0.23561944901923448 141.82548931412762 68.09857496093201 +28 0.24434609527920614 141.2210694644195 70.42073441788365 +29 0.2530727415391778 140.5964780354547 72.7214430369506 +30 0.2617993877991494 139.95190528383287 75.0 +31 0.27052603405912107 139.2875475526584 77.25571123650813 +32 0.2792526803190927 138.60360721173197 79.48788963498072 +33 0.28797932657906433 137.9002925959068 81.69585525225406 +34 0.296705972839036 137.17781794162812 83.87893552061203 +35 0.30543261909900765 136.4364033216744 86.03646545265696 +36 0.3141592653589793 135.67627457812105 88.16778784387098 +37 0.32288591161895097 134.89766325354694 90.27225347280722 +38 0.33161255787892263 134.10080652050416 92.34922129884876 +39 0.3403392041388943 133.28594710927283 94.3980586574756 +40 0.3490658503988659 132.45333323392336 96.41814145298089 +41 0.35779249665883756 131.6032185167079 98.40885434857609 +42 0.3665191429188092 130.73586191080454 100.36959095382873 +43 0.3752457891787809 129.85152762143775 102.29975400937477 +44 0.3839724354387525 128.95048502539885 104.19875556884958 +45 0.39269908169872414 128.03300858899107 106.06601717798215 +46 0.40142572795869574 127.09937778442483 107.90097005079764 +47 0.41015237421866746 126.14987700468738 109.70305524287555 +48 0.41887902047863906 125.18479547691435 111.47172382160912 +49 0.42760566673861067 124.20442717428804 113.20643703341575 +50 0.4363323129985824 123.20907072649044 114.90666646784672 +51 0.445058959258554 122.19902932873782 116.57189421854562 +52 0.45378560551852565 121.17461064942438 118.2016130410083 +53 0.4625122517784973 120.13612673640364 119.79532650709392 +54 0.47123889803846897 119.0838939219355 121.35254915624212 +55 0.4799655442984406 118.01823272632845 122.87280664334878 +56 0.4886921905584123 116.93946776030603 124.35563588325626 +57 0.4974188368183839 115.84792762612705 125.80058519181361 +58 0.5061454830783556 114.74394481749034 127.2072144234639 +59 0.5148721293383272 113.62785561825407 128.57509510531682 +60 0.5235987755982988 112.50000000000001 129.90381056766577 +61 0.5323254218582705 111.36072151847529 131.19295607090933 +62 0.5410520681182421 110.21036720894179 132.44213892883906 +63 0.5497787143782138 109.049287480466 133.6509786282552 +64 0.5585053606381855 107.87783600918081 134.81910694487505 +65 0.5672320068981571 106.69636963055244 135.94616805549754 +66 0.5759586531581287 105.50524823068503 137.03181864639012 +67 0.5846852994181004 104.30483463669552 138.07572801786608 +68 0.593411945678072 103.09549450619338 139.07757818501813 +69 0.6021385919380438 101.8775962158975 140.0370639745803 +70 0.6108652381980153 100.65151074942517 140.95389311788625 +71 0.619591884457987 99.41761158428675 141.82778633989753 +72 0.6283185307179586 98.17627457812105 142.65847744427305 +73 0.6370451769779303 96.92787785420526 143.4457133944553 +74 0.6457718232379019 95.67280168627494 144.1892543907478 +75 0.6544984694978736 94.41142838268905 144.88887394336024 +76 0.6632251157578453 93.14414216997507 145.54435894139948 +77 0.6719517620178168 91.87132907578986 146.15550971778526 +78 0.6806784082777886 90.59337681133194 146.72214011007085 +79 0.6894050545377601 89.31067465324087 147.24407751714958 +80 0.6981317007977318 88.02361332501977 147.72116295183122 +81 0.7068583470577035 86.73258487801732 148.15325108927067 +82 0.7155849933176751 85.43798257200493 148.54021031123557 +83 0.7243116395776468 84.14020075538608 148.8819227461983 +84 0.7330382858376184 82.83963474507401 149.17828430524102 +85 0.74176493209759 81.53668070607438 149.4292047137618 +86 0.7504915783575618 80.23173553080939 149.63460753897365 +87 0.7592182246175333 78.92519671822077 149.7944302131861 +88 0.767944870877505 77.61746225268757 149.90862405286435 +89 0.7766715171374766 76.30893048279626 149.97715427345867 +90 0.7853981633974483 75.0 150.00000000000003 +91 0.7941248096574199 73.69106951720374 149.97715427345867 +92 0.8028514559173915 72.38253774731243 149.90862405286435 +93 0.8115781021773633 71.07480328177923 149.7944302131861 +94 0.8203047484373349 69.76826446919061 149.63460753897365 +95 0.8290313946973066 68.46331929392565 149.42920471376186 +96 0.8377580409572781 67.16036525492602 149.17828430524102 +97 0.8464846872172498 65.85979924461398 148.88192274619828 +98 0.8552113334772213 64.56201742799509 148.5402103112355 +99 0.8639379797371932 63.267415121982644 148.15325108927067 +100 0.8726646259971648 61.97638667498025 147.72116295183125 +101 0.8813912722571364 60.68932534675913 147.24407751714958 +102 0.890117918517108 59.40662318866806 146.72214011007085 +103 0.8988445647770796 58.128670924210134 146.15550971778535 +104 0.9075712110370513 56.85585783002493 145.54435894139948 +105 0.9162978572970231 55.58857161731093 144.8888739433602 +106 0.9250245035569946 54.327198313725084 144.1892543907479 +107 0.9337511498169663 53.07212214579476 143.44571339445528 +108 0.9424777960769379 51.82372542187894 142.65847744427305 +109 0.9512044423369095 50.58238841571326 141.8277863398975 +110 0.9599310885968813 49.34848925057483 140.95389311788625 +111 0.9686577348568529 48.12240378410246 140.03706397458024 +112 0.9773843811168246 46.90450549380659 139.07757818501813 +113 0.9861110273767961 45.69516536330446 138.07572801786603 +114 0.9948376736367678 44.49475176931499 137.03181864639015 +115 1.0035643198967394 43.30363036944755 135.94616805549754 +116 1.0122909661567112 42.122163990819196 134.81910694487505 +117 1.0210176124166828 40.95071251953399 133.6509786282552 +118 1.0297442586766543 39.78963279105821 132.44213892883906 +119 1.038470904936626 38.639278481524734 131.1929560709094 +120 1.0471975511965976 37.50000000000001 129.9038105676658 +121 1.0559241974565694 36.37214438174595 128.57509510531682 +122 1.064650843716541 35.25605518250966 127.20721442346392 +123 1.0733774899765127 34.15207237387297 125.80058519181362 +124 1.0821041362364843 33.06053223969398 124.35563588325626 +125 1.0908307824964558 31.98176727367156 122.87280664334881 +126 1.0995574287564276 30.916106078064505 121.35254915624212 +127 1.1082840750163994 29.863873263596364 119.7953265070939 +128 1.117010721276371 28.82538935057562 118.2016130410083 +129 1.1257373675363425 27.800970671262213 116.57189421854565 +130 1.1344640137963142 26.79092927350954 114.90666646784672 +131 1.1431906600562858 25.79557282571197 113.20643703341578 +132 1.1519173063162573 24.815204523085658 111.47172382160916 +133 1.160643952576229 23.850122995312606 109.70305524287556 +134 1.1693705988362009 22.900622215575172 107.90097005079764 +135 1.1780972450961724 21.96699141100894 106.06601717798215 +136 1.186823891356144 21.04951497460116 104.19875556884962 +137 1.1955505376161157 20.148472378562207 102.2997540093748 +138 1.2042771838760875 19.264138089195423 100.36959095382869 +139 1.213003830136059 18.396781483292106 98.40885434857609 +140 1.2217304763960306 17.546666766076648 96.41814145298093 +141 1.2304571226560024 16.714052890727167 94.3980586574756 +142 1.239183768915974 15.899193479495866 92.34922129884875 +143 1.2479104151759455 15.102336746453046 90.27225347280728 +144 1.2566370614359172 14.323725421878933 88.16778784387098 +145 1.265363707695889 13.563596678325606 86.03646545265688 +146 1.2740903539558606 12.82218205837187 83.87893552061203 +147 1.2828170002158321 12.099707404093204 81.69585525225413 +148 1.2915436464758039 11.396392788268045 79.48788963498072 +149 1.3002702927357754 10.712452447341583 77.25571123650812 +150 1.3089969389957472 10.048094716167096 74.99999999999999 +151 1.3177235852557188 9.40352196454532 72.72144303695057 +152 1.3264502315156905 8.778930535580475 70.4207344178836 +153 1.335176877775662 8.174510685872416 68.09857496093207 +154 1.3439035240356336 7.590446527562489 65.75567201836162 +155 1.3526301702956054 7.026915972251246 63.392739261104914 +156 1.3613568165555772 6.484090676804918 61.01049646136999 +157 1.3700834628155487 5.962135991066964 58.60966927339109 +158 1.3788101090755203 5.461210907490943 56.19098901238681 +159 1.3875367553354918 4.981468012709886 53.755192431795116 +160 1.3962634015954636 4.523053441056868 51.30302149885036 +161 1.4049900478554354 4.086106830051229 48.83522316857348 +162 1.413716694115407 3.6707612778634853 46.35254915624214 +163 1.4224433403753785 3.2771433027723424 43.85575570841059 +164 1.4311699866353502 2.9053728046260745 41.34560337254987 +165 1.4398966328953218 2.5555630283198685 38.82285676537818 +166 1.4486232791552935 2.227820529300248 36.288284339950145 +167 1.457349925415265 1.9222451411073482 33.742658151579796 +168 1.4660765716752369 1.6389299449645818 31.186753622663918 +169 1.4748032179352084 1.37796124142521 28.62134930648175 +170 1.48352986419518 1.1394185240843986 26.047226650039608 +171 1.4922565104551517 0.9233744553646506 23.46516975603466 +172 1.5009831567151235 0.7298948443822312 20.875965144009783 +173 1.509709802975095 0.5590386269008513 18.280401510772162 +174 1.5184364492350666 0.4108578473795116 15.67926949014806 +175 1.5271630954950384 0.28539764311909244 13.073361412148754 +176 1.53588974175501 0.1826962305131935 10.463471061618844 +177 1.5446163880149815 0.10278489340696251 7.8503934364416255 +178 1.5533430342749532 0.04568797356781784 5.234924505375181 +179 1.562069680534925 0.011422863270654782 2.6178609655925094 +180 1.5707963267948966 0.0 -0.0 +181 1.579522973054868 0.011422863270654782 -2.617860965592476 +182 1.5882496193148399 0.04568797356781784 -5.234924505375147 +183 1.5969762655748114 0.10278489340696251 -7.850393436441525 +184 1.605702911834783 0.1826962305131935 -10.46347106161871 +185 1.6144295580947547 0.28539764311905913 -13.073361412148694 +186 1.6231562043547265 0.4108578473795116 -15.679269490148027 +187 1.6318828506146983 0.5590386269008513 -18.280401510772162 +188 1.6406094968746698 0.7298948443822312 -20.875965144009815 +189 1.6493361431346414 0.9233744553646506 -23.465169756034594 +190 1.6580627893946132 1.1394185240843901 -26.047226650039576 +191 1.6667894356545847 1.3779612414251936 -28.621349306481722 +192 1.6755160819145563 1.6389299449645818 -31.186753622663844 +193 1.684242728174528 1.9222451411073398 -33.74265815157973 +194 1.6929693744344996 2.227820529300248 -36.28828433995011 +195 1.7016960206944711 2.55556302831986 -38.82285676537804 +196 1.7104226669544427 2.905372804626066 -41.34560337254981 +197 1.7191493132144147 3.277143302772334 -43.85575570841053 +198 1.7278759594743864 3.6707612778634853 -46.352549156242176 +199 1.736602605734358 4.086106830051237 -48.835223168573506 +200 1.7453292519943295 4.5230534410568595 -51.3030214988503 +201 1.7540558982543013 4.981468012709877 -53.75519243179504 +202 1.7627825445142729 5.461210907490943 -56.19098901238681 +203 1.7715091907742444 5.962135991066956 -58.60966927339103 +204 1.780235837034216 6.484090676804918 -61.01049646136999 +205 1.7889624832941877 7.026915972251246 -63.392739261104914 +206 1.7976891295541593 7.590446527562456 -65.75567201836158 +207 1.8064157758141308 8.174510685872374 -68.09857496093194 +208 1.8151424220741026 8.778930535580475 -70.4207344178836 +209 1.8238690683340746 9.403521964545345 -72.7214430369506 +210 1.8325957145940461 10.048094716167096 -75.00000000000003 +211 1.8413223608540177 10.712452447341583 -77.25571123650812 +212 1.8500490071139892 11.396392788268045 -79.48788963498072 +213 1.858775653373961 12.099707404093197 -81.69585525225406 +214 1.8675022996339325 12.822182058371862 -83.878935520612 +215 1.876228945893904 13.563596678325606 -86.03646545265688 +216 1.8849555921538759 14.323725421878933 -88.16778784387095 +217 1.8936822384138474 15.10233674645303 -90.2722534728072 +218 1.902408884673819 15.899193479495825 -92.3492212988487 +219 1.9111355309337907 16.714052890727167 -94.3980586574756 +220 1.9198621771937625 17.54666676607664 -96.41814145298088 +221 1.9285888234537343 18.396781483292106 -98.40885434857609 +222 1.9373154697137058 19.26413808919543 -100.36959095382875 +223 1.9460421159736774 20.1484723785622 -102.29975400937475 +224 1.9547687622336491 21.04951497460116 -104.1987555688496 +225 1.9634954084936207 21.96699141100894 -106.06601717798213 +226 1.9722220547535922 22.900622215575172 -107.90097005079764 +227 1.980948701013564 23.850122995312606 -109.70305524287556 +228 1.9896753472735356 24.815204523085633 -111.47172382160907 +229 1.9984019935335071 25.795572825711936 -113.20643703341574 +230 2.007128639793479 26.790929273509523 -114.90666646784666 +231 2.015855286053451 27.80097067126222 -116.57189421854568 +232 2.0245819323134224 28.82538935057565 -118.20161304100832 +233 2.033308578573394 29.86387326359639 -119.79532650709392 +234 2.0420352248333655 30.916106078064505 -121.35254915624212 +235 2.050761871093337 31.981767273671505 -122.87280664334871 +236 2.0594885173533086 33.06053223969395 -124.35563588325621 +237 2.0682151636132806 34.15207237387297 -125.80058519181362 +238 2.076941809873252 35.256055182509634 -127.20721442346387 +239 2.0856684561332237 36.37214438174592 -128.57509510531682 +240 2.0943951023931953 37.49999999999996 -129.90381056766577 +241 2.103121748653167 38.63927848152465 -131.1929560709093 +242 2.111848394913139 39.789632791058196 -132.44213892883903 +243 2.1205750411731104 40.95071251953399 -133.6509786282552 +244 2.129301687433082 42.122163990819175 -134.81910694487502 +245 2.138028333693054 43.30363036944755 -135.94616805549754 +246 2.1467549799530254 44.49475176931498 -137.03181864639012 +247 2.155481626212997 45.69516536330446 -138.07572801786603 +248 2.1642082724729685 46.90450549380659 -139.07757818501813 +249 2.17293491873294 48.12240378410241 -140.03706397458024 +250 2.1816615649929116 49.34848925057481 -140.95389311788622 +251 2.1903882112528836 50.58238841571323 -141.82778633989756 +252 2.199114857512855 51.82372542187893 -142.65847744427302 +253 2.2078415037728267 53.07212214579472 -143.4457133944553 +254 2.2165681500327987 54.32719831372507 -144.18925439074786 +255 2.2252947962927703 55.58857161731093 -144.8888739433602 +256 2.234021442552742 56.85585783002492 -145.54435894139948 +257 2.2427480888127134 58.12867092421011 -146.1555097177853 +258 2.251474735072685 59.40662318866803 -146.72214011007085 +259 2.260201381332657 60.68932534675916 -147.24407751714955 +260 2.2689280275926285 61.97638667498025 -147.72116295183125 +261 2.2776546738526 63.267415121982665 -148.15325108927064 +262 2.2863813201125716 64.56201742799506 -148.5402103112355 +263 2.295107966372543 65.85979924461391 -148.88192274619828 +264 2.3038346126325147 67.16036525492594 -149.17828430524096 +265 2.3125612588924866 68.46331929392564 -149.42920471376186 +266 2.321287905152458 69.76826446919057 -149.63460753897365 +267 2.33001455141243 71.07480328177923 -149.79443021318605 +268 2.3387411976724017 72.38253774731245 -149.90862405286435 +269 2.3474678439323733 73.69106951720374 -149.97715427345867 +270 2.356194490192345 75.0 -150.00000000000003 +271 2.3649211364523164 76.30893048279623 -149.9771542734587 +272 2.373647782712288 77.61746225268753 -149.90862405286435 +273 2.3823744289722595 78.92519671822072 -149.7944302131861 +274 2.3911010752322315 80.23173553080939 -149.63460753897365 +275 2.399827721492203 81.53668070607432 -149.4292047137618 +276 2.408554367752175 82.83963474507404 -149.17828430524096 +277 2.4172810140121466 84.14020075538606 -148.88192274619826 +278 2.426007660272118 85.43798257200491 -148.54021031123554 +279 2.4347343065320897 86.73258487801728 -148.15325108927067 +280 2.443460952792061 88.02361332501974 -147.72116295183122 +281 2.4521875990520328 89.31067465324081 -147.2440775171496 +282 2.4609142453120048 90.59337681133195 -146.72214011007082 +283 2.4696408915719763 91.87132907578984 -146.1555097177853 +284 2.478367537831948 93.14414216997505 -145.54435894139948 +285 2.4870941840919194 94.41142838268902 -144.88887394336027 +286 2.495820830351891 95.6728016862749 -144.18925439074783 +287 2.504547476611863 96.92787785420526 -143.4457133944553 +288 2.5132741228718345 98.17627457812102 -142.65847744427307 +289 2.522000769131806 99.41761158428673 -141.8277863398975 +290 2.530727415391778 100.65151074942517 -140.95389311788625 +291 2.5394540616517496 101.87759621589754 -140.03706397458026 +292 2.548180707911721 103.09549450619336 -139.07757818501813 +293 2.5569073541716927 104.30483463669552 -138.07572801786608 +294 2.5656340004316642 105.50524823068496 -137.03181864639018 +295 2.574360646691636 106.69636963055241 -135.94616805549754 +296 2.5830872929516078 107.87783600918081 -134.81910694487505 +297 2.5918139392115793 109.049287480466 -133.6509786282552 +298 2.600540585471551 110.21036720894179 -132.44213892883906 +299 2.609267231731523 111.36072151847529 -131.19295607090933 +300 2.6179938779914944 112.5 -129.9038105676658 +301 2.626720524251466 113.62785561825406 -128.57509510531682 +302 2.6354471705114375 114.74394481749033 -127.20721442346392 +303 2.644173816771409 115.84792762612699 -125.80058519181361 +304 2.652900463031381 116.93946776030603 -124.35563588325626 +305 2.6616271092913526 118.01823272632845 -122.87280664334877 +306 2.670353755551324 119.0838939219355 -121.35254915624212 +307 2.6790804018112957 120.13612673640358 -119.79532650709396 +308 2.6878070480712672 121.17461064942432 -118.20161304100833 +309 2.696533694331239 122.19902932873775 -116.57189421854568 +310 2.705260340591211 123.20907072649044 -114.90666646784672 +311 2.7139869868511823 124.20442717428801 -113.20643703341584 +312 2.7227136331111543 125.18479547691437 -111.47172382160912 +313 2.731440279371126 126.14987700468738 -109.70305524287555 +314 2.7401669256310974 127.09937778442479 -107.90097005079768 +315 2.748893571891069 128.03300858899107 -106.06601717798215 +316 2.7576202181510405 128.95048502539882 -104.19875556884965 +317 2.766346864411012 129.85152762143775 -102.29975400937484 +318 2.7750735106709836 130.73586191080452 -100.36959095382883 +319 2.7838001569309556 131.6032185167079 -98.40885434857609 +320 2.792526803190927 132.45333323392333 -96.41814145298096 +321 2.801253449450899 133.28594710927283 -94.39805865747559 +322 2.8099800957108707 134.10080652050416 -92.3492212988487 +323 2.8187067419708423 134.89766325354694 -90.27225347280722 +324 2.827433388230814 135.67627457812105 -88.16778784387098 +325 2.8361600344907854 136.4364033216744 -86.03646545265696 +326 2.844886680750757 137.1778179416281 -83.87893552061209 +327 2.853613327010729 137.9002925959068 -81.69585525225406 +328 2.8623399732707004 138.60360721173197 -79.48788963498072 +329 2.871066619530672 139.2875475526584 -77.25571123650819 +330 2.8797932657906435 139.95190528383287 -75.00000000000006 +331 2.888519912050615 140.59647803545465 -72.72144303695065 +332 2.897246558310587 141.22106946441951 -70.42073441788365 +333 2.9059732045705586 141.8254893141276 -68.09857496093207 +334 2.91469985083053 142.40955347243752 -65.75567201836171 +335 2.923426497090502 142.97308402774874 -63.392739261104914 +336 2.9321531433504737 143.51590932319507 -61.01049646137005 +337 2.9408797896104453 144.037864008933 -58.60966927339108 +338 2.949606435870417 144.53878909250906 -56.19098901238686 +339 2.9583330821303884 145.01853198729012 -53.755192431795116 +340 2.96705972839036 145.47694655894313 -51.30302149885043 +341 2.975786374650332 145.91389316994875 -48.83522316857347 +342 2.9845130209103035 146.3292387221365 -46.35254915624214 +343 2.993239667170275 146.72285669722766 -43.85575570841059 +344 3.001966313430247 147.0946271953739 -41.34560337254987 +345 3.0106929596902186 147.44443697168012 -38.82285676537812 +346 3.01941960595019 147.7721794706997 -36.2882843399502 +347 3.0281462522101616 148.07775485889266 -33.7426581515798 +348 3.036872898470133 148.3610700550354 -31.186753622663986 +349 3.045599544730105 148.6220387585748 -28.62134930648169 +350 3.0543261909900767 148.86058147591564 -26.047226650039544 +351 3.0630528372500483 149.07662554463533 -23.465169756034662 +352 3.07177948351002 149.27010515561776 -20.87596514400992 +353 3.0805061297699914 149.44096137309913 -18.28040151077223 +354 3.089232776029963 149.58914215262047 -15.679269490148123 +355 3.097959422289935 149.71460235688093 -13.073361412148758 +356 3.1066860685499065 149.81730376948684 -10.463471061618847 +357 3.1154127148098785 149.89721510659302 -7.8503934364414905 +358 3.12413936106985 149.95431202643218 -5.234924505375115 +359 3.1328660073298216 149.98857713672936 -2.6178609655925102 +360 3.141592653589793 150.0 -6.661338147750939e-14 +361 3.1503192998497647 149.98857713672936 2.617860965592477 +362 3.159045946109736 149.95431202643218 5.234924505375048 +363 3.1677725923697078 149.89721510659302 7.850393436441458 +364 3.1764992386296798 149.81730376948684 10.463471061618781 +365 3.1852258848896513 149.71460235688093 13.073361412148692 +366 3.193952531149623 149.58914215262047 15.679269490147922 +367 3.2026791774095944 149.44096137309916 18.280401510771995 +368 3.211405823669566 149.27010515561778 20.87596514400969 +369 3.2201324699295375 149.07662554463536 23.465169756034463 +370 3.2288591161895095 148.86058147591564 26.04722665003948 +371 3.237585762449481 148.6220387585748 28.621349306481626 +372 3.246312408709453 148.36107005503544 31.186753622663918 +373 3.255039054969425 148.07775485889266 33.74265815157987 +374 3.2637657012293966 147.7721794706997 36.28828433995024 +375 3.272492347489368 147.44443697168012 38.822856765378184 +376 3.2812189937493397 147.09462719537387 41.34560337254989 +377 3.2899456400093112 146.72285669722766 43.85575570841053 +378 3.2986722862692828 146.32923872213652 46.35254915624208 +379 3.3073989325292543 145.91389316994875 48.835223168573435 +380 3.3161255787892263 145.47694655894313 51.303021498850356 +381 3.324852225049198 145.01853198729012 53.755192431795045 +382 3.3335788713091694 144.53878909250906 56.19098901238679 +383 3.342305517569141 144.03786400893304 58.60966927339103 +384 3.3510321638291125 143.5159093231951 61.010496461369975 +385 3.359758810089084 142.9730840277488 63.392739261104815 +386 3.368485456349056 142.40955347243752 65.75567201836161 +387 3.3772121026090276 141.8254893141276 68.09857496093198 +388 3.385938748868999 141.22106946441951 70.42073441788355 +389 3.3946653951289707 140.5964780354547 72.72144303695046 +390 3.4033920413889422 139.9519052838329 74.99999999999987 +391 3.412118687648914 139.28754755265848 77.255711236508 +392 3.4208453339088853 138.603607211732 79.4878896349806 +393 3.4295719801688573 137.90029259590685 81.695855252254 +394 3.4382986264288293 137.17781794162812 83.87893552061205 +395 3.447025272688801 136.4364033216744 86.03646545265688 +396 3.455751918948773 135.67627457812102 88.16778784387103 +397 3.4644785652087444 134.89766325354697 90.27225347280731 +398 3.473205211468716 134.10080652050414 92.34922129884875 +399 3.4819318577286875 133.28594710927283 94.39805865747563 +400 3.490658503988659 132.45333323392336 96.41814145298089 +401 3.4993851502486306 131.6032185167079 98.40885434857603 +402 3.5081117965086026 130.73586191080454 100.36959095382879 +403 3.516838442768574 129.85152762143775 102.29975400937477 +404 3.5255650890285457 128.95048502539885 104.19875556884958 +405 3.5342917352885173 128.0330085889911 106.0660171779821 +406 3.543018381548489 127.09937778442482 107.90097005079764 +407 3.5517450278084604 126.1498770046874 109.70305524287551 +408 3.560471674068432 125.18479547691442 111.47172382160905 +409 3.569198320328404 124.20442717428803 113.20643703341578 +410 3.5779249665883754 123.20907072649047 114.90666646784665 +411 3.586651612848347 122.19902932873785 116.57189421854555 +412 3.5953782591083185 121.1746106494244 118.2016130410082 +413 3.60410490536829 120.13612673640367 119.79532650709385 +414 3.6128315516282616 119.08389392193554 121.352549156242 +415 3.6215581978882336 118.01823272632849 122.87280664334872 +416 3.630284844148205 116.93946776030603 124.3556358832562 +417 3.639011490408177 115.84792762612705 125.8005851918136 +418 3.647738136668149 114.74394481749033 127.20721442346394 +419 3.6564647829281207 113.62785561825403 128.57509510531688 +420 3.6651914291880923 112.49999999999999 129.90381056766583 +421 3.673918075448064 111.36072151847527 131.1929560709094 +422 3.6826447217080354 110.21036720894182 132.44213892883903 +423 3.691371367968007 109.04928748046603 133.65097862825513 +424 3.7000980142279785 107.87783600918083 134.81910694487502 +425 3.7088246604879505 106.69636963055244 135.94616805549748 +426 3.717551306747922 105.50524823068501 137.03181864639012 +427 3.7262779530078936 104.30483463669553 138.07572801786603 +428 3.735004599267865 103.09549450619343 139.07757818501807 +429 3.7437312455278366 101.87759621589755 140.0370639745802 +430 3.752457891787808 100.6515107494252 140.95389311788622 +431 3.76118453804778 99.41761158428673 141.8277863398975 +432 3.7699111843077517 98.17627457812105 142.65847744427302 +433 3.7786378305677233 96.92787785420528 143.4457133944553 +434 3.787364476827695 95.67280168627497 144.18925439074778 +435 3.7960911230876664 94.41142838268912 144.88887394336015 +436 3.804817769347638 93.14414216997514 145.5443589413994 +437 3.8135444156076095 91.87132907578996 146.15550971778526 +438 3.8222710618675815 90.593376811332 146.7221401100708 +439 3.8309977081275535 89.31067465324085 147.2440775171496 +440 3.839724354387525 88.0236133250198 147.7211629518312 +441 3.848451000647497 86.73258487801728 148.15325108927067 +442 3.8571776469074686 85.43798257200487 148.54021031123554 +443 3.86590429316744 84.14020075538605 148.88192274619828 +444 3.8746309394274117 82.83963474507401 149.17828430524102 +445 3.883357585687383 81.53668070607439 149.42920471376183 +446 3.8920842319473548 80.2317355308094 149.6346075389736 +447 3.9008108782073267 78.92519671822077 149.79443021318605 +448 3.9095375244672983 77.61746225268755 149.90862405286435 +449 3.91826417072727 76.30893048279626 149.97715427345867 +450 3.9269908169872414 75.00000000000001 150.0 +451 3.935717463247213 73.69106951720377 149.97715427345867 +452 3.9444441095071845 72.38253774731248 149.90862405286435 +453 3.953170755767156 71.07480328177928 149.7944302131861 +454 3.961897402027128 69.76826446919061 149.63460753897365 +455 3.9706240482870996 68.46331929392566 149.4292047137618 +456 3.979350694547071 67.16036525492603 149.17828430524102 +457 3.9880773408070427 65.859799244614 148.88192274619828 +458 3.9968039870670142 64.56201742799516 148.54021031123554 +459 4.005530633326986 63.267415121982765 148.15325108927067 +460 4.014257279586958 61.97638667498026 147.72116295183122 +461 4.022983925846929 60.68932534675927 147.2440775171496 +462 4.031710572106902 59.406623188667986 146.7221401100708 +463 4.040437218366873 58.128670924210155 146.1555097177853 +464 4.049163864626845 56.855857830024895 145.54435894139945 +465 4.057890510886816 55.588571617311 144.88887394336027 +466 4.066617157146788 54.32719831372507 144.1892543907478 +467 4.07534380340676 53.07212214579471 143.4457133944553 +468 4.084070449666731 51.823725421878954 142.65847744427305 +469 4.092797095926703 50.58238841571321 141.8277863398975 +470 4.101523742186674 49.348489250574886 140.95389311788625 +471 4.110250388446646 48.12240378410246 140.03706397458024 +472 4.118977034706617 46.90450549380667 139.07757818501815 +473 4.127703680966589 45.6951653633045 138.07572801786608 +474 4.136430327226561 44.49475176931497 137.03181864639012 +475 4.145156973486532 43.30363036944761 135.94616805549754 +476 4.153883619746504 42.122163990819196 134.81910694487505 +477 4.162610266006475 40.95071251953409 133.65097862825527 +478 4.171336912266447 39.789632791058246 132.44213892883909 +479 4.1800635585264185 38.63927848152484 131.19295607090947 +480 4.1887902047863905 37.50000000000006 129.90381056766583 +481 4.1975168510463625 36.372144381745954 128.57509510531685 +482 4.206243497306334 35.256055182509705 127.20721442346402 +483 4.214970143566306 34.152072373873 125.80058519181364 +484 4.223696789826278 33.06053223969398 124.35563588325626 +485 4.23242343608625 31.981767273671498 122.87280664334867 +486 4.241150082346221 30.91610607806453 121.35254915624213 +487 4.249876728606193 29.863873263596364 119.7953265070939 +488 4.258603374866164 28.82538935057567 118.20161304100833 +489 4.267330021126136 27.800970671262203 116.57189421854561 +490 4.276056667386108 26.790929273509516 114.90666646784662 +491 4.284783313646079 25.795572825711986 113.20643703341585 +492 4.293509959906051 24.81520452308564 111.47172382160912 +493 4.302236606166022 23.850122995312663 109.70305524287565 +494 4.310963252425994 22.900622215575222 107.9009700507977 +495 4.319689898685965 21.966991411008998 106.06601717798223 +496 4.328416544945937 21.04951497460117 104.19875556884968 +497 4.337143191205909 20.1484723785622 102.29975400937475 +498 4.34586983746588 19.264138089195466 100.36959095382882 +499 4.354596483725852 18.396781483292106 98.40885434857611 +500 4.363323129985823 17.546666766076697 96.41814145298106 +501 4.372049776245795 16.714052890727224 94.39805865747572 +502 4.380776422505767 15.899193479495866 92.34922129884875 +503 4.389503068765738 15.102336746453087 90.27225347280735 +504 4.39822971502571 14.32372542187894 88.16778784387103 +505 4.4069563612856815 13.56359667832569 86.03646545265705 +506 4.4156830075456535 12.822182058371911 83.87893552061213 +507 4.4244096538056255 12.099707404093197 81.69585525225406 +508 4.4331363000655974 11.39639278826802 79.48788963498065 +509 4.4418629463255686 10.712452447341592 77.25571123650819 +510 4.4505895925855405 10.048094716167089 74.99999999999997 +511 4.4593162388455125 9.40352196454527 72.72144303695045 +512 4.468042885105484 8.778930535580484 70.42073441788365 +513 4.476769531365456 8.174510685872399 68.09857496093193 +514 4.485496177625427 7.590446527562506 65.75567201836171 +515 4.494222823885399 7.026915972251246 63.392739261104914 +516 4.50294947014537 6.484090676804969 61.010496461370174 +517 4.511676116405342 5.962135991066997 58.60966927339108 +518 4.520402762665314 5.461210907490935 56.190989012386744 +519 4.529129408925285 4.981468012709886 53.755192431795116 +520 4.537856055185257 4.5230534410568595 51.3030214988503 +521 4.546582701445228 4.0861068300512615 48.83522316857363 +522 4.5553093477052 3.6707612778634853 46.35254915624218 +523 4.564035993965171 3.277143302772351 43.85575570841071 +524 4.572762640225143 2.9053728046261 41.34560337255 +525 4.581489286485115 2.5555630283198685 38.82285676537811 +526 4.590215932745086 2.2278205293002977 36.28828433995034 +527 4.598942579005058 1.9222451411073482 33.74265815157983 +528 4.607669225265029 1.638929944964615 31.18675362266411 +529 4.616395871525002 1.3779612414251852 28.621349306481587 +530 4.625122517784973 1.1394185240843901 26.047226650039576 +531 4.633849164044945 0.9233744553646506 23.465169756034562 +532 4.642575810304916 0.7298948443822395 20.875965144009914 +533 4.651302456564888 0.5590386269008513 18.280401510772094 +534 4.66002910282486 0.41085784737950326 15.679269490147892 +535 4.6687557490848315 0.28539764311909244 13.073361412148756 +536 4.6774823953448035 0.1826962305131935 10.463471061618746 +537 4.686209041604775 0.10278489340696251 7.85039343644169 +538 4.694935687864747 0.04568797356781784 5.234924505375147 +539 4.703662334124718 0.011422863270654782 2.617860965592676 +540 4.71238898038469 0.0 6.661338147750939e-14 +541 4.721115626644662 0.011422863270654782 -2.617860965592576 +542 4.729842272904633 0.04568797356781784 -5.234924505375048 +543 4.738568919164605 0.10278489340696251 -7.850393436441557 +544 4.747295565424576 0.18269623051318518 -10.463471061618645 +545 4.756022211684548 0.28539764311909244 -13.073361412148623 +546 4.764748857944519 0.41085784737950326 -15.679269490147792 +547 4.773475504204491 0.559038626900818 -18.280401510771966 +548 4.782202150464463 0.7298948443822312 -20.875965144009783 +549 4.790928796724434 0.9233744553646422 -23.465169756034463 +550 4.799655442984406 1.1394185240843901 -26.047226650039473 +551 4.808382089244377 1.3779612414251852 -28.621349306481488 +552 4.81710873550435 1.6389299449646066 -31.186753622664042 +553 4.825835381764321 1.9222451411073398 -33.74265815157973 +554 4.834562028024293 2.2278205293002893 -36.2882843399502 +555 4.843288674284264 2.55556302831986 -38.82285676537804 +556 4.852015320544236 2.9053728046260745 -41.34560337254987 +557 4.860741966804208 3.2771433027723424 -43.85575570841059 +558 4.869468613064179 3.670761277863477 -46.35254915624208 +559 4.878195259324151 4.0861068300512535 -48.835223168573535 +560 4.886921905584122 4.5230534410568515 -51.303021498850235 +561 4.895648551844094 4.981468012709886 -53.755192431795045 +562 4.9043751981040655 5.461210907490926 -56.190989012386616 +563 4.9131018443640375 5.962135991066956 -58.60966927339103 +564 4.9218284906240095 6.484090676804927 -61.01049646137005 +565 4.930555136883981 7.0269159722512295 -63.39273926110477 +566 4.939281783143953 7.590446527562489 -65.75567201836157 +567 4.948008429403924 8.174510685872367 -68.09857496093187 +568 4.956735075663896 8.778930535580468 -70.42073441788351 +569 4.965461721923867 9.403521964545252 -72.72144303695033 +570 4.974188368183839 10.04809471616708 -74.99999999999987 +571 4.982915014443811 10.712452447341583 -77.2557112365081 +572 4.991641660703782 11.396392788268003 -79.48788963498053 +573 5.000368306963754 12.099707404093172 -81.695855252254 +574 5.009094953223726 12.82218205837187 -83.87893552061203 +575 5.017821599483698 13.56359667832564 -86.03646545265698 +576 5.026548245743669 14.323725421878924 -88.16778784387093 +577 5.035274892003641 15.102336746453046 -90.27225347280728 +578 5.044001538263612 15.899193479495816 -92.34922129884863 +579 5.052728184523584 16.714052890727192 -94.39805865747559 +580 5.061454830783556 17.546666766076648 -96.41814145298093 +581 5.070181477043527 18.39678148329208 -98.40885434857604 +582 5.078908123303499 19.26413808919545 -100.36959095382879 +583 5.08763476956347 20.14847237856215 -102.2997540093747 +584 5.096361415823442 21.049514974601152 -104.19875556884958 +585 5.105088062083414 21.966991411008973 -106.06601717798219 +586 5.113814708343385 22.900622215575172 -107.90097005079764 +587 5.122541354603357 23.850122995312606 -109.70305524287556 +588 5.1312680008633285 24.815204523085566 -111.47172382160905 +589 5.1399946471233005 25.795572825711947 -113.20643703341577 +590 5.148721293383272 26.790929273509473 -114.90666646784659 +591 5.1574479396432436 27.800970671262153 -116.57189421854555 +592 5.1661745859032155 28.82538935057562 -118.2016130410083 +593 5.174901232163187 29.863873263596314 -119.79532650709385 +594 5.183627878423159 30.916106078064505 -121.3525491562421 +595 5.19235452468313 31.981767273671448 -122.87280664334864 +596 5.201081170943102 33.060532239693934 -124.35563588325614 +597 5.209807817203074 34.15207237387296 -125.8005851918136 +598 5.218534463463046 35.25605518250966 -127.20721442346392 +599 5.227261109723017 36.37214438174587 -128.5750951053168 +600 5.235987755982989 37.50000000000001 -129.9038105676658 +601 5.244714402242961 38.63927848152477 -131.19295607090945 +602 5.253441048502932 39.789632791058196 -132.44213892883903 +603 5.262167694762904 40.95071251953401 -133.65097862825525 +604 5.270894341022875 42.12216399081916 -134.819106944875 +605 5.279620987282847 43.30363036944755 -135.94616805549754 +606 5.288347633542818 44.494751769314924 -137.03181864639006 +607 5.29707427980279 45.69516536330446 -138.07572801786603 +608 5.305800926062762 46.90450549380662 -139.07757818501813 +609 5.314527572322733 48.12240378410243 -140.0370639745802 +610 5.323254218582705 49.34848925057485 -140.95389311788622 +611 5.331980864842676 50.58238841571318 -141.82778633989747 +612 5.340707511102648 51.823725421878905 -142.65847744427302 +613 5.349434157362619 53.07212214579462 -143.44571339445523 +614 5.358160803622591 54.32719831372502 -144.18925439074778 +615 5.366887449882563 55.588571617310926 -144.8888739433602 +616 5.3756140961425345 56.85585783002482 -145.5443589413994 +617 5.3843407424025065 58.128670924210084 -146.15550971778526 +618 5.393067388662478 59.40662318866794 -146.7221401100708 +619 5.4017940349224505 60.68932534675921 -147.24407751714963 +620 5.410520681182422 61.97638667498021 -147.7211629518312 +621 5.419247327442394 63.26741512198272 -148.15325108927067 +622 5.427973973702365 64.56201742799503 -148.5402103112355 +623 5.436700619962337 65.85979924461398 -148.88192274619828 +624 5.445427266222309 67.16036525492603 -149.17828430524102 +625 5.45415391248228 68.46331929392561 -149.42920471376183 +626 5.462880558742252 69.76826446919063 -149.63460753897363 +627 5.471607205002223 71.07480328177917 -149.79443021318605 +628 5.480333851262195 72.38253774731241 -149.90862405286435 +629 5.489060497522166 73.69106951720363 -149.97715427345867 +630 5.497787143782138 74.99999999999999 -150.0 +631 5.50651379004211 76.30893048279628 -149.9771542734587 +632 5.515240436302081 77.61746225268752 -149.90862405286435 +633 5.523967082562053 78.92519671822077 -149.79443021318605 +634 5.532693728822024 80.23173553080932 -149.63460753897365 +635 5.541420375081996 81.53668070607432 -149.42920471376186 +636 5.550147021341967 82.83963474507388 -149.178284305241 +637 5.558873667601939 84.14020075538599 -148.88192274619834 +638 5.567600313861911 85.43798257200487 -148.54021031123554 +639 5.576326960121882 86.73258487801724 -148.1532510892707 +640 5.585053606381854 88.02361332501974 -147.72116295183122 +641 5.593780252641825 89.31067465324075 -147.24407751714966 +642 5.602506898901798 90.593376811332 -146.7221401100708 +643 5.611233545161769 91.87132907578986 -146.15550971778526 +644 5.619960191421741 93.14414216997508 -145.54435894139945 +645 5.6286868376817125 94.41142838268901 -144.88887394336027 +646 5.6374134839416845 95.67280168627494 -144.1892543907478 +647 5.6461401302016565 96.92787785420532 -143.44571339445528 +648 5.654866776461628 98.17627457812104 -142.65847744427305 +649 5.6635934227216 99.41761158428677 -141.82778633989747 +650 5.672320068981571 100.65151074942507 -140.95389311788628 +651 5.681046715241543 101.87759621589748 -140.03706397458026 +652 5.689773361501514 103.09549450619333 -139.07757818501815 +653 5.698500007761486 104.3048346366955 -138.07572801786608 +654 5.707226654021458 105.50524823068503 -137.03181864639012 +655 5.715953300281429 106.69636963055238 -135.94616805549754 +656 5.724679946541401 107.87783600918078 -134.81910694487505 +657 5.733406592801372 109.0492874804659 -133.6509786282553 +658 5.742133239061344 110.21036720894176 -132.44213892883909 +659 5.750859885321315 111.36072151847516 -131.19295607090953 +660 5.759586531581287 112.49999999999993 -129.9038105676659 +661 5.768313177841259 113.62785561825406 -128.57509510531688 +662 5.77703982410123 114.74394481749029 -127.20721442346401 +663 5.785766470361202 115.84792762612697 -125.80058519181367 +664 5.794493116621174 116.93946776030603 -124.35563588325626 +665 5.803219762881146 118.01823272632849 -122.87280664334872 +666 5.811946409141117 119.08389392193547 -121.35254915624215 +667 5.820673055401089 120.13612673640364 -119.79532650709392 +668 5.82939970166106 121.1746106494243 -118.20161304100837 +669 5.838126347921032 122.1990293287378 -116.57189421854565 +670 5.846852994181004 123.20907072649047 -114.90666646784665 +671 5.8555796404409755 124.20442717428801 -113.20643703341587 +672 5.8643062867009474 125.18479547691437 -111.47172382160912 +673 5.8730329329609186 126.14987700468733 -109.70305524287569 +674 5.8817595792208905 127.09937778442479 -107.90097005079771 +675 5.890486225480862 128.03300858899098 -106.06601717798225 +676 5.899212871740834 128.9504850253988 -104.19875556884968 +677 5.907939518000806 129.85152762143775 -102.29975400937477 +678 5.916666164260777 130.73586191080452 -100.36959095382883 +679 5.925392810520749 131.60321851670787 -98.40885434857616 +680 5.93411945678072 132.45333323392327 -96.41814145298109 +681 5.942846103040692 133.28594710927274 -94.39805865747569 +682 5.951572749300664 134.10080652050416 -92.34922129884876 +683 5.960299395560635 134.8976632535469 -90.2722534728074 +684 5.969026041820607 135.67627457812102 -88.167787843871 +685 5.977752688080578 136.43640332167433 -86.03646545265713 +686 5.98647933434055 137.17781794162806 -83.87893552061215 +687 5.995205980600522 137.9002925959068 -81.69585525225406 +688 6.003932626860494 138.60360721173197 -79.48788963498065 +689 6.012659273120465 139.2875475526584 -77.2557112365082 +690 6.021385919380437 139.95190528383287 -75.0 +691 6.030112565640409 140.59647803545474 -72.72144303695046 +692 6.03883921190038 141.2210694644195 -70.42073441788365 +693 6.047565858160352 141.82548931412762 -68.09857496093197 +694 6.056292504420323 142.40955347243752 -65.75567201836171 +695 6.065019150680295 142.97308402774874 -63.392739261104914 +696 6.073745796940266 143.51590932319505 -61.01049646137018 +697 6.082472443200238 144.03786400893304 -58.60966927339113 +698 6.09119908946021 144.5387890925091 -56.19098901238675 +699 6.0999257357201815 145.01853198729012 -53.75519243179515 +700 6.1086523819801535 145.47694655894313 -51.303021498850335 +701 6.117379028240125 145.91389316994875 -48.83522316857368 +702 6.126105674500097 146.32923872213652 -46.35254915624221 +703 6.134832320760068 146.72285669722766 -43.85575570841071 +704 6.14355896702004 147.0946271953739 -41.34560337255001 +705 6.152285613280012 147.44443697168012 -38.82285676537814 +706 6.161012259539983 147.77217947069974 -36.288284339950344 +707 6.169738905799955 148.07775485889266 -33.74265815157983 +708 6.178465552059926 148.36107005503538 -31.186753622664142 +709 6.187192198319899 148.6220387585748 -28.621349306481626 +710 6.19591884457987 148.8605814759156 -26.04722665003961 +711 6.204645490839842 149.07662554463536 -23.465169756034562 +712 6.213372137099813 149.27010515561776 -20.87596514400992 +713 6.222098783359785 149.44096137309916 -18.280401510772126 +714 6.230825429619757 149.58914215262047 -15.679269490147922 +715 6.239552075879728 149.71460235688093 -13.07336141214879 +716 6.2482787221397 149.81730376948678 -10.463471061618744 +717 6.257005368399671 149.89721510659302 -7.85039343644169 +718 6.265732014659643 149.95431202643218 -5.234924505375147 +719 6.274458660919614 149.98857713672933 -2.61786096559271 + +HARMONIC_2 +N 720 RADIANS + +0 0.0 0.0 -0.0 +1 0.008726646259971648 0.027412784140690705 -6.2819094064501355 +2 0.017453292519943295 0.10961773830790611 -12.55616527394248 +3 0.02617993877991494 0.24651470842771694 -18.81512338817758 +4 0.03490658503988659 0.4379369066293687 -25.051158172811725 +5 0.04363323129985824 0.6836511144506341 -31.25667198004754 +6 0.05235987755982988 0.983357966978734 -37.424104347196625 +7 0.061086523819801536 1.3366923175801637 -43.54594120794012 +8 0.06981317007977318 1.7432236827756546 -49.61472404705978 +9 0.07853981633974483 2.2024567667180763 -55.62305898749062 +10 0.08726646259971647 2.713832064634096 -61.56362579862038 +11 0.09599310885968812 3.276726544494581 -67.42918681486422 +12 0.10471975511965977 3.890454406082966 -73.21259575364407 +13 0.11344640137963141 4.554267916537463 -78.90680642203391 +14 0.12217304763960307 5.267358321348265 -84.50488130146033 +15 0.1308996938995747 6.028856829700248 -90.00000000000001 +16 0.13962634015954636 6.837835672960817 -95.38546756197688 +17 0.148352986419518 7.693309235023127 -100.65472262473446 +18 0.15707963267948966 8.594235253127374 -105.80134541264522 +19 0.16580627893946132 9.539516087697514 -110.81906555861842 +20 0.17453292519943295 10.528000059645974 -115.70176974357709 +21 0.1832595714594046 11.558482853517255 -120.44350914459449 +22 0.19198621771937624 12.629708984760681 -125.03850668261958 +23 0.20071286397934787 13.740373329345113 -129.48116406095727 +24 0.20943951023931953 14.889122713851378 -133.76606858593104 +25 0.2181661564992912 16.074557564105724 -137.88799976141604 +26 0.22689280275926282 17.295233610345345 -141.84193564920994 +27 0.23561944901923448 18.549663646838678 -145.6230589874906 +28 0.24434609527920614 19.836319343816424 -149.2267630599075 +29 0.2530727415391778 21.15363310950578 -152.64865730815677 +30 0.2617993877991494 22.50000000000001 -155.88457268119893 +31 0.27052603405912107 23.87377967463492 -158.93056671460687 +32 0.2792526803190927 25.273298394491498 -161.78292833385004 +33 0.28797932657906433 26.696851061588994 -164.43818237566816 +34 0.296705972839036 28.142703296283962 -166.8930938220218 +35 0.30543261909900765 29.60909355034492 -169.14467174146358 +36 0.3141592653589793 31.094235253127366 -171.19017293312768 +37 0.32288591161895097 32.59631898823504 -173.0271052688973 +38 0.33161255787892263 34.11351469801494 -174.65323072967948 +39 0.3403392041388943 35.64397391320081 -176.06656813208505 +40 0.3490658503988659 37.185832004988114 -177.26539554219747 +41 0.35779249665883756 38.73721045679706 -178.24825237348261 +42 0.3665191429188092 40.29621915295561 -179.01394116628916 +43 0.3752457891787809 41.86095868151437 -179.56152904676833 +44 0.3839724354387525 43.42952264838744 -179.89034886343723 +45 0.39269908169872414 45.00000000000002 -180.00000000000003 +46 0.40142572795869574 46.57047735161251 -179.8903488634373 +47 0.41015237421866746 48.139041318485646 -179.56152904676833 +48 0.41887902047863906 49.70378084704442 -179.0139411662891 +49 0.42760566673861067 51.262789543202935 -178.24825237348256 +50 0.4363323129985824 52.81416799501187 -177.26539554219747 +51 0.445058959258554 54.35602608679914 -176.0665681320851 +52 0.45378560551852565 55.88648530198504 -174.6532307296794 +53 0.4625122517784973 57.40368101176496 -173.02710526889746 +54 0.47123889803846897 58.905764746872634 -171.19017293312766 +55 0.4799655442984406 60.3909064496551 -169.14467174146353 +56 0.4886921905584123 61.85729670371604 -166.89309382202177 +57 0.4974188368183839 63.303148938411006 -164.43818237566816 +58 0.5061454830783556 64.7267016055085 -161.78292833385 +59 0.5148721293383272 66.12622032536507 -158.93056671460687 +60 0.5235987755982988 67.49999999999999 -155.88457268119902 +61 0.5323254218582705 68.8463668904942 -152.64865730815671 +62 0.5410520681182421 70.16368065618362 -149.22676305990743 +63 0.5497787143782138 71.4503363531613 -145.6230589874906 +64 0.5585053606381855 72.70476638965464 -141.84193564920994 +65 0.5672320068981571 73.9254424358943 -137.887999761416 +66 0.5759586531581287 75.11087728614861 -133.76606858593098 +67 0.5846852994181004 76.2596266706549 -129.4811640609572 +68 0.593411945678072 77.37029101523932 -125.03850668261944 +69 0.6021385919380438 78.44151714648277 -120.4435091445944 +70 0.6108652381980153 79.47199994035401 -115.70176974357716 +71 0.619591884457987 80.4604839123025 -110.81906555861849 +72 0.6283185307179586 81.40576474687263 -105.80134541264516 +73 0.6370451769779303 82.30669076497688 -100.65472262473438 +74 0.6457718232379019 83.16216432703916 -95.38546756197684 +75 0.6544984694978736 83.97114317029974 -89.99999999999999 +76 0.6632251157578453 84.73264167865172 -84.50488130146033 +77 0.6719517620178168 85.4457320834625 -78.90680642203387 +78 0.6806784082777886 86.10954559391705 -73.21259575364402 +79 0.6894050545377601 86.72327345550543 -67.42918681486411 +80 0.6981317007977318 87.2861679353659 -61.56362579862036 +81 0.7068583470577035 87.79754323328191 -55.62305898749052 +82 0.7155849933176751 88.25677631722436 -49.61472404705994 +83 0.7243116395776468 88.66330768241984 -43.545941207940224 +84 0.7330382858376184 89.01664203302126 -37.42410434719666 +85 0.74176493209759 89.31634888554936 -31.256671980047535 +86 0.7504915783575618 89.56206309337068 -25.051158172811732 +87 0.7592182246175333 89.7534852915723 -18.815123388177597 +88 0.767944870877505 89.89038226169208 -12.556165273942534 +89 0.7766715171374766 89.97258721585929 -6.281909406450126 +90 0.7853981633974483 90.0 -0.0 +91 0.7941248096574199 89.97258721585929 6.281909406450126 +92 0.8028514559173915 89.89038226169208 12.556165273942534 +93 0.8115781021773633 89.7534852915723 18.815123388177597 +94 0.8203047484373349 89.56206309337068 25.051158172811732 +95 0.8290313946973066 89.31634888554937 31.256671980047386 +96 0.8377580409572781 89.01664203302127 37.42410434719654 +97 0.8464846872172498 88.66330768241984 43.54594120794002 +98 0.8552113334772213 88.25677631722434 49.61472404705979 +99 0.8639379797371932 87.79754323328191 55.62305898749072 +100 0.8726646259971648 87.2861679353659 61.56362579862031 +101 0.8813912722571364 86.72327345550542 67.42918681486421 +102 0.890117918517108 86.10954559391705 73.21259575364402 +103 0.8988445647770796 85.44573208346254 78.90680642203387 +104 0.9075712110370513 84.73264167865172 84.50488130146033 +105 0.9162978572970231 83.97114317029973 90.00000000000004 +106 0.9250245035569946 83.1621643270392 95.38546756197682 +107 0.9337511498169663 82.30669076497686 100.65472262473436 +108 0.9424777960769379 81.40576474687263 105.80134541264516 +109 0.9512044423369095 80.4604839123025 110.81906555861842 +110 0.9599310885968813 79.47199994035401 115.70176974357716 +111 0.9686577348568529 78.44151714648272 120.44350914459453 +112 0.9773843811168246 77.3702910152393 125.03850668261954 +113 0.9861110273767961 76.25962667065488 129.48116406095718 +114 0.9948376736367678 75.11087728614864 133.76606858593098 +115 1.0035643198967394 73.9254424358943 137.887999761416 +116 1.0122909661567112 72.70476638965464 141.84193564920994 +117 1.0210176124166828 71.4503363531613 145.6230589874906 +118 1.0297442586766543 70.16368065618362 149.22676305990743 +119 1.038470904936626 68.84636689049425 152.64865730815666 +120 1.0471975511965976 67.5 155.8845726811989 +121 1.0559241974565694 66.12622032536508 158.93056671460678 +122 1.064650843716541 64.72670160550852 161.78292833384995 +123 1.0733774899765127 63.30314893841102 164.43818237566816 +124 1.0821041362364843 61.85729670371604 166.89309382202177 +125 1.0908307824964558 60.39090644965513 169.14467174146347 +126 1.0995574287564276 58.905764746872634 171.19017293312766 +127 1.1082840750163994 57.40368101176494 173.02710526889743 +128 1.117010721276371 55.88648530198504 174.6532307296794 +129 1.1257373675363425 54.35602608679919 176.06656813208497 +130 1.1344640137963142 52.814167995011864 177.2653955421975 +131 1.1431906600562858 51.262789543202956 178.24825237348256 +132 1.1519173063162573 49.70378084704444 179.01394116628916 +133 1.160643952576229 48.13904131848563 179.56152904676836 +134 1.1693705988362009 46.57047735161251 179.8903488634373 +135 1.1780972450961724 45.00000000000002 180.00000000000003 +136 1.186823891356144 43.42952264838747 179.89034886343728 +137 1.1955505376161157 41.86095868151437 179.56152904676838 +138 1.2042771838760875 40.296219152955565 179.0139411662892 +139 1.213003830136059 38.73721045679706 178.24825237348261 +140 1.2217304763960306 37.18583200498815 177.26539554219755 +141 1.2304571226560024 35.64397391320081 176.06656813208505 +142 1.239183768915974 34.11351469801496 174.65323072967934 +143 1.2479104151759455 32.59631898823506 173.02710526889743 +144 1.2566370614359172 31.094235253127366 171.19017293312768 +145 1.265363707695889 29.609093550344895 169.14467174146347 +146 1.2740903539558606 28.142703296283962 166.8930938220218 +147 1.2828170002158321 26.696851061589022 164.43818237566828 +148 1.2915436464758039 25.273298394491498 161.78292833385004 +149 1.3002702927357754 23.873779674634918 158.9305667146068 +150 1.3089969389957472 22.499999999999996 155.88457268119896 +151 1.3177235852557188 21.15363310950579 152.64865730815671 +152 1.3264502315156905 19.836319343816385 149.22676305990748 +153 1.335176877775662 18.549663646838727 145.62305898749062 +154 1.3439035240356336 17.295233610345395 141.84193564920997 +155 1.3526301702956054 16.074557564105724 137.88799976141604 +156 1.3613568165555772 14.889122713851354 133.7660685859309 +157 1.3700834628155487 13.740373329345113 129.48116406095727 +158 1.3788101090755203 12.629708984760697 125.03850668261954 +159 1.3875367553354918 11.558482853517294 120.4435091445946 +160 1.3962634015954636 10.528000059645994 115.7017697435772 +161 1.4049900478554354 9.5395160876975 110.81906555861845 +162 1.413716694115407 8.594235253127374 105.80134541264522 +163 1.4224433403753785 7.693309235023142 100.6547226247346 +164 1.4311699866353502 6.837835672960817 95.38546756197688 +165 1.4398966328953218 6.028856829700258 90.00000000000016 +166 1.4486232791552935 5.267358321348265 84.50488130146033 +167 1.457349925415265 4.5542679165374835 78.90680642203405 +168 1.4660765716752369 3.890454406082966 73.21259575364407 +169 1.4748032179352084 3.276726544494581 67.42918681486422 +170 1.48352986419518 2.713832064634131 61.5636257986205 +171 1.4922565104551517 2.2024567667180763 55.62305898749062 +172 1.5009831567151235 1.7432236827756498 49.61472404705977 +173 1.509709802975095 1.3366923175801686 43.545941207940274 +174 1.5184364492350666 0.983357966978759 37.424104347196774 +175 1.5271630954950384 0.6836511144506491 31.25667198004752 +176 1.53588974175501 0.4379369066293537 25.051158172811895 +177 1.5446163880149815 0.24651470842770196 18.815123388177746 +178 1.5533430342749532 0.10961773830790611 12.55616527394264 +179 1.562069680534925 0.027412784140690705 6.281909406450135 +180 1.5707963267948966 0.0 -0.0 +181 1.579522973054868 0.027412784140690705 -6.281909406450055 +182 1.5882496193148399 0.10961773830790611 -12.55616527394256 +183 1.5969762655748114 0.24651470842769696 -18.815123388177504 +184 1.605702911834783 0.4379369066293487 -25.051158172811576 +185 1.6144295580947547 0.6836511144506091 -31.2566719800474 +186 1.6231562043547265 0.983357966978754 -37.42410434719669 +187 1.6318828506146983 1.3366923175801686 -43.545941207940274 +188 1.6406094968746698 1.7432236827756546 -49.61472404705985 +189 1.6493361431346414 2.202456766718066 -55.62305898749046 +190 1.6580627893946132 2.7138320646341207 -61.56362579862043 +191 1.6667894356545847 3.276726544494561 -67.42918681486417 +192 1.6755160819145563 3.890454406082956 -73.2125957536439 +193 1.684242728174528 4.554267916537463 -78.90680642203391 +194 1.6929693744344996 5.267358321348261 -84.50488130146024 +195 1.7016960206944711 6.028856829700228 -89.99999999999987 +196 1.7104226669544427 6.837835672960802 -95.38546756197677 +197 1.7191493132144147 7.693309235023127 -100.65472262473446 +198 1.7278759594743864 8.594235253127385 -105.8013454126453 +199 1.736602605734358 9.539516087697509 -110.81906555861852 +200 1.7453292519943295 10.528000059645974 -115.70176974357709 +201 1.7540558982543013 11.558482853517269 -120.44350914459446 +202 1.7627825445142729 12.629708984760697 -125.03850668261954 +203 1.7715091907742444 13.740373329345093 -129.48116406095713 +204 1.780235837034216 14.889122713851354 -133.7660685859309 +205 1.7889624832941877 16.074557564105724 -137.88799976141604 +206 1.7976891295541593 17.295233610345345 -141.84193564920994 +207 1.8064157758141308 18.54966364683865 -145.62305898749042 +208 1.8151424220741026 19.836319343816385 -149.22676305990748 +209 1.8238690683340746 21.15363310950582 -152.6486573081567 +210 1.8325957145940461 22.50000000000001 -155.88457268119905 +211 1.8413223608540177 23.873779674634918 -158.9305667146068 +212 1.8500490071139892 25.273298394491498 -161.78292833385004 +213 1.858775653373961 26.696851061588987 -164.43818237566813 +214 1.8675022996339325 28.14270329628394 -166.89309382202174 +215 1.876228945893904 29.609093550344895 -169.14467174146347 +216 1.8849555921538759 31.09423525312735 -171.19017293312763 +217 1.8936822384138474 32.59631898823501 -173.02710526889732 +218 1.902408884673819 34.11351469801491 -174.6532307296794 +219 1.9111355309337907 35.64397391320081 -176.06656813208505 +220 1.9198621771937625 37.185832004988114 -177.2653955421974 +221 1.9285888234537343 38.73721045679706 -178.24825237348261 +222 1.9373154697137058 40.2962191529556 -179.01394116628924 +223 1.9460421159736774 41.86095868151434 -179.56152904676836 +224 1.9547687622336491 43.42952264838746 -179.89034886343725 +225 1.9634954084936207 45.0 -180.0 +226 1.9722220547535922 46.57047735161251 -179.8903488634373 +227 1.980948701013564 48.13904131848563 -179.56152904676836 +228 1.9896753472735356 49.70378084704437 -179.0139411662891 +229 1.9984019935335071 51.262789543202906 -178.24825237348261 +230 2.007128639793479 52.814167995011836 -177.2653955421975 +231 2.015855286053451 54.35602608679921 -176.06656813208497 +232 2.0245819323134224 55.88648530198507 -174.65323072967934 +233 2.033308578573394 57.40368101176497 -173.02710526889737 +234 2.0420352248333655 58.905764746872634 -171.19017293312766 +235 2.050761871093337 60.39090644965504 -169.14467174146355 +236 2.0594885173533086 61.857296703715996 -166.89309382202183 +237 2.0682151636132806 63.30314893841102 -164.43818237566816 +238 2.076941809873252 64.72670160550847 -161.78292833385 +239 2.0856684561332237 66.12622032536507 -158.93056671460687 +240 2.0943951023931953 67.49999999999996 -155.8845726811991 +241 2.103121748653167 68.84636689049415 -152.6486573081569 +242 2.111848394913139 70.1636806561836 -149.22676305990746 +243 2.1205750411731104 71.4503363531613 -145.6230589874906 +244 2.129301687433082 72.7047663896546 -141.84193564920994 +245 2.138028333693054 73.9254424358943 -137.887999761416 +246 2.1467549799530254 75.11087728614862 -133.76606858593098 +247 2.155481626212997 76.25962667065488 -129.48116406095718 +248 2.1642082724729685 77.3702910152393 -125.03850668261954 +249 2.17293491873294 78.4415171464827 -120.44350914459473 +250 2.1816615649929116 79.47199994035397 -115.70176974357719 +251 2.1903882112528836 80.4604839123025 -110.81906555861858 +252 2.199114857512855 81.40576474687262 -105.8013454126452 +253 2.2078415037728267 82.30669076497685 -100.65472262473452 +254 2.2165681500327987 83.16216432703918 -95.38546756197684 +255 2.2252947962927703 83.97114317029973 -90.00000000000004 +256 2.234021442552742 84.73264167865172 -84.50488130146036 +257 2.2427480888127134 85.44573208346253 -78.90680642203401 +258 2.251474735072685 86.10954559391705 -73.21259575364415 +259 2.260201381332657 86.72327345550542 -67.42918681486404 +260 2.2689280275926285 87.2861679353659 -61.56362579862031 +261 2.2776546738526 87.7975432332819 -55.62305898749065 +262 2.2863813201125716 88.25677631722434 -49.61472404706005 +263 2.295107966372543 88.66330768241983 -43.545941207940366 +264 2.3038346126325147 89.01664203302124 -37.42410434719695 +265 2.3125612588924866 89.31634888554939 -31.256671980047425 +266 2.321287905152458 89.56206309337068 -25.051158172811952 +267 2.33001455141243 89.75348529157229 -18.815123388177536 +268 2.3387411976724017 89.8903822616921 -12.556165273942474 +269 2.3474678439323733 89.97258721585929 -6.281909406450126 +270 2.356194490192345 90.0 -0.0 +271 2.3649211364523164 89.97258721585932 6.281909406449996 +272 2.373647782712288 89.8903822616921 12.556165273942385 +273 2.3823744289722595 89.7534852915723 18.815123388177277 +274 2.3911010752322315 89.56206309337068 25.051158172811732 +275 2.399827721492203 89.31634888554936 31.256671980047305 +276 2.408554367752175 89.01664203302124 37.424104347196824 +277 2.4172810140121466 88.66330768241981 43.545941207940174 +278 2.426007660272118 88.25677631722435 49.61472404705985 +279 2.4347343065320897 87.79754323328193 55.62305898749038 +280 2.443460952792061 87.2861679353659 61.56362579862025 +281 2.4521875990520328 86.72327345550545 67.42918681486397 +282 2.4609142453120048 86.10954559391703 73.21259575364407 +283 2.4696408915719763 85.44573208346253 78.90680642203377 +284 2.478367537831948 84.73264167865173 84.50488130146026 +285 2.4870941840919194 83.97114317029977 89.99999999999989 +286 2.495820830351891 83.16216432703918 95.38546756197668 +287 2.504547476611863 82.30669076497688 100.65472262473438 +288 2.5132741228718345 81.40576474687268 105.80134541264506 +289 2.522000769131806 80.4604839123025 110.81906555861842 +290 2.530727415391778 79.47199994035401 115.70176974357716 +291 2.5394540616517496 78.44151714648274 120.4435091445945 +292 2.548180707911721 77.37029101523933 125.03850668261934 +293 2.5569073541716927 76.2596266706549 129.4811640609572 +294 2.5656340004316642 75.11087728614866 133.76606858593075 +295 2.574360646691636 73.92544243589431 137.88799976141587 +296 2.5830872929516078 72.70476638965462 141.84193564920997 +297 2.5918139392115793 71.4503363531613 145.6230589874906 +298 2.600540585471551 70.16368065618362 149.22676305990743 +299 2.609267231731523 68.8463668904942 152.64865730815671 +300 2.6179938779914944 67.5 155.8845726811989 +301 2.626720524251466 66.12622032536508 158.93056671460678 +302 2.6354471705114375 64.72670160550852 161.78292833384995 +303 2.644173816771409 63.303148938411034 164.43818237566802 +304 2.652900463031381 61.85729670371604 166.89309382202177 +305 2.6616271092913526 60.3909064496551 169.1446717414635 +306 2.670353755551324 58.905764746872634 171.19017293312766 +307 2.6790804018112957 57.403681011765 173.0271052688973 +308 2.6878070480712672 55.886485301985104 174.65323072967925 +309 2.696533694331239 54.35602608679924 176.06656813208485 +310 2.705260340591211 52.81416799501187 177.26539554219747 +311 2.7139869868511823 51.26278954320299 178.24825237348256 +312 2.7227136331111543 49.7037808470444 179.0139411662892 +313 2.731440279371126 48.139041318485646 179.56152904676833 +314 2.7401669256310974 46.57047735161255 179.89034886343723 +315 2.748893571891069 45.00000000000002 180.00000000000003 +316 2.7576202181510405 43.42952264838749 179.8903488634373 +317 2.766346864411012 41.860958681514404 179.56152904676838 +318 2.7750735106709836 40.29621915295568 179.01394116628921 +319 2.7838001569309556 38.73721045679706 178.24825237348261 +320 2.792526803190927 37.18583200498818 177.26539554219747 +321 2.801253449450899 35.643973913200824 176.06656813208494 +322 2.8099800957108707 34.11351469801493 174.65323072967934 +323 2.8187067419708423 32.59631898823504 173.0271052688973 +324 2.827433388230814 31.09423525312738 171.19017293312766 +325 2.8361600344907854 29.60909355034492 169.14467174146358 +326 2.844886680750757 28.14270329628401 166.89309382202177 +327 2.853613327010729 26.696851061588994 164.43818237566816 +328 2.8623399732707004 25.273298394491498 161.78292833385004 +329 2.871066619530672 23.873779674634946 158.93056671460693 +330 2.8797932657906435 22.50000000000005 155.88457268119896 +331 2.888519912050615 21.15363310950582 152.64865730815686 +332 2.897246558310587 19.836319343816406 149.22676305990757 +333 2.9059732045705586 18.549663646838713 145.62305898749065 +334 2.91469985083053 17.295233610345413 141.84193564921014 +335 2.923426497090502 16.074557564105724 137.88799976141604 +336 2.9321531433504737 14.889122713851378 133.76606858593104 +337 2.9408797896104453 13.740373329345143 129.48116406095718 +338 2.949606435870417 12.629708984760711 125.03850668261964 +339 2.9583330821303884 11.558482853517294 120.4435091445946 +340 2.96705972839036 10.528000059646029 115.70176974357733 +341 2.975786374650332 9.539516087697514 110.81906555861842 +342 2.9845130209103035 8.594235253127394 105.8013454126452 +343 2.993239667170275 7.693309235023142 100.6547226247346 +344 3.001966313430247 6.837835672960817 95.38546756197688 +345 3.0106929596902186 6.028856829700268 90.0 +346 3.01941960595019 5.2673583213483255 84.50488130146043 +347 3.0281462522101616 4.5542679165374835 78.90680642203407 +348 3.036872898470133 3.890454406082986 73.21259575364422 +349 3.045599544730105 3.276726544494551 67.4291868148641 +350 3.0543261909900767 2.713832064634096 61.56362579862038 +351 3.0630528372500483 2.202456766718096 55.62305898749061 +352 3.07177948351002 1.7432236827756697 49.614724047060086 +353 3.0805061297699914 1.3366923175801788 43.54594120794044 +354 3.089232776029963 0.983357966978784 37.42410434719691 +355 3.097959422289935 0.6836511144506341 31.256671980047546 +356 3.1066860685499065 0.4379369066293337 25.051158172811903 +357 3.1154127148098785 0.24651470842769696 18.81512338817742 +358 3.12413936106985 0.10961773830790611 12.55616527394248 +359 3.1328660073298216 0.02741278414067072 6.281909406450137 +360 3.141592653589793 0.0 1.5987211554602254e-13 +361 3.1503192998497647 0.02741278414067072 -6.281909406450057 +362 3.159045946109736 0.10961773830790611 -12.55616527394232 +363 3.1677725923697078 0.24651470842769696 -18.815123388177344 +364 3.1764992386296798 0.4379369066293287 -25.051158172811743 +365 3.1852258848896513 0.6836511144506291 -31.256671980047386 +366 3.193952531149623 0.983357966978764 -37.42410434719644 +367 3.2026791774095944 1.3366923175801537 -43.54594120793988 +368 3.211405823669566 1.7432236827755998 -49.61472404705958 +369 3.2201324699295375 2.202456766718046 -55.62305898749016 +370 3.2288591161895095 2.713832064634091 -61.563625798620215 +371 3.237585762449481 3.276726544494546 -67.42918681486394 +372 3.246312408709453 3.890454406082966 -73.21259575364407 +373 3.255039054969425 4.554267916537493 -78.90680642203421 +374 3.2637657012293966 5.2673583213483255 -84.5048813014605 +375 3.272492347489368 6.028856829700283 -90.00000000000016 +376 3.2812189937493397 6.837835672960862 -95.3854675619769 +377 3.2899456400093112 7.693309235023127 -100.65472262473446 +378 3.2986722862692828 8.594235253127355 -105.80134541264509 +379 3.3073989325292543 9.539516087697505 -110.81906555861835 +380 3.3161255787892263 10.52800005964601 -115.70176974357719 +381 3.324852225049198 11.558482853517274 -120.44350914459449 +382 3.3335788713091694 12.629708984760672 -125.0385066826195 +383 3.342305517569141 13.740373329345093 -129.48116406095713 +384 3.3510321638291125 14.889122713851329 -133.7660685859309 +385 3.359758810089084 16.074557564105664 -137.88799976141587 +386 3.368485456349056 17.295233610345388 -141.84193564920992 +387 3.3772121026090276 18.5496636468387 -145.62305898749045 +388 3.385938748868999 19.83631934381636 -149.22676305990737 +389 3.3946653951289707 21.15363310950572 -152.64865730815654 +390 3.4033920413889422 22.49999999999994 -155.88457268119873 +391 3.412118687648914 23.873779674634825 -158.93056671460673 +392 3.4208453339088853 25.273298394491427 -161.78292833384987 +393 3.4295719801688573 26.696851061588944 -164.43818237566813 +394 3.4382986264288293 28.142703296283972 -166.89309382202177 +395 3.447025272688801 29.60909355034489 -169.14467174146347 +396 3.455751918948773 31.094235253127415 -171.19017293312766 +397 3.4644785652087444 32.59631898823507 -173.02710526889751 +398 3.473205211468716 34.11351469801496 -174.65323072967934 +399 3.4819318577286875 35.64397391320084 -176.06656813208502 +400 3.490658503988659 37.185832004988114 -177.26539554219747 +401 3.4993851502486306 38.73721045679703 -178.24825237348256 +402 3.5081117965086026 40.29621915295563 -179.01394116628924 +403 3.516838442768574 41.86095868151437 -179.56152904676833 +404 3.5255650890285457 43.42952264838744 -179.89034886343723 +405 3.5342917352885173 44.99999999999997 -180.00000000000003 +406 3.543018381548489 46.570477351612524 -179.89034886343723 +407 3.5517450278084604 48.139041318485596 -179.5615290467683 +408 3.560471674068432 49.70378084704433 -179.01394116628924 +409 3.569198320328404 51.262789543202956 -178.24825237348256 +410 3.5779249665883754 52.814167995011836 -177.2653955421974 +411 3.586651612848347 54.356026086799105 -176.06656813208502 +412 3.5953782591083185 55.88648530198498 -174.65323072967934 +413 3.60410490536829 57.40368101176488 -173.02710526889746 +414 3.6128315516282616 58.90576474687254 -171.19017293312768 +415 3.6215581978882336 60.39090644965505 -169.14467174146355 +416 3.630284844148205 61.857296703715996 -166.89309382202174 +417 3.639011490408177 63.303148938411 -164.43818237566816 +418 3.647738136668149 64.72670160550854 -161.78292833384995 +419 3.6564647829281207 66.12622032536513 -158.93056671460678 +420 3.6651914291880923 67.50000000000001 -155.8845726811989 +421 3.673918075448064 68.84636689049422 -152.6486573081567 +422 3.6826447217080354 70.1636806561836 -149.22676305990754 +423 3.691371367968007 71.45033635316125 -145.6230589874906 +424 3.7000980142279785 72.7047663896546 -141.84193564920994 +425 3.7088246604879505 73.92544243589428 -137.88799976141595 +426 3.717551306747922 75.11087728614862 -133.76606858593098 +427 3.7262779530078936 76.25962667065488 -129.48116406095718 +428 3.735004599267865 77.37029101523927 -125.03850668261958 +429 3.7437312455278366 78.44151714648271 -120.44350914459456 +430 3.752457891787808 79.47199994035397 -115.70176974357719 +431 3.76118453804778 80.4604839123025 -110.81906555861842 +432 3.7699111843077517 81.40576474687262 -105.8013454126452 +433 3.7786378305677233 82.30669076497685 -100.65472262473452 +434 3.787364476827695 83.16216432703914 -95.38546756197704 +435 3.7960911230876664 83.97114317029968 -90.0000000000002 +436 3.804817769347638 84.73264167865166 -84.50488130146057 +437 3.8135444156076095 85.44573208346247 -78.90680642203438 +438 3.8222710618675815 86.109545593917 -73.21259575364421 +439 3.8309977081275535 86.72327345550543 -67.42918681486408 +440 3.839724354387525 87.28616793536585 -61.563625798620386 +441 3.848451000647497 87.79754323328193 -55.62305898749028 +442 3.8571776469074686 88.25677631722435 -49.61472404705969 +443 3.86590429316744 88.66330768241984 -43.545941207940146 +444 3.8746309394274117 89.01664203302126 -37.42410434719666 +445 3.883357585687383 89.31634888554936 -31.256671980047603 +446 3.8920842319473548 89.56206309337064 -25.051158172811835 +447 3.9008108782073267 89.75348529157229 -18.815123388177536 +448 3.9095375244672983 89.8903822616921 -12.556165273942474 +449 3.91826417072727 89.97258721585929 -6.281909406450126 +450 3.9269908169872414 90.0 -4.9960036108132044e-14 +451 3.935717463247213 89.97258721585929 6.281909406449996 +452 3.9444441095071845 89.8903822616921 12.556165273942264 +453 3.953170755767156 89.7534852915723 18.815123388177277 +454 3.961897402027128 89.56206309337068 25.051158172811732 +455 3.9706240482870996 89.31634888554936 31.256671980047305 +456 3.979350694547071 89.01664203302126 37.42410434719644 +457 3.9880773408070427 88.66330768241984 43.545941207939904 +458 3.9968039870670142 88.25677631722436 49.61472404705954 +459 4.005530633326986 87.79754323328193 55.62305898749019 +460 4.014257279586958 87.2861679353659 61.56362579862025 +461 4.022983925846929 86.72327345550546 67.42918681486357 +462 4.031710572106902 86.10954559391699 73.21259575364432 +463 4.040437218366873 85.44573208346253 78.90680642203384 +464 4.049163864626845 84.73264167865169 84.50488130146046 +465 4.057890510886816 83.97114317029977 89.99999999999977 +466 4.066617157146788 83.16216432703916 95.38546756197688 +467 4.07534380340676 82.30669076497685 100.6547226247346 +468 4.084070449666731 81.40576474687265 105.80134541264509 +469 4.092797095926703 80.46048391230246 110.81906555861863 +470 4.101523742186674 79.47199994035402 115.7017697435769 +471 4.110250388446646 78.44151714648272 120.44350914459453 +472 4.118977034706617 77.37029101523936 125.03850668261924 +473 4.127703680966589 76.25962667065491 129.48116406095713 +474 4.136430327226561 75.11087728614861 133.76606858593098 +475 4.145156973486532 73.92544243589433 137.8879997614158 +476 4.153883619746504 72.70476638965462 141.84193564920997 +477 4.162610266006475 71.45033635316139 145.6230589874902 +478 4.171336912266447 70.16368065618366 149.22676305990734 +479 4.1800635585264185 68.84636689049435 152.64865730815634 +480 4.1887902047863905 67.50000000000006 155.88457268119873 +481 4.1975168510463625 66.1262203253651 158.93056671460678 +482 4.206243497306334 64.72670160550861 161.7829283338499 +483 4.214970143566306 63.30314893841105 164.4381823756681 +484 4.223696789826278 61.85729670371604 166.89309382202177 +485 4.23242343608625 60.39090644965502 169.14467174146355 +486 4.241150082346221 58.905764746872656 171.19017293312763 +487 4.249876728606193 57.40368101176494 173.02710526889743 +488 4.258603374866164 55.886485301985104 174.65323072967925 +489 4.267330021126136 54.35602608679916 176.0665681320849 +490 4.276056667386108 52.8141679950118 177.26539554219744 +491 4.284783313646079 51.26278954320299 178.24825237348261 +492 4.293509959906051 49.7037808470444 179.0139411662892 +493 4.302236606166022 48.13904131848572 179.56152904676833 +494 4.310963252425994 46.570477351612574 179.89034886343723 +495 4.319689898685965 45.0000000000001 179.99999999999997 +496 4.328416544945937 43.4295226483875 179.89034886343734 +497 4.337143191205909 41.86095868151434 179.56152904676836 +498 4.34586983746588 40.29621915295566 179.01394116628924 +499 4.354596483725852 38.73721045679708 178.24825237348264 +500 4.363323129985823 37.18583200498824 177.26539554219758 +501 4.372049776245795 35.64397391320091 176.06656813208505 +502 4.380776422505767 34.11351469801496 174.65323072967934 +503 4.389503068765738 32.596318988235126 173.02710526889743 +504 4.39822971502571 31.094235253127383 171.19017293312774 +505 4.4069563612856815 29.60909355034503 169.14467174146358 +506 4.4156830075456535 28.142703296284033 166.89309382202183 +507 4.4244096538056255 26.696851061588987 164.43818237566813 +508 4.4331363000655974 25.273298394491455 161.78292833384998 +509 4.4418629463255686 23.873779674634946 158.93056671460693 +510 4.4505895925855405 22.49999999999998 155.8845726811989 +511 4.4593162388455125 21.153633109505705 152.64865730815654 +512 4.468042885105484 19.836319343816406 149.22676305990757 +513 4.476769531365456 18.54966364683867 145.62305898749034 +514 4.485496177625427 17.29523361034543 141.8419356492101 +515 4.494222823885399 16.074557564105724 137.88799976141604 +516 4.50294947014537 14.88912271385146 133.76606858593118 +517 4.511676116405342 13.740373329345143 129.48116406095718 +518 4.520402762665314 12.629708984760681 125.0385066826194 +519 4.529129408925285 11.558482853517294 120.4435091445946 +520 4.537856055185257 10.528000059645974 115.70176974357709 +521 4.546582701445228 9.53951608769756 110.81906555861873 +522 4.5553093477052 8.594235253127385 105.80134541264532 +523 4.564035993965171 7.693309235023177 100.65472262473489 +524 4.572762640225143 6.837835672960867 95.38546756197717 +525 4.581489286485115 6.028856829700248 90.00000000000001 +526 4.590215932745086 5.267358321348356 84.50488130146071 +527 4.598942579005058 4.5542679165374835 78.90680642203414 +528 4.607669225265029 3.890454406083026 73.2125957536445 +529 4.616395871525002 3.2767265444945357 67.42918681486387 +530 4.625122517784973 2.7138320646341207 61.56362579862043 +531 4.633849164044945 2.2024567667180612 55.62305898749039 +532 4.642575810304916 1.7432236827756697 49.61472404706008 +533 4.651302456564888 1.3366923175801637 43.54594120794012 +534 4.66002910282486 0.983357966978739 37.42410434719637 +535 4.6687557490848315 0.6836511144506541 31.256671980047525 +536 4.6774823953448035 0.4379369066293487 25.051158172811657 +537 4.686209041604775 0.24651470842770196 18.8151233881779 +538 4.694935687864747 0.10961773830790611 12.55616527394256 +539 4.703662334124718 0.0274127841406957 6.281909406450534 +540 4.71238898038469 0.0 1.5987211554602254e-13 +541 4.721115626644662 0.0274127841406957 -6.2819094064502945 +542 4.729842272904633 0.10961773830790611 -12.55616527394232 +543 4.738568919164605 0.24651470842769696 -18.81512338817758 +544 4.747295565424576 0.4379369066293437 -25.05115817281142 +545 4.756022211684548 0.6836511144506391 -31.25667198004721 +546 4.764748857944519 0.983357966978729 -37.424104347196135 +547 4.773475504204491 1.3366923175801138 -43.54594120793983 +548 4.782202150464463 1.7432236827756498 -49.61472404705977 +549 4.790928796724434 2.202456766718046 -55.62305898749016 +550 4.799655442984406 2.7138320646341105 -61.5636257986202 +551 4.808382089244377 3.276726544494521 -67.42918681486363 +552 4.81710873550435 3.890454406083011 -73.21259575364434 +553 4.825835381764321 4.554267916537463 -78.90680642203391 +554 4.834562028024293 5.2673583213483255 -84.50488130146043 +555 4.843288674284264 6.028856829700228 -89.99999999999987 +556 4.852015320544236 6.837835672960817 -95.38546756197688 +557 4.860741966804208 7.693309235023142 -100.6547226247346 +558 4.869468613064179 8.594235253127355 -105.80134541264509 +559 4.878195259324151 9.539516087697534 -110.81906555861855 +560 4.886921905584122 10.528000059645954 -115.70176974357695 +561 4.895648551844094 11.558482853517274 -120.44350914459449 +562 4.9043751981040655 12.629708984760637 -125.03850668261913 +563 4.9131018443640375 13.740373329345093 -129.48116406095713 +564 4.9218284906240095 14.889122713851384 -133.76606858593104 +565 4.930555136883981 16.074557564105667 -137.88799976141578 +566 4.939281783143953 17.29523361034537 -141.84193564920983 +567 4.948008429403924 18.549663646838617 -145.6230589874903 +568 4.956735075663896 19.83631934381635 -149.2267630599073 +569 4.965461721923867 21.153633109505655 -152.64865730815634 +570 4.974188368183839 22.49999999999994 -155.88457268119873 +571 4.982915014443811 23.87377967463491 -158.93056671460675 +572 4.991641660703782 25.273298394491402 -161.78292833384975 +573 5.000368306963754 26.696851061588944 -164.43818237566813 +574 5.009094953223726 28.142703296283962 -166.8930938220218 +575 5.017821599483698 29.60909355034495 -169.14467174146358 +576 5.026548245743669 31.094235253127334 -171.1901729331276 +577 5.035274892003641 32.59631898823506 -173.02710526889743 +578 5.044001538263612 34.11351469801487 -174.65323072967925 +579 5.052728184523584 35.643973913200824 -176.06656813208494 +580 5.061454830783556 37.18583200498815 -177.26539554219755 +581 5.070181477043527 38.737210456797015 -178.24825237348261 +582 5.078908123303499 40.29621915295563 -179.01394116628924 +583 5.08763476956347 41.860958681514276 -179.5615290467684 +584 5.096361415823442 43.42952264838744 -179.89034886343723 +585 5.105088062083414 45.00000000000006 -179.99999999999997 +586 5.113814708343385 46.57047735161251 -179.8903488634373 +587 5.122541354603357 48.13904131848563 -179.56152904676836 +588 5.1312680008633285 49.70378084704432 -179.0139411662893 +589 5.1399946471233005 51.26278954320292 -178.24825237348261 +590 5.148721293383272 52.81416799501175 -177.26539554219755 +591 5.1574479396432436 54.356026086799105 -176.06656813208502 +592 5.1661745859032155 55.88648530198504 -174.6532307296794 +593 5.174901232163187 57.40368101176488 -173.02710526889751 +594 5.183627878423159 58.90576474687263 -171.19017293312766 +595 5.19235452468313 60.39090644965496 -169.14467174146367 +596 5.201081170943102 61.85729670371596 -166.89309382202183 +597 5.209807817203074 63.303148938411 -164.43818237566816 +598 5.218534463463046 64.72670160550852 -161.78292833384995 +599 5.227261109723017 66.12622032536501 -158.930566714607 +600 5.235987755982989 67.5 -155.8845726811989 +601 5.244714402242961 68.8463668904943 -152.64865730815657 +602 5.253441048502932 70.1636806561836 -149.22676305990746 +603 5.262167694762904 71.45033635316135 -145.62305898749048 +604 5.270894341022875 72.70476638965457 -141.84193564921003 +605 5.279620987282847 73.9254424358943 -137.887999761416 +606 5.288347633542818 75.11087728614855 -133.7660685859312 +607 5.29707427980279 76.25962667065488 -129.48116406095718 +608 5.305800926062762 77.37029101523932 -125.03850668261944 +609 5.314527572322733 78.4415171464827 -120.44350914459464 +610 5.323254218582705 79.471999940354 -115.70176974357703 +611 5.331980864842676 80.46048391230242 -110.81906555861873 +612 5.340707511102648 81.4057647468726 -105.80134541264532 +613 5.349434157362619 82.30669076497678 -100.65472262473489 +614 5.358160803622591 83.16216432703912 -95.38546756197704 +615 5.366887449882563 83.97114317029971 -90.00000000000004 +616 5.3756140961425345 84.73264167865163 -84.5048813014608 +617 5.3843407424025065 85.44573208346249 -78.90680642203407 +618 5.393067388662478 86.10954559391698 -73.21259575364451 +619 5.4017940349224505 86.72327345550548 -67.42918681486384 +620 5.410520681182422 87.28616793536587 -61.56362579862045 +621 5.419247327442394 87.79754323328193 -55.62305898749038 +622 5.427973973702365 88.25677631722434 -49.61472404706012 +623 5.436700619962337 88.66330768241984 -43.54594120794002 +624 5.445427266222309 89.01664203302126 -37.42410434719644 +625 5.45415391248228 89.31634888554936 -31.256671980047603 +626 5.462880558742252 89.56206309337067 -25.051158172811675 +627 5.471607205002223 89.75348529157228 -18.815123388177824 +628 5.480333851262195 89.8903822616921 -12.556165273942614 +629 5.489060497522166 89.97258721585928 -6.281909406450685 +630 5.497787143782138 90.0 -4.9960036108132044e-14 +631 5.50651379004211 89.97258721585932 6.281909406450335 +632 5.515240436302081 89.8903822616921 12.556165273942264 +633 5.523967082562053 89.75348529157229 18.815123388177536 +634 5.532693728822024 89.56206309337068 25.051158172811373 +635 5.541420375081996 89.31634888554937 31.256671980047276 +636 5.550147021341967 89.01664203302127 37.42410434719605 +637 5.558873667601939 88.66330768241987 43.54594120793987 +638 5.567600313861911 88.25677631722435 49.61472404705969 +639 5.576326960121882 87.79754323328196 55.62305898749017 +640 5.585053606381854 87.2861679353659 61.56362579862025 +641 5.593780252641825 86.7232734555055 67.42918681486367 +642 5.602506898901798 86.10954559391699 73.21259575364432 +643 5.611233545161769 85.4457320834625 78.90680642203387 +644 5.619960191421741 84.7326416786517 84.5048813014604 +645 5.6286868376817125 83.97114317029977 89.99999999999977 +646 5.6374134839416845 83.16216432703916 95.38546756197684 +647 5.6461401302016565 82.30669076497684 100.65472262473475 +648 5.654866776461628 81.40576474687265 105.80134541264509 +649 5.6635934227216 80.46048391230246 110.81906555861855 +650 5.672320068981571 79.47199994035407 115.7017697435767 +651 5.681046715241543 78.44151714648275 120.44350914459432 +652 5.689773361501514 77.37029101523936 125.03850668261924 +653 5.698500007761486 76.25962667065491 129.48116406095713 +654 5.707226654021458 75.11087728614861 133.76606858593098 +655 5.715953300281429 73.92544243589433 137.8879997614158 +656 5.724679946541401 72.70476638965464 141.84193564920983 +657 5.733406592801372 71.45033635316142 145.6230589874902 +658 5.742133239061344 70.16368065618366 149.22676305990734 +659 5.750859885321315 68.84636689049437 152.6486573081564 +660 5.759586531581287 67.50000000000009 155.88457268119876 +661 5.768313177841259 66.12622032536511 158.93056671460684 +662 5.77703982410123 64.72670160550861 161.7829283338498 +663 5.785766470361202 63.303148938411084 164.43818237566802 +664 5.794493116621174 61.85729670371604 166.89309382202177 +665 5.803219762881146 60.39090644965505 169.14467174146355 +666 5.811946409141117 58.905764746872656 171.1901729331276 +667 5.820673055401089 57.40368101176496 173.02710526889746 +668 5.82939970166106 55.88648530198513 174.65323072967922 +669 5.838126347921032 54.35602608679919 176.06656813208497 +670 5.846852994181004 52.814167995011836 177.2653955421974 +671 5.8555796404409755 51.262789543203006 178.24825237348267 +672 5.8643062867009474 49.7037808470444 179.0139411662892 +673 5.8730329329609186 48.13904131848573 179.56152904676833 +674 5.8817595792208905 46.57047735161256 179.8903488634373 +675 5.890486225480862 45.00000000000012 179.99999999999991 +676 5.899212871740834 43.42952264838752 179.89034886343725 +677 5.907939518000806 41.86095868151437 179.56152904676833 +678 5.916666164260777 40.29621915295568 179.01394116628921 +679 5.925392810520749 38.7372104567971 178.24825237348273 +680 5.93411945678072 37.18583200498828 177.26539554219755 +681 5.942846103040692 35.64397391320092 176.066568132085 +682 5.951572749300664 34.11351469801494 174.65323072967948 +683 5.960299395560635 32.59631898823515 173.02710526889757 +684 5.969026041820607 31.094235253127408 171.19017293312766 +685 5.977752688080578 29.60909355034503 169.1446717414638 +686 5.98647933434055 28.14270329628406 166.89309382202183 +687 5.995205980600522 26.696851061588994 164.43818237566816 +688 6.003932626860494 25.273298394491466 161.78292833384992 +689 6.012659273120465 23.873779674634957 158.93056671460695 +690 6.021385919380437 22.50000000000001 155.88457268119893 +691 6.030112565640409 21.15363310950571 152.64865730815654 +692 6.03883921190038 19.836319343816424 149.2267630599075 +693 6.047565858160352 18.54966364683867 145.6230589874905 +694 6.056292504420323 17.295233610345413 141.84193564921014 +695 6.065019150680295 16.074557564105724 137.88799976141604 +696 6.073745796940266 14.889122713851425 133.7660685859313 +697 6.082472443200238 13.740373329345124 129.48116406095735 +698 6.09119908946021 12.629708984760661 125.03850668261943 +699 6.0999257357201815 11.558482853517308 120.44350914459469 +700 6.1086523819801535 10.528000059645985 115.70176974357715 +701 6.117379028240125 9.539516087697574 110.81906555861885 +702 6.126105674500097 8.594235253127385 105.80134541264536 +703 6.134832320760068 7.693309235023177 100.65472262473489 +704 6.14355896702004 6.837835672960847 95.38546756197718 +705 6.152285613280012 6.028856829700253 90.00000000000009 +706 6.161012259539983 5.267358321348316 84.50488130146077 +707 6.169738905799955 4.5542679165374835 78.90680642203414 +708 6.178465552059926 3.8904544060830357 73.21259575364456 +709 6.187192198319899 3.276726544494546 67.42918681486394 +710 6.19591884457987 2.7138320646341105 61.56362579862053 +711 6.204645490839842 2.2024567667180612 55.62305898749039 +712 6.213372137099813 1.7432236827756697 49.614724047060086 +713 6.222098783359785 1.3366923175801637 43.545941207940196 +714 6.230825429619757 0.983357966978764 37.42410434719644 +715 6.239552075879728 0.6836511144506341 31.25667198004762 +716 6.2482787221397 0.4379369066293687 25.051158172811643 +717 6.257005368399671 0.24651470842772694 18.8151233881779 +718 6.265732014659643 0.10961773830790611 12.55616527394256 +719 6.274458660919614 0.0274127841406957 6.281909406450615 + +HARMONIC_3 +N 720 RADIANS + +0 0.0 0.0 -0.0 +1 0.008726646259971648 0.008529071242088904 -1.9546695209757408 +2 0.017453292519943295 0.03411368693063732 -3.9087436306800853 +3 0.02617993877991494 0.07674605374387777 -5.861627099209696 +4 0.03490658503988659 0.13641318544986358 -7.81272505934202 +5 0.04363323129985824 0.21309690686224325 -9.761443187737738 +6 0.05235987755982988 0.30677385937668955 -11.70718788597717 +7 0.061086523819801536 0.41741550808596894 -13.649366461376497 +8 0.06981317007977318 0.544988150472066 -15.587387307527308 +9 0.07853981633974483 0.6894529266722724 -17.520660084505877 +10 0.08726646259971647 0.8507658313163322 -19.448595898696194 +11 0.09599310885968812 1.0288777269308236 -21.37060748217304 +12 0.10471975511965977 1.2237343589068876 -23.28610937158906 +13 0.11344640137963141 1.4352763720268138 -25.194518086512865 +14 0.12217304763960307 1.663439328544185 -27.095252307162777 +15 0.1308996938995747 1.9081537278121683 -28.987733051482323 +16 0.13962634015954636 2.1693450274541357 -30.8713838515039 +17 0.148352986419518 2.4469336660700094 -32.745630928946525 +18 0.15707963267948966 2.7408350874714023 -34.609903369994136 +19 0.16580627893946132 3.050959766438263 -36.463633299201526 +20 0.17453292519943295 3.377213235989122 -38.30625605247489 +21 0.1832595714594046 3.719496116156696 -40.137210349073634 +22 0.19198621771937624 4.077704144259892 -41.95593846258216 +23 0.20071286397934787 4.451728206663333 -43.76188639079868 +24 0.20943951023931953 4.841454372014345 -45.554504024489646 +25 0.2181661564992912 5.246763925947597 -47.33324531495834 +26 0.22689280275926282 5.6675334072466335 -49.09756844037665 +27 0.23561944901923448 6.103634645451379 -50.846935970829236 +28 0.24434609527920614 6.554934799900107 -52.580815032019785 +29 0.2530727415391778 7.021296400193826 -54.29867746758978 +30 0.2617993877991494 7.502577388071445 -56.0 +31 0.27052603405912107 7.9986311606817155 -57.68426438992608 +32 0.2792526803190927 8.50930661524014 -59.35095759411894 +33 0.28797932657906433 9.034448195056253 -60.999571921683035 +34 0.296705972839036 9.573895936917662 -62.62960518872365 +35 0.30543261909900765 10.12748551981646 -64.2405608713172 +36 0.3141592653589793 10.695048315002936 -65.831948256757 +37 0.32288591161895097 11.276411437351614 -67.40328259302939 +38 0.33161255787892263 11.871397798023555 -68.95408523647374 +39 0.3403392041388943 12.479826158409617 -70.48388379758178 +40 0.3490658503988659 13.101511185337225 -71.99221228489239 +41 0.35779249665883756 13.736263507524773 -73.47861124693682 +42 0.3665191429188092 14.383889773265935 -74.94262791219212 +43 0.3752457891787809 15.04419270932646 -76.38381632699983 +44 0.3839724354387525 15.716971181035527 -77.80173749140768 +45 0.39269908169872414 16.402020253553342 -79.19595949289334 +46 0.40142572795869574 17.09913125429613 -80.5660576379289 +47 0.41015237421866746 17.80809183650009 -81.91161458134708 +48 0.41887902047863906 18.528686043903953 -83.23222045346814 +49 0.42760566673861067 19.2606943765316 -84.52747298495044 +50 0.4363323129985824 20.003893857553802 -85.79697762932555 +51 0.445058959258554 20.75805810120908 -87.04034768318073 +52 0.45378560551852565 21.522957381763128 -88.25720440395287 +53 0.4625122517784973 22.29835870348529 -89.4471771252968 +54 0.47123889803846897 23.0840258716215 -90.60990336999411 +55 0.4799655442984406 23.87971956434142 -91.7450289603671 +56 0.4886921905584123 24.685197405638167 -92.85220812616467 +57 0.4974188368183839 25.50021403915848 -93.93110360988749 +58 0.5061454830783556 26.32452120294053 -94.9813867695197 +59 0.5148721293383272 27.157867805036954 -96.00273767863655 +60 0.5235987755982988 27.999999999999986 -96.99484522385711 +61 0.5323254218582705 28.85066126620511 -97.9574071996123 +62 0.5410520681182421 29.70959248399013 -98.89013040019982 +63 0.5497787143782138 30.576532014585375 -99.79273070909721 +64 0.5585053606381855 31.451215779811665 -100.66493318550671 +65 0.5672320068981571 32.33337734252084 -101.50647214810483 +66 0.5759586531581287 33.22274798775518 -102.31709125597129 +67 0.5846852994181004 34.119056804600675 -103.09654358667333 +68 0.593411945678072 35.022030768708944 -103.84459171148019 +69 0.6021385919380438 35.9313948254632 -104.5610077676866 +70 0.6108652381980153 36.84687197376254 -105.24557352802174 +71 0.619591884457987 37.76818335039923 -105.89808046712349 +72 0.6283185307179586 38.69504831500294 -106.51832982505721 +73 0.6370451769779303 39.627184535526744 -107.10613266785997 +74 0.6457718232379019 40.564308074248046 -107.66130994509169 +75 0.6544984694978736 41.50613347425884 -108.18369254437565 +76 0.6632251157578453 42.45237384641862 -108.6731213429116 +77 0.6719517620178168 43.40274095674357 -109.12944725594632 +78 0.6806784082777886 44.35694531420548 -109.55253128218624 +79 0.6894050545377601 45.31469625891349 -109.94224454613835 +80 0.6981317007977318 46.2757020506519 -110.29846833736731 +81 0.7068583470577035 47.23966995774707 -110.62109414665542 +82 0.7155849933176751 48.206306346236325 -110.9100236990559 +83 0.7243116395776468 49.175316769311735 -111.16516898382807 +84 0.7330382858376184 50.146406057011404 -111.38645228124662 +85 0.74176493209759 51.11927840613113 -111.57380618627549 +86 0.7504915783575618 52.093637470328986 -111.72717362910032 +87 0.7592182246175333 53.06918645039515 -111.84650789251228 +88 0.767944870877505 54.04562818465995 -111.93177262613871 +89 0.7766715171374766 55.02266523951213 -111.9829418575158 +90 0.7853981633974483 56.0 -112.00000000000003 +91 0.7941248096574199 56.97733476048787 -111.9829418575158 +92 0.8028514559173915 57.95437181534005 -111.93177262613871 +93 0.8115781021773633 58.93081354960485 -111.84650789251228 +94 0.8203047484373349 59.906362529671014 -111.72717362910032 +95 0.8290313946973066 60.88072159386884 -111.57380618627552 +96 0.8377580409572781 61.853593942988574 -111.38645228124662 +97 0.8464846872172498 62.82468323068823 -111.16516898382807 +98 0.8552113334772213 63.79369365376366 -110.91002369905586 +99 0.8639379797371932 64.76033004225296 -110.62109414665544 +100 0.8726646259971648 65.72429794934808 -110.29846833736732 +101 0.8813912722571364 66.68530374108651 -109.94224454613835 +102 0.890117918517108 67.64305468579451 -109.55253128218624 +103 0.8988445647770796 68.59725904325643 -109.12944725594639 +104 0.9075712110370513 69.54762615358139 -108.6731213429116 +105 0.9162978572970231 70.49386652574117 -108.18369254437563 +106 0.9250245035569946 71.43569192575194 -107.66130994509176 +107 0.9337511498169663 72.37281546447325 -107.10613266785994 +108 0.9424777960769379 73.30495168499706 -106.51832982505721 +109 0.9512044423369095 74.23181664960076 -105.89808046712348 +110 0.9599310885968813 75.15312802623745 -105.24557352802174 +111 0.9686577348568529 76.06860517453683 -104.56100776768659 +112 0.9773843811168246 76.97796923129108 -103.84459171148019 +113 0.9861110273767961 77.88094319539934 -103.0965435866733 +114 0.9948376736367678 78.77725201224482 -102.31709125597132 +115 1.0035643198967394 79.66662265747917 -101.50647214810483 +116 1.0122909661567112 80.54878422018834 -100.66493318550671 +117 1.0210176124166828 81.42346798541462 -99.79273070909721 +118 1.0297442586766543 82.29040751600986 -98.89013040019982 +119 1.038470904936626 83.14933873379486 -97.95740719961235 +120 1.0471975511965976 84.0 -96.99484522385713 +121 1.0559241974565694 84.84213219496303 -96.00273767863656 +122 1.064650843716541 85.67547879705945 -94.98138676951973 +123 1.0733774899765127 86.4997859608415 -93.9311036098875 +124 1.0821041362364843 87.31480259436184 -92.85220812616467 +125 1.0908307824964558 88.12028043565857 -91.74502896036711 +126 1.0995574287564276 88.91597412837851 -90.60990336999411 +127 1.1082840750163994 89.70164129651471 -89.44717712529679 +128 1.117010721276371 90.47704261823687 -88.25720440395287 +129 1.1257373675363425 91.24194189879088 -87.04034768318076 +130 1.1344640137963142 91.99610614244621 -85.79697762932555 +131 1.1431906600562858 92.7393056234684 -84.52747298495045 +132 1.1519173063162573 93.47131395609604 -83.23222045346817 +133 1.160643952576229 94.19190816349992 -81.9116145813471 +134 1.1693705988362009 94.90086874570387 -80.5660576379289 +135 1.1780972450961724 95.59797974644665 -79.19595949289334 +136 1.186823891356144 96.28302881896445 -77.80173749140772 +137 1.1955505376161157 96.95580729067356 -76.38381632699983 +138 1.2042771838760875 97.6161102267341 -74.94262791219208 +139 1.213003830136059 98.26373649247523 -73.47861124693682 +140 1.2217304763960306 98.89848881466276 -71.99221228489243 +141 1.2304571226560024 99.52017384159038 -70.48388379758178 +142 1.239183768915974 100.12860220197642 -68.95408523647373 +143 1.2479104151759455 100.7235885626484 -67.40328259302943 +144 1.2566370614359172 101.30495168499706 -65.831948256757 +145 1.265363707695889 101.87251448018355 -64.24056087131714 +146 1.2740903539558606 102.42610406308233 -62.62960518872365 +147 1.2828170002158321 102.96555180494374 -60.999571921683085 +148 1.2915436464758039 103.49069338475987 -59.35095759411894 +149 1.3002702927357754 104.00136883931827 -57.684264389926064 +150 1.3089969389957472 104.49742261192857 -55.99999999999999 +151 1.3177235852557188 104.97870359980617 -54.29867746758976 +152 1.3264502315156905 105.44506520009992 -52.58081503201974 +153 1.335176877775662 105.89636535454859 -50.84693597082927 +154 1.3439035240356336 106.33246659275335 -49.09756844037668 +155 1.3526301702956054 106.75323607405241 -47.33324531495834 +156 1.3613568165555772 107.15854562798566 -45.55450402448959 +157 1.3700834628155487 107.54827179333667 -43.76188639079868 +158 1.3788101090755203 107.92229585574009 -41.955938462582154 +159 1.3875367553354918 108.2805038838433 -40.13721034907368 +160 1.3962634015954636 108.62278676401087 -38.306256052474936 +161 1.4049900478554354 108.94904023356175 -36.46363329920153 +162 1.413716694115407 109.2591649125286 -34.609903369994136 +163 1.4224433403753785 109.55306633392999 -32.745630928946575 +164 1.4311699866353502 109.83065497254586 -30.8713838515039 +165 1.4398966328953218 110.09184627218784 -28.987733051482373 +166 1.4486232791552935 110.33656067145583 -27.095252307162777 +167 1.457349925415265 110.56472362797318 -25.194518086512915 +168 1.4660765716752369 110.77626564109312 -23.28610937158906 +169 1.4748032179352084 110.97112227306917 -21.37060748217304 +170 1.48352986419518 111.14923416868365 -19.44859589869624 +171 1.4922565104551517 111.31054707332773 -17.520660084505877 +172 1.5009831567151235 111.45501184952792 -15.587387307527305 +173 1.509709802975095 111.58258449191403 -13.649366461376546 +174 1.5184364492350666 111.6932261406233 -11.707187885977218 +175 1.5271630954950384 111.78690309313774 -9.761443187737736 +176 1.53588974175501 111.86358681455015 -7.812725059342069 +177 1.5446163880149815 111.92325394625612 -5.861627099209747 +178 1.5533430342749532 111.96588631306938 -3.908743630680135 +179 1.562069680534925 111.9914709287579 -1.9546695209757405 +180 1.5707963267948966 112.0 -0.0 +181 1.579522973054868 111.9914709287579 1.9546695209757157 +182 1.5882496193148399 111.96588631306938 3.90874363068011 +183 1.5969762655748114 111.92325394625612 5.861627099209672 +184 1.605702911834783 111.86358681455015 7.81272505934197 +185 1.6144295580947547 111.78690309313777 9.761443187737692 +186 1.6231562043547265 111.6932261406233 11.707187885977193 +187 1.6318828506146983 111.58258449191403 13.649366461376546 +188 1.6406094968746698 111.45501184952792 15.58738730752733 +189 1.6493361431346414 111.31054707332773 17.520660084505828 +190 1.6580627893946132 111.14923416868365 19.448595898696215 +191 1.6667894356545847 110.9711222730692 21.370607482173018 +192 1.6755160819145563 110.77626564109312 23.286109371589003 +193 1.684242728174528 110.56472362797318 25.194518086512865 +194 1.6929693744344996 110.33656067145583 27.09525230716275 +195 1.7016960206944711 110.09184627218784 28.987733051482273 +196 1.7104226669544427 109.83065497254587 30.871383851503857 +197 1.7191493132144147 109.55306633392999 32.745630928946525 +198 1.7278759594743864 109.2591649125286 34.60990336999416 +199 1.736602605734358 108.94904023356175 36.46363329920155 +200 1.7453292519943295 108.62278676401087 38.30625605247489 +201 1.7540558982543013 108.2805038838433 40.13721034907363 +202 1.7627825445142729 107.92229585574009 41.955938462582154 +203 1.7715091907742444 107.54827179333667 43.76188639079863 +204 1.780235837034216 107.15854562798566 45.55450402448959 +205 1.7889624832941877 106.75323607405241 47.33324531495834 +206 1.7976891295541593 106.33246659275336 49.09756844037665 +207 1.8064157758141308 105.89636535454862 50.84693597082918 +208 1.8151424220741026 105.44506520009992 52.58081503201974 +209 1.8238690683340746 104.97870359980615 54.29867746758978 +210 1.8325957145940461 104.49742261192857 56.00000000000003 +211 1.8413223608540177 104.00136883931827 57.684264389926064 +212 1.8500490071139892 103.49069338475987 59.35095759411894 +213 1.858775653373961 102.96555180494374 60.999571921683035 +214 1.8675022996339325 102.42610406308235 62.62960518872363 +215 1.876228945893904 101.87251448018355 64.24056087131714 +216 1.8849555921538759 101.30495168499706 65.83194825675697 +217 1.8936822384138474 100.7235885626484 67.40328259302937 +218 1.902408884673819 100.12860220197645 68.9540852364737 +219 1.9111355309337907 99.52017384159038 70.48388379758178 +220 1.9198621771937625 98.89848881466277 71.99221228489239 +221 1.9285888234537343 98.26373649247523 73.47861124693682 +222 1.9373154697137058 97.61611022673408 74.94262791219214 +223 1.9460421159736774 96.95580729067356 76.38381632699982 +224 1.9547687622336491 96.28302881896445 77.8017374914077 +225 1.9634954084936207 95.59797974644665 79.19595949289332 +226 1.9722220547535922 94.90086874570387 80.5660576379289 +227 1.980948701013564 94.19190816349992 81.9116145813471 +228 1.9896753472735356 93.47131395609605 83.2322204534681 +229 1.9984019935335071 92.73930562346843 84.52747298495042 +230 2.007128639793479 91.99610614244622 85.79697762932551 +231 2.015855286053451 91.24194189879087 87.04034768318078 +232 2.0245819323134224 90.47704261823685 88.25720440395288 +233 2.033308578573394 89.7016412965147 89.4471771252968 +234 2.0420352248333655 88.91597412837851 90.60990336999411 +235 2.050761871093337 88.1202804356586 91.74502896036704 +236 2.0594885173533086 87.31480259436185 92.85220812616464 +237 2.0682151636132806 86.4997859608415 93.9311036098875 +238 2.076941809873252 85.67547879705947 94.98138676951969 +239 2.0856684561332237 84.84213219496304 96.00273767863655 +240 2.0943951023931953 84.00000000000003 96.99484522385711 +241 2.103121748653167 83.14933873379493 97.95740719961229 +242 2.111848394913139 82.29040751600988 98.8901304001998 +243 2.1205750411731104 81.42346798541462 99.79273070909721 +244 2.129301687433082 80.54878422018835 100.66493318550667 +245 2.138028333693054 79.66662265747917 101.50647214810483 +246 2.1467549799530254 78.77725201224482 102.31709125597129 +247 2.155481626212997 77.88094319539934 103.0965435866733 +248 2.1642082724729685 76.97796923129108 103.84459171148019 +249 2.17293491873294 76.06860517453687 104.56100776768658 +250 2.1816615649929116 75.15312802623748 105.24557352802171 +251 2.1903882112528836 74.23181664960079 105.89808046712349 +252 2.199114857512855 73.30495168499706 106.51832982505718 +253 2.2078415037728267 72.37281546447328 107.10613266785995 +254 2.2165681500327987 71.43569192575195 107.66130994509173 +255 2.2252947962927703 70.49386652574117 108.18369254437563 +256 2.234021442552742 69.5476261535814 108.67312134291161 +257 2.2427480888127134 68.59725904325646 109.12944725594636 +258 2.251474735072685 67.64305468579454 109.55253128218624 +259 2.260201381332657 66.68530374108649 109.94224454613834 +260 2.2689280275926285 65.72429794934808 110.29846833736732 +261 2.2776546738526 64.76033004225295 110.62109414665542 +262 2.2863813201125716 63.7936936537637 110.91002369905586 +263 2.295107966372543 62.82468323068828 111.16516898382807 +264 2.3038346126325147 61.85359394298864 111.38645228124659 +265 2.3125612588924866 60.880721593868856 111.57380618627553 +266 2.321287905152458 59.906362529671036 111.72717362910032 +267 2.33001455141243 58.93081354960485 111.84650789251225 +268 2.3387411976724017 57.95437181534004 111.93177262613872 +269 2.3474678439323733 56.97733476048787 111.9829418575158 +270 2.356194490192345 56.0 112.00000000000003 +271 2.3649211364523164 55.02266523951215 111.98294185751584 +272 2.373647782712288 54.045628184659975 111.93177262613872 +273 2.3823744289722595 53.0691864503952 111.84650789251228 +274 2.3911010752322315 52.093637470328986 111.72717362910032 +275 2.399827721492203 51.119278406131166 111.57380618627549 +276 2.408554367752175 50.14640605701138 111.38645228124659 +277 2.4172810140121466 49.17531676931174 111.16516898382804 +278 2.426007660272118 48.20630634623634 110.91002369905588 +279 2.4347343065320897 47.2396699577471 110.62109414665544 +280 2.443460952792061 46.27570205065193 110.29846833736731 +281 2.4521875990520328 45.31469625891353 109.94224454613838 +282 2.4609142453120048 44.356945314205475 109.55253128218622 +283 2.4696408915719763 43.40274095674358 109.12944725594636 +284 2.478367537831948 42.452373846418624 108.67312134291161 +285 2.4870941840919194 41.50613347425886 108.18369254437567 +286 2.495820830351891 40.56430807424808 107.66130994509172 +287 2.504547476611863 39.627184535526744 107.10613266785997 +288 2.5132741228718345 38.695048315002964 106.51832982505724 +289 2.522000769131806 37.76818335039924 105.89808046712348 +290 2.530727415391778 36.84687197376254 105.24557352802174 +291 2.5394540616517496 35.93139482546318 104.56100776768659 +292 2.548180707911721 35.02203076870896 103.8445917114802 +293 2.5569073541716927 34.119056804600675 103.09654358667333 +294 2.5656340004316642 33.22274798775523 102.31709125597133 +295 2.574360646691636 32.33337734252086 101.50647214810482 +296 2.5830872929516078 31.451215779811665 100.6649331855067 +297 2.5918139392115793 30.576532014585375 99.79273070909721 +298 2.600540585471551 29.70959248399013 98.89013040019982 +299 2.609267231731523 28.85066126620511 97.9574071996123 +300 2.6179938779914944 28.000000000000007 96.99484522385713 +301 2.626720524251466 27.15786780503697 96.00273767863656 +302 2.6354471705114375 26.324521202940552 94.98138676951973 +303 2.644173816771409 25.500214039158514 93.93110360988749 +304 2.652900463031381 24.685197405638167 92.85220812616467 +305 2.6616271092913526 23.87971956434142 91.74502896036708 +306 2.670353755551324 23.0840258716215 90.60990336999411 +307 2.6790804018112957 22.29835870348532 89.44717712529682 +308 2.6878070480712672 21.522957381763167 88.2572044039529 +309 2.696533694331239 20.75805810120915 87.04034768318078 +310 2.705260340591211 20.003893857553802 85.79697762932555 +311 2.7139869868511823 19.260694376531625 84.52747298495049 +312 2.7227136331111543 18.528686043903946 83.23222045346814 +313 2.731440279371126 17.80809183650009 81.91161458134708 +314 2.7401669256310974 17.09913125429616 80.56605763792894 +315 2.748893571891069 16.402020253553342 79.19595949289334 +316 2.7576202181510405 15.71697118103554 77.80173749140775 +317 2.766346864411012 15.044192709326467 76.38381632699988 +318 2.7750735106709836 14.383889773265967 74.9426279121922 +319 2.7838001569309556 13.736263507524773 73.47861124693682 +320 2.792526803190927 13.10151118533725 71.99221228489245 +321 2.801253449450899 12.479826158409637 70.48388379758177 +322 2.8099800957108707 11.871397798023567 68.9540852364737 +323 2.8187067419708423 11.276411437351614 67.40328259302939 +324 2.827433388230814 10.695048315002955 65.831948256757 +325 2.8361600344907854 10.12748551981646 64.2405608713172 +326 2.844886680750757 9.573895936917687 62.62960518872369 +327 2.853613327010729 9.034448195056253 60.999571921683035 +328 2.8623399732707004 8.50930661524014 59.35095759411894 +329 2.871066619530672 7.998631160681722 57.68426438992611 +330 2.8797932657906435 7.5025773880714635 56.000000000000036 +331 2.888519912050615 7.021296400193845 54.29867746758981 +332 2.897246558310587 6.554934799900095 52.580815032019785 +333 2.9059732045705586 6.103634645451398 50.84693597082927 +334 2.91469985083053 5.667533407246658 49.09756844037675 +335 2.923426497090502 5.246763925947597 47.33324531495834 +336 2.9321531433504737 4.841454372014345 45.554504024489646 +337 2.9408797896104453 4.451728206663358 43.761886390798665 +338 2.949606435870417 4.0777041442599105 41.95593846258219 +339 2.9583330821303884 3.719496116156715 40.13721034907368 +340 2.96705972839036 3.3772132359891405 38.306256052474986 +341 2.975786374650332 3.050959766438263 36.463633299201526 +342 2.9845130209103035 2.7408350874714147 34.609903369994136 +343 2.993239667170275 2.4469336660700156 32.745630928946575 +344 3.001966313430247 2.1693450274541357 30.8713838515039 +345 3.0106929596902186 1.9081537278121807 28.98773305148233 +346 3.01941960595019 1.6634393285442162 27.09525230716282 +347 3.0281462522101616 1.43527637202682 25.194518086512918 +348 3.036872898470133 1.2237343589068939 23.28610937158911 +349 3.045599544730105 1.0288777269308111 21.370607482172996 +350 3.0543261909900767 0.8507658313163322 19.448595898696194 +351 3.0630528372500483 0.6894529266722849 17.52066008450588 +352 3.07177948351002 0.5449881504720722 15.587387307527408 +353 3.0805061297699914 0.41741550808597516 13.649366461376596 +354 3.089232776029963 0.3067738593767144 11.707187885977264 +355 3.097959422289935 0.21309690686224325 9.76144318773774 +356 3.1066860685499065 0.13641318544983871 7.812725059342073 +357 3.1154127148098785 0.07674605374386534 5.861627099209646 +358 3.12413936106985 0.03411368693063732 3.9087436306800853 +359 3.1328660073298216 0.00852907124207647 1.9546695209757408 +360 3.141592653589793 0.0 4.973799150320701e-14 +361 3.1503192998497647 0.00852907124207647 -1.954669520975716 +362 3.159045946109736 0.03411368693063732 -3.9087436306800356 +363 3.1677725923697078 0.07674605374386534 -5.861627099209621 +364 3.1764992386296798 0.13641318544983871 -7.812725059342023 +365 3.1852258848896513 0.21309690686224325 -9.76144318773769 +366 3.193952531149623 0.3067738593767082 -11.707187885977115 +367 3.2026791774095944 0.41741550808596894 -13.649366461376422 +368 3.211405823669566 0.5449881504720411 -15.587387307527235 +369 3.2201324699295375 0.6894529266722662 -17.52066008450573 +370 3.2288591161895095 0.8507658313163322 -19.448595898696144 +371 3.237585762449481 1.0288777269308111 -21.370607482172947 +372 3.246312408709453 1.2237343589068876 -23.28610937158906 +373 3.255039054969425 1.43527637202682 -25.194518086512968 +374 3.2637657012293966 1.6634393285442162 -27.095252307162845 +375 3.272492347489368 1.9081537278121807 -28.98773305148238 +376 3.2812189937493397 2.1693450274541606 -30.871383851503918 +377 3.2899456400093112 2.4469336660700094 -32.745630928946525 +378 3.2986722862692828 2.740835087471396 -34.609903369994086 +379 3.3073989325292543 3.050959766438263 -36.463633299201504 +380 3.3161255787892263 3.3772132359891405 -38.306256052474936 +381 3.324852225049198 3.719496116156715 -40.137210349073634 +382 3.3335788713091694 4.077704144259892 -41.95593846258213 +383 3.342305517569141 4.451728206663327 -43.76188639079863 +384 3.3510321638291125 4.841454372014327 -45.55450402448958 +385 3.359758810089084 5.246763925947579 -47.33324531495826 +386 3.368485456349056 5.667533407246658 -49.09756844037666 +387 3.3772121026090276 6.103634645451398 -50.846935970829215 +388 3.385938748868999 6.554934799900082 -52.580815032019714 +389 3.3946653951289707 7.021296400193814 -54.298677467589684 +390 3.4033920413889422 7.50257738807142 -55.9999999999999 +391 3.412118687648914 7.998631160681678 -57.68426438992598 +392 3.4208453339088853 8.509306615240115 -59.35095759411885 +393 3.4295719801688573 9.034448195056235 -60.999571921683 +394 3.4382986264288293 9.573895936917669 -62.629605188723666 +395 3.447025272688801 10.127485519816453 -64.24056087131714 +396 3.455751918948773 10.695048315002968 -65.83194825675703 +397 3.4644785652087444 11.276411437351609 -67.40328259302946 +398 3.473205211468716 11.87139779802358 -68.95408523647373 +399 3.4819318577286875 12.479826158409637 -70.4838837975818 +400 3.490658503988659 13.101511185337225 -71.99221228489239 +401 3.4993851502486306 13.736263507524761 -73.47861124693677 +402 3.5081117965086026 14.383889773265935 -74.94262791219217 +403 3.516838442768574 15.04419270932646 -76.38381632699983 +404 3.5255650890285457 15.716971181035527 -77.80173749140768 +405 3.5342917352885173 16.402020253553324 -79.19595949289331 +406 3.543018381548489 17.09913125429614 -80.5660576379289 +407 3.5517450278084604 17.808091836500072 -81.91161458134704 +408 3.560471674068432 18.528686043903903 -83.23222045346809 +409 3.569198320328404 19.260694376531603 -84.52747298495045 +410 3.5779249665883754 20.00389385755379 -85.7969776293255 +411 3.586651612848347 20.758058101209073 -87.04034768318068 +412 3.5953782591083185 21.522957381763117 -88.25720440395278 +413 3.60410490536829 22.29835870348526 -89.44717712529673 +414 3.6128315516282616 23.084025871621467 -90.60990336999403 +415 3.6215581978882336 23.879719564341396 -91.74502896036705 +416 3.630284844148205 24.68519740563816 -92.85220812616463 +417 3.639011490408177 25.50021403915848 -93.93110360988749 +418 3.647738136668149 26.324521202940552 -94.98138676951974 +419 3.6564647829281207 27.157867805036986 -96.0027376786366 +420 3.6651914291880923 28.000000000000014 -96.99484522385714 +421 3.673918075448064 28.85066126620513 -97.95740719961233 +422 3.6826447217080354 29.709592483990107 -98.89013040019981 +423 3.691371367968007 30.576532014585357 -99.79273070909716 +424 3.7000980142279785 31.451215779811655 -100.66493318550667 +425 3.7088246604879505 32.33337734252085 -101.50647214810479 +426 3.717551306747922 33.222747987755184 -102.31709125597129 +427 3.7262779530078936 34.11905680460067 -103.0965435866733 +428 3.735004599267865 35.02203076870891 -103.84459171148016 +429 3.7437312455278366 35.93139482546316 -104.56100776768656 +430 3.752457891787808 36.846871973762525 -105.24557352802171 +431 3.76118453804778 37.76818335039924 -105.89808046712348 +432 3.7699111843077517 38.695048315002936 -106.51832982505718 +433 3.7786378305677233 39.62718453552673 -107.10613266785995 +434 3.787364476827695 40.56430807424802 -107.66130994509167 +435 3.7960911230876664 41.506133474258796 -108.18369254437559 +436 3.804817769347638 42.45237384641857 -108.67312134291156 +437 3.8135444156076095 43.402740956743486 -109.12944725594632 +438 3.8222710618675815 44.35694531420544 -109.5525312821862 +439 3.8309977081275535 45.3146962589135 -109.94224454613837 +440 3.839724354387525 46.275702050651894 -110.29846833736728 +441 3.848451000647497 47.23966995774711 -110.62109414665542 +442 3.8571776469074686 48.20630634623636 -110.91002369905587 +443 3.86590429316744 49.17531676931175 -111.16516898382807 +444 3.8746309394274117 50.146406057011404 -111.38645228124662 +445 3.883357585687383 51.119278406131116 -111.5738061862755 +446 3.8920842319473548 52.09363747032898 -111.72717362910029 +447 3.9008108782073267 53.06918645039516 -111.84650789251225 +448 3.9095375244672983 54.04562818465996 -111.93177262613872 +449 3.91826417072727 55.02266523951213 -111.9829418575158 +450 3.9269908169872414 55.999999999999986 -112.0 +451 3.935717463247213 56.97733476048785 -111.9829418575158 +452 3.9444441095071845 57.95437181534001 -111.93177262613872 +453 3.953170755767156 58.9308135496048 -111.84650789251228 +454 3.961897402027128 59.906362529671014 -111.72717362910032 +455 3.9706240482870996 60.88072159386883 -111.57380618627549 +456 3.979350694547071 61.85359394298856 -111.38645228124662 +457 3.9880773408070427 62.82468323068822 -111.16516898382807 +458 3.9968039870670142 63.79369365376361 -110.91002369905588 +459 4.005530633326986 64.76033004225287 -110.62109414665542 +460 4.014257279586958 65.72429794934807 -110.29846833736731 +461 4.022983925846929 66.68530374108641 -109.94224454613837 +462 4.031710572106902 67.64305468579457 -109.5525312821862 +463 4.040437218366873 68.59725904325641 -109.12944725594635 +464 4.049163864626845 69.5476261535814 -108.67312134291159 +465 4.057890510886816 70.49386652574113 -108.18369254437566 +466 4.066617157146788 71.43569192575195 -107.6613099450917 +467 4.07534380340676 72.37281546447329 -107.10613266785995 +468 4.084070449666731 73.30495168499705 -106.51832982505721 +469 4.092797095926703 74.2318166496008 -105.89808046712346 +470 4.101523742186674 75.15312802623743 -105.24557352802174 +471 4.110250388446646 76.06860517453683 -104.56100776768659 +472 4.118977034706617 76.97796923129101 -103.84459171148023 +473 4.127703680966589 77.88094319539931 -103.09654358667335 +474 4.136430327226561 78.77725201224482 -102.31709125597129 +475 4.145156973486532 79.66662265747911 -101.50647214810483 +476 4.153883619746504 80.54878422018834 -100.6649331855067 +477 4.162610266006475 81.42346798541455 -99.79273070909727 +478 4.171336912266447 82.29040751600985 -98.89013040019985 +479 4.1800635585264185 83.14933873379479 -97.9574071996124 +480 4.1887902047863905 83.99999999999994 -96.99484522385715 +481 4.1975168510463625 84.84213219496301 -96.00273767863658 +482 4.206243497306334 85.67547879705941 -94.9813867695198 +483 4.214970143566306 86.49978596084149 -93.93110360988751 +484 4.223696789826278 87.31480259436184 -92.85220812616467 +485 4.23242343608625 88.12028043565861 -91.74502896036701 +486 4.241150082346221 88.91597412837848 -90.60990336999413 +487 4.249876728606193 89.70164129651471 -89.44717712529679 +488 4.258603374866164 90.47704261823684 -88.2572044039529 +489 4.267330021126136 91.24194189879088 -87.04034768318071 +490 4.276056667386108 91.99610614244622 -85.79697762932548 +491 4.284783313646079 92.73930562346838 -84.5274729849505 +492 4.293509959906051 93.47131395609605 -83.23222045346814 +493 4.302236606166022 94.19190816349987 -81.91161458134715 +494 4.310963252425994 94.90086874570383 -80.56605763792895 +495 4.319689898685965 95.59797974644661 -79.19595949289341 +496 4.328416544945937 96.28302881896445 -77.80173749140775 +497 4.337143191205909 96.95580729067356 -76.38381632699982 +498 4.34586983746588 97.61611022673405 -74.94262791219218 +499 4.354596483725852 98.26373649247523 -73.47861124693682 +500 4.363323129985823 98.89848881466274 -71.99221228489252 +501 4.372049776245795 99.52017384159035 -70.48388379758187 +502 4.380776422505767 100.12860220197642 -68.95408523647373 +503 4.389503068765738 100.72358856264836 -67.40328259302949 +504 4.39822971502571 101.30495168499706 -65.83194825675703 +505 4.4069563612856815 101.87251448018348 -64.24056087131727 +506 4.4156830075456535 102.4261040630823 -62.62960518872373 +507 4.4244096538056255 102.96555180494374 -60.999571921683035 +508 4.4331363000655974 103.49069338475988 -59.35095759411889 +509 4.4418629463255686 104.00136883931827 -57.68426438992611 +510 4.4505895925855405 104.49742261192857 -55.99999999999997 +511 4.4593162388455125 104.9787035998062 -54.29867746758967 +512 4.468042885105484 105.44506520009992 -52.580815032019785 +513 4.476769531365456 105.8963653545486 -50.846935970829165 +514 4.485496177625427 106.33246659275333 -49.09756844037674 +515 4.494222823885399 106.75323607405241 -47.33324531495834 +516 4.50294947014537 107.15854562798562 -45.55450402448973 +517 4.511676116405342 107.54827179333664 -43.761886390798665 +518 4.520402762665314 107.92229585574009 -41.955938462582104 +519 4.529129408925285 108.2805038838433 -40.13721034907368 +520 4.537856055185257 108.62278676401087 -38.30625605247489 +521 4.546582701445228 108.94904023356173 -36.463633299201646 +522 4.5553093477052 109.2591649125286 -34.609903369994164 +523 4.564035993965171 109.55306633392998 -32.74563092894667 +524 4.572762640225143 109.83065497254584 -30.871383851504 +525 4.581489286485115 110.09184627218784 -28.987733051482323 +526 4.590215932745086 110.33656067145577 -27.09525230716292 +527 4.598942579005058 110.56472362797318 -25.19451808651294 +528 4.607669225265029 110.77626564109309 -23.286109371589202 +529 4.616395871525002 110.9711222730692 -21.370607482172918 +530 4.625122517784973 111.14923416868365 -19.448595898696215 +531 4.633849164044945 111.31054707332773 -17.520660084505806 +532 4.642575810304916 111.45501184952792 -15.587387307527404 +533 4.651302456564888 111.58258449191403 -13.649366461376497 +534 4.66002910282486 111.69322614062331 -11.707187885977092 +535 4.6687557490848315 111.78690309313774 -9.761443187737738 +536 4.6774823953448035 111.86358681455015 -7.812725059341997 +537 4.686209041604775 111.92325394625612 -5.861627099209795 +538 4.694935687864747 111.96588631306938 -3.90874363068011 +539 4.703662334124718 111.9914709287579 -1.9546695209758649 +540 4.71238898038469 112.0 -4.973799150320701e-14 +541 4.721115626644662 111.9914709287579 1.9546695209757903 +542 4.729842272904633 111.96588631306938 3.9087436306800356 +543 4.738568919164605 111.92325394625612 5.861627099209696 +544 4.747295565424576 111.86358681455016 7.812725059341922 +545 4.756022211684548 111.78690309313774 9.761443187737639 +546 4.764748857944519 111.69322614062331 11.707187885977017 +547 4.773475504204491 111.58258449191406 13.649366461376403 +548 4.782202150464463 111.45501184952792 15.587387307527305 +549 4.790928796724434 111.31054707332774 17.52066008450573 +550 4.799655442984406 111.14923416868365 19.44859589869614 +551 4.808382089244377 110.9711222730692 21.370607482172844 +552 4.81710873550435 110.77626564109309 23.286109371589152 +553 4.825835381764321 110.56472362797318 25.194518086512865 +554 4.834562028024293 110.33656067145579 27.09525230716282 +555 4.843288674284264 110.09184627218784 28.987733051482273 +556 4.852015320544236 109.83065497254586 30.8713838515039 +557 4.860741966804208 109.55306633392999 32.745630928946575 +558 4.869468613064179 109.2591649125286 34.609903369994086 +559 4.878195259324151 108.94904023356173 36.463633299201575 +560 4.886921905584122 108.62278676401088 38.306256052474836 +561 4.895648551844094 108.2805038838433 40.137210349073634 +562 4.9043751981040655 107.9222958557401 41.95593846258201 +563 4.9131018443640375 107.54827179333667 43.76188639079863 +564 4.9218284906240095 107.15854562798566 45.554504024489646 +565 4.930555136883981 106.75323607405241 47.33324531495823 +566 4.939281783143953 106.33246659275335 49.09756844037664 +567 4.948008429403924 105.89636535454864 50.84693597082913 +568 4.956735075663896 105.44506520009992 52.580815032019686 +569 4.965461721923867 104.97870359980621 54.298677467589584 +570 4.974188368183839 104.49742261192857 55.9999999999999 +571 4.982915014443811 104.00136883931827 57.68426438992606 +572 4.991641660703782 103.4906933847599 59.350957594118796 +573 5.000368306963754 102.96555180494377 60.999571921683 +574 5.009094953223726 102.42610406308233 62.62960518872365 +575 5.017821599483698 101.87251448018353 64.24056087131721 +576 5.026548245743669 101.30495168499706 65.83194825675696 +577 5.035274892003641 100.7235885626484 67.40328259302943 +578 5.044001538263612 100.12860220197646 68.95408523647365 +579 5.052728184523584 99.52017384159038 70.48388379758177 +580 5.061454830783556 98.89848881466276 71.99221228489243 +581 5.070181477043527 98.26373649247523 73.47861124693678 +582 5.078908123303499 97.61611022673407 74.94262791219217 +583 5.08763476956347 96.95580729067359 76.38381632699976 +584 5.096361415823442 96.28302881896447 77.80173749140768 +585 5.105088062083414 95.59797974644664 79.19595949289337 +586 5.113814708343385 94.90086874570387 80.5660576379289 +587 5.122541354603357 94.19190816349992 81.9116145813471 +588 5.1312680008633285 93.47131395609611 83.23222045346809 +589 5.1399946471233005 92.73930562346841 84.52747298495044 +590 5.148721293383272 91.99610614244627 85.79697762932545 +591 5.1574479396432436 91.24194189879093 87.04034768318068 +592 5.1661745859032155 90.47704261823687 88.25720440395287 +593 5.174901232163187 89.70164129651475 89.44717712529673 +594 5.183627878423159 88.91597412837851 90.6099033699941 +595 5.19235452468313 88.12028043565866 91.74502896036698 +596 5.201081170943102 87.31480259436185 92.85220812616458 +597 5.209807817203074 86.49978596084152 93.93110360988749 +598 5.218534463463046 85.67547879705945 94.98138676951973 +599 5.227261109723017 84.84213219496309 96.00273767863654 +600 5.235987755982989 84.0 96.99484522385713 +601 5.244714402242961 83.14933873379483 97.95740719961239 +602 5.253441048502932 82.29040751600988 98.8901304001998 +603 5.262167694762904 81.4234679854146 99.79273070909724 +604 5.270894341022875 80.54878422018837 100.66493318550665 +605 5.279620987282847 79.66662265747917 101.50647214810483 +606 5.288347633542818 78.77725201224486 102.31709125597125 +607 5.29707427980279 77.88094319539934 103.0965435866733 +608 5.305800926062762 76.97796923129106 103.84459171148019 +609 5.314527572322733 76.06860517453686 104.56100776768656 +610 5.323254218582705 75.15312802623744 105.24557352802172 +611 5.331980864842676 74.23181664960083 105.89808046712344 +612 5.340707511102648 73.30495168499708 106.51832982505718 +613 5.349434157362619 72.37281546447335 107.10613266785991 +614 5.358160803622591 71.43569192575198 107.66130994509166 +615 5.366887449882563 70.49386652574117 108.18369254437562 +616 5.3756140961425345 69.54762615358148 108.67312134291154 +617 5.3843407424025065 68.59725904325647 109.12944725594632 +618 5.393067388662478 67.6430546857946 109.55253128218618 +619 5.4017940349224505 66.68530374108646 109.9422445461384 +620 5.410520681182422 65.72429794934811 110.2984683373673 +621 5.419247327442394 64.76033004225289 110.62109414665544 +622 5.427973973702365 63.7936936537637 110.91002369905586 +623 5.436700619962337 62.82468323068823 111.16516898382807 +624 5.445427266222309 61.85359394298856 111.38645228124662 +625 5.45415391248228 60.880721593868884 111.5738061862755 +626 5.462880558742252 59.906362529671 111.7271736291003 +627 5.471607205002223 58.930813549604885 111.84650789251225 +628 5.480333851262195 57.95437181534007 111.93177262613872 +629 5.489060497522166 56.977334760487956 111.9829418575158 +630 5.497787143782138 56.000000000000014 112.0 +631 5.50651379004211 55.0226652395121 111.98294185751584 +632 5.515240436302081 54.04562818465999 111.93177262613872 +633 5.523967082562053 53.06918645039516 111.84650789251225 +634 5.532693728822024 52.09363747032904 111.72717362910034 +635 5.541420375081996 51.11927840613117 111.57380618627552 +636 5.550147021341967 50.146406057011504 111.3864522812466 +637 5.558873667601939 49.17531676931179 111.16516898382808 +638 5.567600313861911 48.20630634623636 110.91002369905587 +639 5.576326960121882 47.239669957747125 110.62109414665545 +640 5.585053606381854 46.27570205065193 110.29846833736731 +641 5.593780252641825 45.31469625891358 109.94224454613841 +642 5.602506898901798 44.35694531420543 109.5525312821862 +643 5.611233545161769 43.40274095674357 109.12944725594632 +644 5.619960191421741 42.4523738464186 108.6731213429116 +645 5.6286868376817125 41.506133474258874 108.18369254437566 +646 5.6374134839416845 40.564308074248046 107.66130994509169 +647 5.6461401302016565 39.627184535526695 107.10613266785994 +648 5.654866776461628 38.69504831500296 106.51832982505721 +649 5.6635934227216 37.76818335039921 105.89808046712345 +650 5.672320068981571 36.84687197376262 105.24557352802175 +651 5.681046715241543 35.93139482546321 104.56100776768659 +652 5.689773361501514 35.02203076870898 103.84459171148023 +653 5.698500007761486 34.11905680460069 103.09654358667335 +654 5.707226654021458 33.22274798775518 102.31709125597129 +655 5.715953300281429 32.33337734252088 101.50647214810483 +656 5.724679946541401 31.451215779811676 100.6649331855067 +657 5.733406592801372 30.576532014585457 99.7927307090973 +658 5.742133239061344 29.709592483990157 98.89013040019985 +659 5.750859885321315 28.850661266205215 97.95740719961245 +660 5.759586531581287 28.00000000000005 96.99484522385718 +661 5.768313177841259 27.15786780503697 96.0027376786366 +662 5.77703982410123 26.324521202940595 94.98138676951979 +663 5.785766470361202 25.50021403915853 93.93110360988754 +664 5.794493116621174 24.685197405638167 92.85220812616467 +665 5.803219762881146 23.879719564341396 91.74502896036705 +666 5.811946409141117 23.084025871621517 90.60990336999414 +667 5.820673055401089 22.29835870348529 89.4471771252968 +668 5.82939970166106 21.522957381763185 88.25720440395291 +669 5.838126347921032 20.75805810120912 87.04034768318076 +670 5.846852994181004 20.00389385755379 85.7969776293255 +671 5.8555796404409755 19.260694376531617 84.52747298495052 +672 5.8643062867009474 18.528686043903946 83.23222045346814 +673 5.8730329329609186 17.80809183650013 81.91161458134718 +674 5.8817595792208905 17.099131254296154 80.56605763792896 +675 5.890486225480862 16.402020253553403 79.19595949289342 +676 5.899212871740834 15.716971181035557 77.80173749140775 +677 5.907939518000806 15.04419270932646 76.38381632699983 +678 5.916666164260777 14.383889773265967 74.9426279121922 +679 5.925392810520749 13.736263507524779 73.47861124693686 +680 5.93411945678072 13.101511185337287 71.99221228489255 +681 5.942846103040692 12.479826158409672 70.48388379758185 +682 5.951572749300664 11.871397798023555 68.95408523647374 +683 5.960299395560635 11.276411437351639 67.40328259302953 +684 5.969026041820607 10.695048315002968 65.83194825675702 +685 5.977752688080578 10.127485519816496 64.24056087131731 +686 5.98647933434055 9.573895936917706 62.629605188723744 +687 5.995205980600522 9.034448195056253 60.999571921683035 +688 6.003932626860494 8.509306615240135 59.35095759411889 +689 6.012659273120465 7.998631160681722 57.68426438992613 +690 6.021385919380437 7.502577388071445 56.0 +691 6.030112565640409 7.021296400193801 54.29867746758968 +692 6.03883921190038 6.554934799900107 52.580815032019785 +693 6.047565858160352 6.103634645451379 50.84693597082921 +694 6.056292504420323 5.667533407246658 49.09756844037675 +695 6.065019150680295 5.246763925947597 47.33324531495834 +696 6.073745796940266 4.8414543720143515 45.55450402448974 +697 6.082472443200238 4.451728206663333 43.76188639079871 +698 6.09119908946021 4.077704144259886 41.95593846258211 +699 6.0999257357201815 3.719496116156721 40.13721034907371 +700 6.1086523819801535 3.377213235989122 38.306256052474914 +701 6.117379028240125 3.0509597664382753 36.46363329920168 +702 6.126105674500097 2.7408350874714023 34.609903369994186 +703 6.134832320760068 2.446933666070022 32.74563092894667 +704 6.14355896702004 2.169345027454142 30.871383851504007 +705 6.152285613280012 1.9081537278121683 28.987733051482348 +706 6.161012259539983 1.6634393285441975 27.095252307162927 +707 6.169738905799955 1.43527637202682 25.19451808651294 +708 6.178465552059926 1.2237343589069125 23.286109371589227 +709 6.187192198319899 1.0288777269308111 21.370607482172947 +710 6.19591884457987 0.8507658313163384 19.448595898696244 +711 6.204645490839842 0.6894529266722724 17.520660084505806 +712 6.213372137099813 0.5449881504720722 15.587387307527408 +713 6.222098783359785 0.41741550808596894 13.649366461376522 +714 6.230825429619757 0.3067738593767082 11.707187885977115 +715 6.239552075879728 0.21309690686224325 9.761443187737763 +716 6.2482787221397 0.13641318544986358 7.812725059341995 +717 6.257005368399671 0.07674605374388399 5.861627099209795 +718 6.265732014659643 0.03411368693063732 3.90874363068011 +719 6.274458660919614 0.008529071242088904 1.95466952097589 + +HARMONIC_4 +N 720 RADIANS + +0 0.0 46.0 -0.0 +1 0.008726646259971648 45.999124230475935 0.2007103164625992 +2 0.017453292519943295 45.996496988597 0.4014053480575184 +3 0.02617993877991494 45.99211847443782 0.6020698110810813 +4 0.03490658503988659 45.985989021439195 0.8026884241575211 +5 0.04363323129985824 45.97810909638273 1.0032459094027302 +6 0.05235987755982988 45.9684792993552 1.2037269935877062 +7 0.061086523819801536 45.95710036370294 1.404116409301706 +8 0.06981317007977318 45.943973155975954 1.6043988961148796 +9 0.07853981633974483 45.929098675861944 1.804559201740436 +10 0.08726646259971647 45.91247805611015 2.004582083196137 +11 0.09599310885968812 45.89411256244511 2.204452307965154 +12 0.10471975511965977 45.874003593470285 2.4041546551560313 +13 0.11344640137963141 45.85215268056152 2.6036739166618528 +14 0.12217304763960307 45.828561487750406 2.802994898318391 +15 0.1308996938995747 45.80323181159764 3.002102421061186 +16 0.13962634015954636 45.77616558105612 3.200981322081504 +17 0.148352986419518 45.74736485732409 3.399616455981045 +18 0.15707963267948966 45.71683183368817 3.5979926959253117 +19 0.16580627893946132 45.684568835356316 3.796094934795584 +20 0.17453292519943295 45.65057831928079 3.993908086339397 +21 0.1832595714594046 45.61486287397096 4.191417086319392 +22 0.19198621771937624 45.57742521929627 4.388606893660532 +23 0.20071286397934787 45.538268206279085 4.585462491595536 +24 0.20943951023931953 45.49739481687753 4.781968888808466 +25 0.2181661564992912 45.454808163758464 4.978111120576366 +26 0.22689280275926282 45.410511490060415 5.173874249908891 +27 0.23561944901923448 45.36450816914657 5.369243368685822 +28 0.24434609527920614 45.31680170434792 5.564203598792361 +29 0.2530727415391778 45.267395728696485 5.758740093252156 +30 0.2617993877991494 45.21629400464857 5.952838037357978 +31 0.27052603405912107 45.163500423798325 6.146482649799909 +32 0.2792526803190927 45.109019006581335 6.33965918379098 +33 0.28797932657906433 45.05285390196844 6.532352928190221 +34 0.296705972839036 44.99500938714982 6.724549208622946 +35 0.30543261909900765 44.93548986720921 6.916233388598285 +36 0.3141592653589793 44.874299874788534 7.107390870623791 +37 0.32288591161895097 44.811444069742585 7.298007097317118 +38 0.33161255787892263 44.74692723878429 7.488067552514604 +39 0.3403392041388943 44.68075429512011 7.677557762376729 +40 0.3490658503988659 44.61293027807589 7.866463296490379 +41 0.35779249665883756 44.54346035271315 8.054769768967752 +42 0.3665191429188092 44.472349809435634 8.242462839541908 +43 0.3752457891787809 44.39960406358656 8.429528214658838 +44 0.3839724354387525 44.32522865503611 8.615951648565975 +45 0.39269908169872414 44.249229247759594 8.801718944397068 +46 0.40142572795869574 44.17161162940613 8.986815955253293 +47 0.41015237421866746 44.09238171085785 9.171228585280662 +48 0.41887902047863906 44.011545525779816 9.354942790743404 +49 0.42760566673861067 43.92910923016049 9.537944581093495 +50 0.4363323129985824 43.84507910184295 9.720220020036088 +51 0.445058959258554 43.7594615400468 9.901755226590785 +52 0.45378560551852565 43.672263064880845 10.08253637614878 +53 0.4625122517784973 43.58349031684658 10.262549701525602 +54 0.47123889803846897 43.49315005633246 10.441781494009577 +55 0.4799655442984406 43.401249163099095 10.620218104405781 +56 0.4886921905584123 43.30779463575532 10.797845944075487 +57 0.4974188368183839 43.2127935912252 10.974651485970993 +58 0.5061454830783556 43.1162532642061 11.150621265665752 +59 0.5148721293383272 43.018181006617695 11.325741882379742 +60 0.5235987755982988 42.918584287042094 11.499999999999998 +61 0.5323254218582705 42.81747069015509 11.673382348096192 +62 0.5410520681182421 42.71484791614858 11.845875722931249 +63 0.5497787143782138 42.61072378014412 12.017466988466825 +64 0.5585053606381855 42.50510621159779 12.188143077363716 +65 0.5672320068981571 42.39800325369637 12.357890991976952 +66 0.5759586531581287 42.28942306274475 12.52669780534562 +67 0.5846852994181004 42.179373907544864 12.69455066217734 +68 0.593411945678072 42.06786416876596 12.861436779827178 +69 0.6021385919380438 41.954902338306354 13.027343449271157 +70 0.6108652381980153 41.840497018646815 13.192258036074058 +71 0.619591884457987 41.724656922195344 13.356167981351614 +72 0.6283185307179586 41.60739087062379 13.519060802726882 +73 0.6370451769779303 41.488707794195996 13.680924095280849 +74 0.6457718232379019 41.368616731087734 13.84174553249711 +75 0.6544984694978736 41.247126826698405 14.001512867200574 +76 0.6632251157578453 41.1242473329546 14.16021393249014 +77 0.6719517620178168 40.99998760760552 14.317836642665249 +78 0.6806784082777886 40.87435711351033 14.474368994146262 +79 0.6894050545377601 40.74736541791756 14.629799066388571 +80 0.6981317007977318 40.61902219173649 14.784115022790406 +81 0.7068583470577035 40.48933720880071 14.937305111594224 +82 0.7155849933176751 40.35832034512376 15.089357666781668 +83 0.7243116395776468 40.225981578147056 15.240261108961963 +84 0.7330382858376184 40.09233098598007 15.390003946253739 +85 0.74176493209759 39.95737874663285 15.538574775160184 +86 0.7504915783575618 39.82113513724092 15.685962281437467 +87 0.7592182246175333 39.68361053328261 15.832155240956343 +88 0.767944870877505 39.544815407788974 15.977142520556937 +89 0.7766715171374766 39.40476033054617 16.12091307889657 +90 0.7853981633974483 39.26345596729059 16.263455967290593 +91 0.7941248096574199 39.12091307889657 16.404760330546175 +92 0.8028514559173915 38.97714252055694 16.544815407788974 +93 0.8115781021773633 38.83215524095634 16.683610533282614 +94 0.8203047484373349 38.68596228143747 16.82113513724092 +95 0.8290313946973066 38.538574775160185 16.957378746632852 +96 0.8377580409572781 38.39000394625374 17.092330985980066 +97 0.8464846872172498 38.24026110896197 17.225981578147046 +98 0.8552113334772213 38.089357666781666 17.358320345123754 +99 0.8639379797371932 37.93730511159422 17.489337208800716 +100 0.8726646259971648 37.78411502279041 17.619022191736494 +101 0.8813912722571364 37.62979906638857 17.74736541791756 +102 0.890117918517108 37.47436899414626 17.87435711351033 +103 0.8988445647770796 37.317836642665256 17.99998760760552 +104 0.9075712110370513 37.16021393249014 18.124247332954603 +105 0.9162978572970231 37.00151286720057 18.24712682669841 +106 0.9250245035569946 36.841745532497114 18.368616731087734 +107 0.9337511498169663 36.680924095280844 18.488707794195996 +108 0.9424777960769379 36.519060802726884 18.607390870623792 +109 0.9512044423369095 36.35616798135162 18.72465692219534 +110 0.9599310885968813 36.19225803607406 18.840497018646815 +111 0.9686577348568529 36.02734344927116 18.95490233830636 +112 0.9773843811168246 35.86143677982717 19.06786416876596 +113 0.9861110273767961 35.694550662177335 19.179373907544868 +114 0.9948376736367678 35.52669780534563 19.289423062744753 +115 1.0035643198967394 35.35789099197695 19.398003253696373 +116 1.0122909661567112 35.18814307736372 19.5051062115978 +117 1.0210176124166828 35.01746698846682 19.610723780144124 +118 1.0297442586766543 34.84587572293125 19.71484791614858 +119 1.038470904936626 34.673382348096204 19.81747069015509 +120 1.0471975511965976 34.5 19.918584287042087 +121 1.0559241974565694 34.325741882379745 20.01818100661769 +122 1.064650843716541 34.150621265665755 20.1162532642061 +123 1.0733774899765127 33.974651485970995 20.212793591225203 +124 1.0821041362364843 33.79784594407549 20.30779463575532 +125 1.0908307824964558 33.62021810440579 20.401249163099095 +126 1.0995574287564276 33.441781494009575 20.49315005633246 +127 1.1082840750163994 33.2625497015256 20.58349031684658 +128 1.117010721276371 33.08253637614878 20.67226306488084 +129 1.1257373675363425 32.901755226590794 20.759461540046793 +130 1.1344640137963142 32.72022002003609 20.845079101842952 +131 1.1431906600562858 32.5379445810935 20.929109230160492 +132 1.1519173063162573 32.35494279074341 21.011545525779816 +133 1.160643952576229 32.171228585280666 21.092381710857854 +134 1.1693705988362009 31.98681595525329 21.17161162940613 +135 1.1780972450961724 31.801718944397066 21.249229247759594 +136 1.186823891356144 31.61595164856598 21.32522865503611 +137 1.1955505376161157 31.429528214658838 21.399604063586565 +138 1.2042771838760875 31.2424628395419 21.47234980943564 +139 1.213003830136059 31.054769768967752 21.543460352713144 +140 1.2217304763960306 30.866463296490384 21.612930278075893 +141 1.2304571226560024 30.67755776237673 21.680754295120106 +142 1.239183768915974 30.488067552514604 21.746927238784284 +143 1.2479104151759455 30.29800709731712 21.811444069742585 +144 1.2566370614359172 30.107390870623792 21.874299874788534 +145 1.265363707695889 29.91623338859828 21.93548986720922 +146 1.2740903539558606 29.724549208622946 21.995009387149818 +147 1.2828170002158321 29.532352928190225 22.05285390196844 +148 1.2915436464758039 29.339659183790978 22.109019006581335 +149 1.3002702927357754 29.146482649799907 22.16350042379833 +150 1.3089969389957472 28.952838037357978 22.21629400464857 +151 1.3177235852557188 28.758740093252154 22.267395728696478 +152 1.3264502315156905 28.564203598792353 22.31680170434792 +153 1.335176877775662 28.369243368685826 22.36450816914656 +154 1.3439035240356336 28.1738742499089 22.410511490060408 +155 1.3526301702956054 27.978111120576365 22.454808163758468 +156 1.3613568165555772 27.78196888880846 22.49739481687753 +157 1.3700834628155487 27.585462491595536 22.538268206279085 +158 1.3788101090755203 27.38860689366053 22.57742521929627 +159 1.3875367553354918 27.191417086319397 22.614862873970953 +160 1.3962634015954636 26.993908086339403 22.650578319280786 +161 1.4049900478554354 26.796094934795583 22.684568835356323 +162 1.413716694115407 26.597992695925313 22.71683183368817 +163 1.4224433403753785 26.39961645598105 22.747364857324087 +164 1.4311699866353502 26.200981322081503 22.77616558105612 +165 1.4398966328953218 26.002102421061192 22.80323181159764 +166 1.4486232791552935 25.802994898318392 22.82856148775041 +167 1.457349925415265 25.603673916661858 22.852152680561513 +168 1.4660765716752369 25.40415465515603 22.874003593470285 +169 1.4748032179352084 25.204452307965155 22.894112562445113 +170 1.48352986419518 25.00458208319614 22.912478056110146 +171 1.4922565104551517 24.804559201740435 22.929098675861944 +172 1.5009831567151235 24.60439889611488 22.943973155975957 +173 1.509709802975095 24.40411640930171 22.95710036370294 +174 1.5184364492350666 24.20372699358771 22.9684792993552 +175 1.5271630954950384 24.00324590940273 22.978109096382727 +176 1.53588974175501 23.802688424157527 22.9859890214392 +177 1.5446163880149815 23.602069811081087 22.992118474437817 +178 1.5533430342749532 23.401405348057523 22.996496988597 +179 1.562069680534925 23.200710316462597 22.99912423047594 +180 1.5707963267948966 23.0 23.0 +181 1.579522973054868 22.799289683537403 22.99912423047594 +182 1.5882496193148399 22.59859465194248 22.996496988597 +183 1.5969762655748114 22.39793018891892 22.992118474437817 +184 1.605702911834783 22.197311575842484 22.9859890214392 +185 1.6144295580947547 21.996754090597275 22.97810909638273 +186 1.6231562043547265 21.796273006412292 22.9684792993552 +187 1.6318828506146983 21.59588359069829 22.95710036370294 +188 1.6406094968746698 21.395601103885117 22.943973155975957 +189 1.6493361431346414 21.19544079825957 22.929098675861944 +190 1.6580627893946132 20.99541791680386 22.912478056110146 +191 1.6667894356545847 20.795547692034848 22.894112562445113 +192 1.6755160819145563 20.595845344843973 22.874003593470285 +193 1.684242728174528 20.396326083338145 22.852152680561513 +194 1.6929693744344996 20.19700510168161 22.82856148775041 +195 1.7016960206944711 19.99789757893882 22.80323181159764 +196 1.7104226669544427 19.7990186779185 22.77616558105612 +197 1.7191493132144147 19.600383544018953 22.747364857324087 +198 1.7278759594743864 19.402007304074687 22.71683183368817 +199 1.736602605734358 19.203905065204413 22.684568835356323 +200 1.7453292519943295 19.006091913660605 22.650578319280786 +201 1.7540558982543013 18.808582913680606 22.614862873970953 +202 1.7627825445142729 18.61139310633947 22.57742521929627 +203 1.7715091907742444 18.414537508404468 22.538268206279085 +204 1.780235837034216 18.21803111119154 22.49739481687753 +205 1.7889624832941877 18.021888879423635 22.454808163758468 +206 1.7976891295541593 17.82612575009111 22.410511490060415 +207 1.8064157758141308 17.630756631314185 22.364508169146568 +208 1.8151424220741026 17.435796401207647 22.31680170434792 +209 1.8238690683340746 17.241259906747842 22.267395728696474 +210 1.8325957145940461 17.047161962642022 22.21629400464857 +211 1.8413223608540177 16.853517350200093 22.16350042379833 +212 1.8500490071139892 16.660340816209022 22.109019006581335 +213 1.858775653373961 16.46764707180978 22.05285390196844 +214 1.8675022996339325 16.275450791377057 21.995009387149818 +215 1.876228945893904 16.08376661140172 21.93548986720922 +216 1.8849555921538759 15.892609129376211 21.874299874788534 +217 1.8936822384138474 15.701992902682884 21.811444069742585 +218 1.902408884673819 15.511932447485401 21.74692723878429 +219 1.9111355309337907 15.322442237623271 21.680754295120106 +220 1.9198621771937625 15.133536703509622 21.612930278075893 +221 1.9285888234537343 14.945230231032248 21.543460352713144 +222 1.9373154697137058 14.757537160458094 21.47234980943564 +223 1.9460421159736774 14.570471785341164 21.399604063586565 +224 1.9547687622336491 14.384048351434023 21.32522865503611 +225 1.9634954084936207 14.198281055602934 21.249229247759594 +226 1.9722220547535922 14.013184044746707 21.17161162940613 +227 1.980948701013564 13.828771414719338 21.092381710857854 +228 1.9896753472735356 13.645057209256601 21.01154552577982 +229 1.9984019935335071 13.462055418906505 20.929109230160496 +230 2.007128639793479 13.279779979963916 20.845079101842952 +231 2.015855286053451 13.098244773409206 20.759461540046793 +232 2.0245819323134224 12.917463623851214 20.672263064880838 +233 2.033308578573394 12.737450298474398 20.583490316846575 +234 2.0420352248333655 12.558218505990425 20.49315005633246 +235 2.050761871093337 12.379781895594226 20.401249163099102 +236 2.0594885173533086 12.202154055924519 20.30779463575532 +237 2.0682151636132806 12.025348514029005 20.212793591225203 +238 2.076941809873252 11.849378734334248 20.1162532642061 +239 2.0856684561332237 11.674258117620258 20.01818100661769 +240 2.0943951023931953 11.500000000000005 19.918584287042094 +241 2.103121748653167 11.326617651903813 19.817470690155098 +242 2.111848394913139 11.154124277068755 19.71484791614858 +243 2.1205750411731104 10.982533011533175 19.610723780144124 +244 2.129301687433082 10.81185692263629 19.5051062115978 +245 2.138028333693054 10.642109008023048 19.398003253696373 +246 2.1467549799530254 10.473302194654377 19.289423062744753 +247 2.155481626212997 10.305449337822662 19.179373907544868 +248 2.1642082724729685 10.138563220172824 19.06786416876596 +249 2.17293491873294 9.972656550728853 18.954902338306365 +250 2.1816615649929116 9.807741963925945 18.840497018646815 +251 2.1903882112528836 9.643832018648386 18.724656922195344 +252 2.199114857512855 9.48093919727312 18.607390870623792 +253 2.2078415037728267 9.319075904719153 18.488707794196 +254 2.2165681500327987 9.158254467502887 18.368616731087734 +255 2.2252947962927703 8.998487132799427 18.24712682669841 +256 2.234021442552742 8.83978606750986 18.124247332954607 +257 2.2427480888127134 8.682163357334751 17.999987607605522 +258 2.251474735072685 8.52563100585374 17.87435711351033 +259 2.260201381332657 8.370200933611429 17.747365417917553 +260 2.2689280275926285 8.215884977209592 17.619022191736494 +261 2.2776546738526 8.062694888405778 17.489337208800713 +262 2.2863813201125716 7.9106423332183375 17.358320345123758 +263 2.295107966372543 7.759738891038043 17.225981578147053 +264 2.3038346126325147 7.6099960537462685 17.092330985980073 +265 2.3125612588924866 7.461425224839812 16.957378746632855 +266 2.321287905152458 7.314037718562537 16.821135137240926 +267 2.33001455141243 7.167844759043658 16.683610533282614 +268 2.3387411976724017 7.0228574794430605 16.544815407788974 +269 2.3474678439323733 6.879086921103429 16.404760330546175 +270 2.356194490192345 6.736544032709406 16.263455967290593 +271 2.3649211364523164 6.595239669453827 16.120913078896574 +272 2.373647782712288 6.455184592211028 15.977142520556942 +273 2.3823744289722595 6.316389466717392 15.83215524095635 +274 2.3911010752322315 6.178864862759079 15.685962281437467 +275 2.399827721492203 6.042621253367151 15.538574775160189 +276 2.408554367752175 5.9076690140199295 15.390003946253735 +277 2.4172810140121466 5.774018421852952 15.24026110896196 +278 2.426007660272118 5.641679654876244 15.089357666781668 +279 2.4347343065320897 5.510662791199291 14.93730511159423 +280 2.443460952792061 5.380977808263508 14.784115022790408 +281 2.4521875990520328 5.252634582082445 14.629799066388577 +282 2.4609142453120048 5.125642886489669 14.47436899414626 +283 2.4696408915719763 5.000012392394482 14.317836642665254 +284 2.478367537831948 4.875752667045396 14.160213932490143 +285 2.4870941840919194 4.752873173301594 14.00151286720058 +286 2.495820830351891 4.63138326891227 13.841745532497114 +287 2.504547476611863 4.511292205804002 13.680924095280849 +288 2.5132741228718345 4.392609129376211 13.519060802726887 +289 2.522000769131806 4.27534307780466 13.356167981351614 +290 2.530727415391778 4.159502981353186 13.192258036074058 +291 2.5394540616517496 4.045097661693639 13.027343449271156 +292 2.548180707911721 3.9321358312340453 12.861436779827182 +293 2.5569073541716927 3.820626092455131 12.69455066217734 +294 2.5656340004316642 3.7105769372552517 12.52669780534563 +295 2.574360646691636 3.6019967463036338 12.357890991976955 +296 2.5830872929516078 3.494893788402203 12.188143077363712 +297 2.5918139392115793 3.3892762198558772 12.017466988466825 +298 2.600540585471551 3.2851520838514188 11.845875722931249 +299 2.609267231731523 3.182529309844906 11.673382348096192 +300 2.6179938779914944 3.081415712957912 11.5 +301 2.626720524251466 2.9818189933823094 11.325741882379743 +302 2.6354471705114375 2.8837467357939004 11.150621265665755 +303 2.644173816771409 2.7872064087748014 10.974651485970996 +304 2.652900463031381 2.6922053642446793 10.797845944075487 +305 2.6616271092913526 2.5987508369009005 10.62021810440578 +306 2.670353755551324 2.506849943667538 10.441781494009577 +307 2.6790804018112957 2.4165096831534276 10.262549701525607 +308 2.6878070480712672 2.3277369351191632 10.082536376148786 +309 2.696533694331239 2.240538459953213 9.901755226590796 +310 2.705260340591211 2.1549208981570516 9.720220020036088 +311 2.7139869868511823 2.070890769839511 9.537944581093504 +312 2.7227136331111543 1.98845447422018 9.354942790743404 +313 2.731440279371126 1.9076182891421496 9.171228585280662 +314 2.7401669256310974 1.828388370593874 8.986815955253299 +315 2.748893571891069 1.750770752240405 8.801718944397068 +316 2.7576202181510405 1.6747713449638892 8.615951648565982 +317 2.766346864411012 1.6003959364134372 8.429528214658843 +318 2.7750735106709836 1.5276501905643651 8.242462839541917 +319 2.7838001569309556 1.456539647286856 8.054769768967752 +320 2.792526803190927 1.3870697219241088 7.866463296490386 +321 2.801253449450899 1.3192457048798987 7.677557762376729 +322 2.8099800957108707 1.2530727612157126 7.4880675525146 +323 2.8187067419708423 1.1885559302574182 7.298007097317118 +324 2.827433388230814 1.125700125211469 7.107390870623792 +325 2.8361600344907854 1.0645101327907804 6.916233388598285 +326 2.844886680750757 1.0049906128501875 6.724549208622951 +327 2.853613327010729 0.9471460980315598 6.532352928190221 +328 2.8623399732707004 0.8909809934186654 6.33965918379098 +329 2.871066619530672 0.8364995762016721 6.146482649799912 +330 2.8797932657906435 0.7837059953514339 5.952838037357982 +331 2.888519912050615 0.7326042713035219 5.758740093252159 +332 2.897246558310587 0.6831982956520811 5.56420359879236 +333 2.9059732045705586 0.6354918308534366 5.369243368685828 +334 2.91469985083053 0.5894885099395893 5.173874249908903 +335 2.923426497090502 0.5451918362415327 4.978111120576366 +336 2.9321531433504737 0.5026051831224692 4.781968888808466 +337 2.9408797896104453 0.461731793720922 4.585462491595536 +338 2.949606435870417 0.42257478070372856 4.388606893660535 +339 2.9583330821303884 0.3851371260290464 4.191417086319397 +340 2.96705972839036 0.34942168071921553 3.993908086339407 +341 2.975786374650332 0.3154311646436795 3.796094934795584 +342 2.9845130209103035 0.28316816631183384 3.5979926959253126 +343 2.993239667170275 0.252635142675913 3.3996164559810502 +344 3.001966313430247 0.22383441894388167 3.200981322081504 +345 3.0106929596902186 0.1967681884023612 3.0021024210611866 +346 3.01941960595019 0.17143851224959694 2.802994898318396 +347 3.0281462522101616 0.14784731943848595 2.6036739166618585 +348 3.036872898470133 0.12599640652971433 2.4041546551560367 +349 3.045599544730105 0.10588743755488639 2.2044523079651492 +350 3.0543261909900767 0.0875219438898499 2.004582083196137 +351 3.0630528372500483 0.07090132413805683 1.8045592017404362 +352 3.07177948351002 0.056026844024043454 1.6043988961148898 +353 3.0805061297699914 0.04289963629706084 1.4041164093017162 +354 3.089232776029963 0.03152070064480439 1.2037269935877162 +355 3.097959422289935 0.02189090361727064 1.0032459094027304 +356 3.1066860685499065 0.014010978560797471 0.8026884241575263 +357 3.1154127148098785 0.007881525562183023 0.602069811081076 +358 3.12413936106985 0.0035030114030007997 0.4014053480575184 +359 3.1328660073298216 0.0008757695240573238 0.20071031646259918 +360 3.141592653589793 0.0 5.10702591327572e-15 +361 3.1503192998497647 0.0008757695240573238 -0.20071031646259663 +362 3.159045946109736 0.0035030114030007997 -0.40140534805751327 +363 3.1677725923697078 0.007881525562183023 -0.6020698110810735 +364 3.1764992386296798 0.014010978560797471 -0.8026884241575212 +365 3.1852258848896513 0.02189090361727064 -1.0032459094027253 +366 3.193952531149623 0.03152070064480439 -1.2037269935877009 +367 3.2026791774095944 0.04289963629706084 -1.4041164093016985 +368 3.211405823669566 0.05602684402403835 -1.604398896114872 +369 3.2201324699295375 0.07090132413805428 -1.8045592017404206 +370 3.2288591161895095 0.0875219438898499 -2.004582083196132 +371 3.237585762449481 0.10588743755488639 -2.2044523079651444 +372 3.246312408709453 0.12599640652971433 -2.4041546551560313 +373 3.255039054969425 0.14784731943848595 -2.6036739166618634 +374 3.2637657012293966 0.17143851224959694 -2.8029948983183988 +375 3.272492347489368 0.1967681884023612 -3.002102421061192 +376 3.2812189937493397 0.22383441894388678 -3.200981322081507 +377 3.2899456400093112 0.252635142675913 -3.399616455981045 +378 3.2986722862692828 0.2831681663118313 -3.597992695925307 +379 3.3073989325292543 0.3154311646436795 -3.7960949347955815 +380 3.3161255787892263 0.34942168071921553 -3.993908086339402 +381 3.324852225049198 0.3851371260290464 -4.191417086319392 +382 3.3335788713091694 0.422574780703726 -4.388606893660529 +383 3.342305517569141 0.4617317937209169 -4.585462491595532 +384 3.3510321638291125 0.5026051831224666 -4.781968888808459 +385 3.359758810089084 0.5451918362415301 -4.978111120576358 +386 3.368485456349056 0.5894885099395919 -5.173874249908894 +387 3.3772121026090276 0.6354918308534392 -5.369243368685822 +388 3.385938748868999 0.6831982956520811 -5.564203598792352 +389 3.3946653951289707 0.7326042713035193 -5.758740093252145 +390 3.4033920413889422 0.7837059953514288 -5.952838037357967 +391 3.412118687648914 0.836499576201667 -6.146482649799897 +392 3.4208453339088853 0.8909809934186629 -6.339659183790969 +393 3.4295719801688573 0.9471460980315572 -6.532352928190216 +394 3.4382986264288293 1.004990612850185 -6.724549208622947 +395 3.447025272688801 1.0645101327907804 -6.916233388598279 +396 3.455751918948773 1.1257001252114713 -7.107390870623797 +397 3.4644785652087444 1.1885559302574156 -7.298007097317124 +398 3.473205211468716 1.253072761215715 -7.488067552514604 +399 3.4819318577286875 1.3192457048798987 -7.677557762376732 +400 3.490658503988659 1.3870697219241062 -7.866463296490379 +401 3.4993851502486306 1.456539647286856 -8.054769768967747 +402 3.5081117965086026 1.5276501905643598 -8.242462839541911 +403 3.516838442768574 1.6003959364134372 -8.429528214658838 +404 3.5255650890285457 1.6747713449638892 -8.615951648565975 +405 3.5342917352885173 1.7507707522404026 -8.801718944397061 +406 3.543018381548489 1.8283883705938715 -8.986815955253293 +407 3.5517450278084604 1.907618289142147 -9.171228585280657 +408 3.560471674068432 1.988454474220175 -9.354942790743396 +409 3.569198320328404 2.0708907698395085 -9.537944581093498 +410 3.5779249665883754 2.1549208981570516 -9.720220020036084 +411 3.586651612848347 2.240538459953203 -9.90175522659078 +412 3.5953782591083185 2.327736935119158 -10.082536376148772 +413 3.60410490536829 2.41650968315342 -10.262549701525593 +414 3.6128315516282616 2.506849943667536 -10.441781494009565 +415 3.6215581978882336 2.598750836900898 -10.620218104405774 +416 3.630284844148205 2.6922053642446793 -10.797845944075481 +417 3.639011490408177 2.787206408774796 -10.974651485970991 +418 3.647738136668149 2.8837467357939004 -11.150621265665759 +419 3.6564647829281207 2.9818189933823094 -11.325741882379749 +420 3.6651914291880923 3.081415712957912 -11.500000000000002 +421 3.673918075448064 3.1825293098449086 -11.673382348096197 +422 3.6826447217080354 3.2851520838514165 -11.845875722931245 +423 3.691371367968007 3.3892762198558772 -12.017466988466817 +424 3.7000980142279785 3.494893788402203 -12.18814307736371 +425 3.7088246604879505 3.601996746303631 -12.35789099197695 +426 3.717551306747922 3.710576937255247 -12.526697805345623 +427 3.7262779530078936 3.820626092455131 -12.694550662177338 +428 3.735004599267865 3.93213583123404 -12.861436779827173 +429 3.7437312455278366 4.045097661693639 -13.02734344927115 +430 3.752457891787808 4.159502981353186 -13.192258036074055 +431 3.76118453804778 4.27534307780466 -13.356167981351614 +432 3.7699111843077517 4.392609129376209 -13.51906080272688 +433 3.7786378305677233 4.511292205804 -13.680924095280847 +434 3.787364476827695 4.631383268912263 -13.841745532497105 +435 3.7960911230876664 4.752873173301588 -14.001512867200566 +436 3.804817769347638 4.875752667045391 -14.16021393249013 +437 3.8135444156076095 5.00001239239447 -14.317836642665238 +438 3.8222710618675815 5.125642886489667 -14.474368994146255 +439 3.8309977081275535 5.252634582082442 -14.629799066388573 +440 3.839724354387525 5.380977808263506 -14.784115022790402 +441 3.848451000647497 5.510662791199294 -14.93730511159423 +442 3.8571776469074686 5.641679654876249 -15.08935766678167 +443 3.86590429316744 5.774018421852952 -15.240261108961963 +444 3.8746309394274117 5.907669014019932 -15.390003946253739 +445 3.883357585687383 6.042621253367144 -15.538574775160184 +446 3.8920842319473548 6.178864862759079 -15.685962281437462 +447 3.9008108782073267 6.316389466717387 -15.832155240956343 +448 3.9095375244672983 6.455184592211025 -15.977142520556939 +449 3.91826417072727 6.595239669453827 -16.12091307889657 +450 3.9269908169872414 6.736544032709406 -16.263455967290593 +451 3.935717463247213 6.8790869211034265 -16.40476033054617 +452 3.9444441095071845 7.022857479443055 -16.54481540778897 +453 3.953170755767156 7.16784475904365 -16.683610533282607 +454 3.961897402027128 7.314037718562533 -16.82113513724092 +455 3.9706240482870996 7.461425224839812 -16.95737874663285 +456 3.979350694547071 7.609996053746255 -17.092330985980063 +457 3.9880773408070427 7.759738891038032 -17.225981578147042 +458 3.9968039870670142 7.910642333218325 -17.358320345123747 +459 4.005530633326986 8.062694888405769 -17.489337208800706 +460 4.014257279586958 8.215884977209592 -17.61902219173649 +461 4.022983925846929 8.370200933611416 -17.747365417917546 +462 4.031710572106902 8.525631005853748 -17.874357113510335 +463 4.040437218366873 8.682163357334748 -17.99998760760552 +464 4.049163864626845 8.839786067509865 -18.124247332954607 +465 4.057890510886816 8.99848713279942 -18.247126826698405 +466 4.066617157146788 9.15825446750289 -18.368616731087734 +467 4.07534380340676 9.319075904719156 -18.488707794196003 +468 4.084070449666731 9.480939197273115 -18.60739087062379 +469 4.092797095926703 9.643832018648391 -18.724656922195344 +470 4.101523742186674 9.807741963925936 -18.840497018646808 +471 4.110250388446646 9.972656550728848 -18.95490233830636 +472 4.118977034706617 10.138563220172813 -19.06786416876595 +473 4.127703680966589 10.305449337822658 -19.179373907544868 +474 4.136430327226561 10.47330219465438 -19.289423062744753 +475 4.145156973486532 10.642109008023043 -19.398003253696363 +476 4.153883619746504 10.811856922636288 -19.5051062115978 +477 4.162610266006475 10.982533011533162 -19.610723780144113 +478 4.171336912266447 11.154124277068746 -19.714847916148578 +479 4.1800635585264185 11.326617651903788 -19.81747069015508 +480 4.1887902047863905 11.499999999999993 -19.918584287042084 +481 4.1975168510463625 11.674258117620255 -20.01818100661769 +482 4.206243497306334 11.849378734334234 -20.116253264206097 +483 4.214970143566306 12.025348514029004 -20.2127935912252 +484 4.223696789826278 12.202154055924513 -20.30779463575532 +485 4.23242343608625 12.379781895594231 -20.401249163099102 +486 4.241150082346221 12.55821850599042 -20.49315005633246 +487 4.249876728606193 12.737450298474398 -20.58349031684658 +488 4.258603374866164 12.917463623851214 -20.672263064880838 +489 4.267330021126136 13.098244773409215 -20.759461540046793 +490 4.276056667386108 13.279779979963921 -20.845079101842952 +491 4.284783313646079 13.462055418906496 -20.929109230160492 +492 4.293509959906051 13.645057209256596 -21.01154552577982 +493 4.302236606166022 13.828771414719327 -21.092381710857847 +494 4.310963252425994 14.013184044746701 -21.171611629406126 +495 4.319689898685965 14.198281055602923 -21.24922924775959 +496 4.328416544945937 14.384048351434018 -21.32522865503611 +497 4.337143191205909 14.570471785341164 -21.399604063586565 +498 4.34586983746588 14.757537160458083 -21.472349809435638 +499 4.354596483725852 14.945230231032248 -21.543460352713144 +500 4.363323129985823 15.133536703509606 -21.61293027807589 +501 4.372049776245795 15.32244223762326 -21.6807542951201 +502 4.380776422505767 15.511932447485396 -21.746927238784284 +503 4.389503068765738 15.701992902682871 -21.811444069742578 +504 4.39822971502571 15.892609129376206 -21.874299874788534 +505 4.4069563612856815 16.083766611401707 -21.935489867209213 +506 4.4156830075456535 16.275450791377043 -21.995009387149814 +507 4.4244096538056255 16.46764707180978 -22.05285390196844 +508 4.4331363000655974 16.660340816209025 -22.109019006581338 +509 4.4418629463255686 16.853517350200086 -22.16350042379833 +510 4.4505895925855405 17.047161962642026 -22.21629400464857 +511 4.4593162388455125 17.241259906747857 -22.267395728696485 +512 4.468042885105484 17.43579640120764 -22.31680170434792 +513 4.476769531365456 17.630756631314185 -22.36450816914656 +514 4.485496177625427 17.826125750091098 -22.410511490060408 +515 4.494222823885399 18.021888879423635 -22.454808163758468 +516 4.50294947014537 18.218031111191525 -22.497394816877527 +517 4.511676116405342 18.414537508404464 -22.538268206279078 +518 4.520402762665314 18.611393106339474 -22.57742521929627 +519 4.529129408925285 18.808582913680603 -22.614862873970953 +520 4.537856055185257 19.006091913660605 -22.650578319280786 +521 4.546582701445228 19.203905065204403 -22.68456883535632 +522 4.5553093477052 19.402007304074687 -22.71683183368817 +523 4.564035993965171 19.60038354401894 -22.747364857324087 +524 4.572762640225143 19.799018677918486 -22.776165581056116 +525 4.581489286485115 19.997897578938815 -22.80323181159764 +526 4.590215932745086 20.197005101681594 -22.828561487750402 +527 4.598942579005058 20.39632608333814 -22.852152680561513 +528 4.607669225265029 20.595845344843955 -22.874003593470285 +529 4.616395871525002 20.79554769203486 -22.894112562445113 +530 4.625122517784973 20.99541791680386 -22.912478056110146 +531 4.633849164044945 21.195440798259572 -22.929098675861944 +532 4.642575810304916 21.39560110388511 -22.943973155975957 +533 4.651302456564888 21.595883590698293 -22.95710036370294 +534 4.66002910282486 21.796273006412303 -22.9684792993552 +535 4.6687557490848315 21.99675409059727 -22.978109096382727 +536 4.6774823953448035 22.19731157584248 -22.9859890214392 +537 4.686209041604775 22.39793018891891 -22.992118474437817 +538 4.694935687864747 22.59859465194248 -22.996496988597 +539 4.703662334124718 22.79928968353739 -22.99912423047594 +540 4.71238898038469 22.999999999999996 -23.0 +541 4.721115626644662 23.200710316462605 -22.99912423047594 +542 4.729842272904633 23.401405348057512 -22.996496988597 +543 4.738568919164605 23.60206981108108 -22.992118474437817 +544 4.747295565424576 23.802688424157513 -22.9859890214392 +545 4.756022211684548 24.00324590940272 -22.978109096382727 +546 4.764748857944519 24.20372699358769 -22.9684792993552 +547 4.773475504204491 24.404116409301697 -22.957100363702946 +548 4.782202150464463 24.60439889611488 -22.943973155975957 +549 4.790928796724434 24.80455920174042 -22.929098675861944 +550 4.799655442984406 25.004582083196134 -22.912478056110146 +551 4.808382089244377 25.204452307965134 -22.894112562445113 +552 4.81710873550435 25.40415465515604 -22.874003593470285 +553 4.825835381764321 25.603673916661855 -22.852152680561513 +554 4.834562028024293 25.802994898318396 -22.828561487750402 +555 4.843288674284264 26.00210242106118 -22.80323181159764 +556 4.852015320544236 26.200981322081503 -22.77616558105612 +557 4.860741966804208 26.39961645598105 -22.747364857324087 +558 4.869468613064179 26.597992695925306 -22.71683183368817 +559 4.878195259324151 26.79609493479559 -22.68456883535632 +560 4.886921905584122 26.993908086339392 -22.650578319280786 +561 4.895648551844094 27.191417086319394 -22.614862873970953 +562 4.9043751981040655 27.388606893660516 -22.57742521929627 +563 4.9131018443640375 27.585462491595532 -22.538268206279085 +564 4.9218284906240095 27.781968888808468 -22.49739481687753 +565 4.930555136883981 27.978111120576354 -22.454808163758468 +566 4.939281783143953 28.17387424990889 -22.410511490060408 +567 4.948008429403924 28.36924336868581 -22.364508169146568 +568 4.956735075663896 28.56420359879235 -22.31680170434792 +569 4.965461721923867 28.758740093252133 -22.267395728696485 +570 4.974188368183839 28.952838037357967 -22.21629400464857 +571 4.982915014443811 29.146482649799907 -22.16350042379833 +572 4.991641660703782 29.339659183790964 -22.109019006581338 +573 5.000368306963754 29.532352928190214 -22.052853901968444 +574 5.009094953223726 29.724549208622946 -21.995009387149818 +575 5.017821599483698 29.91623338859829 -21.935489867209217 +576 5.026548245743669 30.107390870623785 -21.874299874788534 +577 5.035274892003641 30.29800709731712 -21.811444069742585 +578 5.044001538263612 30.488067552514593 -21.74692723878429 +579 5.052728184523584 30.67755776237673 -21.680754295120103 +580 5.061454830783556 30.866463296490384 -21.612930278075893 +581 5.070181477043527 31.05476976896775 -21.543460352713147 +582 5.078908123303499 31.24246283954191 -21.47234980943564 +583 5.08763476956347 31.429528214658827 -21.39960406358657 +584 5.096361415823442 31.615951648565975 -21.32522865503611 +585 5.105088062083414 31.80171894439707 -21.249229247759594 +586 5.113814708343385 31.98681595525329 -21.17161162940613 +587 5.122541354603357 32.171228585280666 -21.092381710857854 +588 5.1312680008633285 32.354942790743394 -21.011545525779827 +589 5.1399946471233005 32.53794458109349 -20.929109230160496 +590 5.148721293383272 32.72022002003607 -20.845079101842956 +591 5.1574479396432436 32.90175522659078 -20.759461540046797 +592 5.1661745859032155 33.08253637614878 -20.67226306488084 +593 5.174901232163187 33.26254970152559 -20.583490316846582 +594 5.183627878423159 33.441781494009575 -20.49315005633246 +595 5.19235452468313 33.620218104405765 -20.401249163099106 +596 5.201081170943102 33.797845944075476 -20.30779463575532 +597 5.209807817203074 33.974651485970995 -20.212793591225203 +598 5.218534463463046 34.150621265665755 -20.1162532642061 +599 5.227261109723017 34.32574188237974 -20.0181810066177 +600 5.235987755982989 34.5 -19.918584287042087 +601 5.244714402242961 34.673382348096204 -19.81747069015509 +602 5.253441048502932 34.84587572293125 -19.71484791614858 +603 5.262167694762904 35.017466988466836 -19.61072378014412 +604 5.270894341022875 35.188143077363705 -19.5051062115978 +605 5.279620987282847 35.35789099197695 -19.398003253696373 +606 5.288347633542818 35.52669780534561 -19.28942306274476 +607 5.29707427980279 35.694550662177335 -19.179373907544868 +608 5.305800926062762 35.86143677982718 -19.067864168765958 +609 5.314527572322733 36.02734344927114 -18.954902338306365 +610 5.323254218582705 36.19225803607406 -18.840497018646808 +611 5.331980864842676 36.356167981351604 -18.724656922195347 +612 5.340707511102648 36.51906080272688 -18.607390870623792 +613 5.349434157362619 36.68092409528084 -18.488707794196007 +614 5.358160803622591 36.84174553249711 -18.368616731087737 +615 5.366887449882563 37.00151286720057 -18.24712682669841 +616 5.3756140961425345 37.16021393249013 -18.124247332954614 +617 5.3843407424025065 37.31783664266524 -17.999987607605522 +618 5.393067388662478 37.474368994146246 -17.874357113510342 +619 5.4017940349224505 37.62979906638858 -17.747365417917553 +620 5.410520681182422 37.7841150227904 -17.619022191736498 +621 5.419247327442394 37.93730511159423 -17.48933720880071 +622 5.427973973702365 38.08935766678166 -17.35832034512376 +623 5.436700619962337 38.24026110896197 -17.225981578147046 +624 5.445427266222309 38.39000394625374 -17.092330985980063 +625 5.45415391248228 38.538574775160185 -16.957378746632855 +626 5.462880558742252 38.68596228143747 -16.82113513724092 +627 5.471607205002223 38.83215524095633 -16.683610533282618 +628 5.480333851262195 38.97714252055694 -16.544815407788978 +629 5.489060497522166 39.12091307889656 -16.404760330546186 +630 5.497787143782138 39.26345596729059 -16.263455967290593 +631 5.50651379004211 39.40476033054618 -16.120913078896567 +632 5.515240436302081 39.54481540778897 -15.977142520556944 +633 5.523967082562053 39.68361053328261 -15.832155240956343 +634 5.532693728822024 39.821135137240915 -15.685962281437476 +635 5.541420375081996 39.95737874663285 -15.53857477516019 +636 5.550147021341967 40.092330985980055 -15.390003946253753 +637 5.558873667601939 40.22598157814704 -15.24026110896197 +638 5.567600313861911 40.35832034512375 -15.08935766678167 +639 5.576326960121882 40.489337208800706 -14.937305111594235 +640 5.585053606381854 40.61902219173649 -14.784115022790408 +641 5.593780252641825 40.74736541791755 -14.629799066388586 +642 5.602506898901798 40.874357113510335 -14.474368994146252 +643 5.611233545161769 40.99998760760552 -14.317836642665249 +644 5.619960191421741 41.1242473329546 -14.160213932490137 +645 5.6286868376817125 41.247126826698405 -14.00151286720058 +646 5.6374134839416845 41.368616731087734 -13.84174553249711 +647 5.6461401302016565 41.488707794196 -13.680924095280842 +648 5.654866776461628 41.60739087062379 -13.519060802726885 +649 5.6635934227216 41.724656922195344 -13.356167981351609 +650 5.672320068981571 41.8404970186468 -13.192258036074069 +651 5.681046715241543 41.954902338306354 -13.027343449271157 +652 5.689773361501514 42.06786416876595 -12.861436779827187 +653 5.698500007761486 42.179373907544864 -12.694550662177342 +654 5.707226654021458 42.28942306274475 -12.52669780534562 +655 5.715953300281429 42.39800325369636 -12.357890991976957 +656 5.724679946541401 42.50510621159779 -12.188143077363716 +657 5.733406592801372 42.61072378014411 -12.01746698846684 +658 5.742133239061344 42.71484791614858 -11.845875722931254 +659 5.750859885321315 42.81747069015508 -11.673382348096215 +660 5.759586531581287 42.91858428704208 -11.50000000000001 +661 5.768313177841259 43.018181006617695 -11.325741882379747 +662 5.77703982410123 43.116253264206094 -11.150621265665766 +663 5.785766470361202 43.2127935912252 -10.974651485971002 +664 5.794493116621174 43.30779463575532 -10.797845944075487 +665 5.803219762881146 43.4012491630991 -10.620218104405774 +666 5.811946409141117 43.49315005633246 -10.44178149400958 +667 5.820673055401089 43.58349031684658 -10.262549701525602 +668 5.82939970166106 43.67226306488084 -10.082536376148791 +669 5.838126347921032 43.75946154004679 -9.90175522659079 +670 5.846852994181004 43.84507910184295 -9.720220020036084 +671 5.8555796404409755 43.92910923016049 -9.537944581093505 +672 5.8643062867009474 44.011545525779816 -9.354942790743404 +673 5.8730329329609186 44.09238171085785 -9.171228585280675 +674 5.8817595792208905 44.17161162940613 -8.986815955253299 +675 5.890486225480862 44.24922924775959 -8.801718944397077 +676 5.899212871740834 44.32522865503611 -8.615951648565984 +677 5.907939518000806 44.39960406358656 -8.429528214658838 +678 5.916666164260777 44.472349809435634 -8.242462839541917 +679 5.925392810520749 44.54346035271315 -8.054769768967757 +680 5.93411945678072 44.612930278075886 -7.866463296490398 +681 5.942846103040692 44.680754295120096 -7.67755776237674 +682 5.951572749300664 44.74692723878429 -7.488067552514604 +683 5.960299395560635 44.811444069742585 -7.298007097317133 +684 5.969026041820607 44.87429987478853 -7.107390870623795 +685 5.977752688080578 44.93548986720921 -6.916233388598299 +686 5.98647933434055 44.99500938714981 -6.724549208622957 +687 5.995205980600522 45.05285390196844 -6.532352928190221 +688 6.003932626860494 45.109019006581335 -6.339659183790975 +689 6.012659273120465 45.163500423798325 -6.146482649799914 +690 6.021385919380437 45.21629400464857 -5.952838037357978 +691 6.030112565640409 45.267395728696485 -5.758740093252144 +692 6.03883921190038 45.31680170434792 -5.564203598792361 +693 6.047565858160352 45.36450816914657 -5.36924336868582 +694 6.056292504420323 45.410511490060415 -5.173874249908903 +695 6.065019150680295 45.454808163758464 -4.978111120576366 +696 6.073745796940266 45.49739481687753 -4.781968888808477 +697 6.082472443200238 45.538268206279085 -4.585462491595539 +698 6.09119908946021 45.57742521929627 -4.388606893660526 +699 6.0999257357201815 45.61486287397096 -4.1914170863194 +700 6.1086523819801535 45.65057831928079 -3.9939080863393994 +701 6.117379028240125 45.684568835356316 -3.7960949347956 +702 6.126105674500097 45.71683183368817 -3.597992695925317 +703 6.134832320760068 45.74736485732409 -3.3996164559810604 +704 6.14355896702004 45.77616558105612 -3.2009813220815153 +705 6.152285613280012 45.80323181159764 -3.002102421061189 +706 6.161012259539983 45.828561487750406 -2.8029948983184063 +707 6.169738905799955 45.85215268056152 -2.6036739166618608 +708 6.178465552059926 45.87400359347028 -2.404154655156049 +709 6.187192198319899 45.894112562445116 -2.2044523079651444 +710 6.19591884457987 45.91247805611015 -2.0045820831961425 +711 6.204645490839842 45.929098675861944 -1.8045592017404282 +712 6.213372137099813 45.943973155975954 -1.6043988961148898 +713 6.222098783359785 45.95710036370294 -1.4041164093017087 +714 6.230825429619757 45.968479299355195 -1.2037269935877009 +715 6.239552075879728 45.97810909638273 -1.0032459094027328 +716 6.2482787221397 45.985989021439195 -0.8026884241575185 +717 6.257005368399671 45.99211847443782 -0.6020698110810915 +718 6.265732014659643 45.996496988597 -0.4014053480575209 +719 6.274458660919614 45.999124230475935 -0.20071031646261453 + +HARMONIC_5 +N 720 RADIANS + +0 0.0 0.0 -0.0 +1 0.008726646259971648 0.006510825464412062 -1.4920860535487603 +2 0.017453292519943295 0.02603883966309506 -2.9831495058477806 +3 0.02617993877991494 0.058570659070575015 -4.472168456487151 +4 0.03490658503988659 0.10408398800281804 -5.958122406256236 +5 0.04363323129985824 0.16254763389760063 -7.439992956542959 +6 0.05235987755982988 0.23392152869238025 -8.916764507293145 +7 0.061086523819801536 0.3181567562848644 -10.387424953052388 +8 0.06981317007977318 0.415195586057694 -11.850966376612265 +9 0.07853981633974483 0.5249715124441391 -13.306385739786627 +10 0.08726646259971647 0.6474093005076936 -14.752685570843681 +11 0.09599310885968812 0.7824250375043362 -16.188874648123605 +12 0.10471975511965977 0.929926190392085 -17.61396867937201 +13 0.11344640137963141 1.0898116692486035 -19.026990976324935 +14 0.12217304763960307 1.2619718965531606 -20.42697312408211 +15 0.1308996938995747 1.4462888822855477 -21.81295564481012 +16 0.13962634015954636 1.6426363047905794 -23.183988655320608 +17 0.148352986419518 1.8508795973526482 -24.53913251807283 +18 0.15707963267948966 2.070876040421012 -25.877458485154182 +19 0.16580627893946132 2.30247485942266 -27.198049334797663 +20 0.17453292519943295 2.5455173280956602 -28.5 +21 0.1832595714594046 2.799836877272244 -29.78241818880909 +22 0.19198621771937624 3.065259209036937 -31.044424995856556 +23 0.20071286397934787 3.3416024161816975 -32.28515550471548 +24 0.20943951023931953 3.628677106875996 -33.503759380670985 +25 0.2181661564992912 3.92628653446653 -34.699401453497074 +26 0.22689280275926282 4.234226732317545 -35.87126228984072 +27 0.23561944901923448 4.552286653599402 -37.018538754820476 +28 0.24434609527920614 4.880248315929518 -38.14044456245493 +29 0.2530727415391778 5.217886950766533 -39.23621081454401 +30 0.2617993877991494 5.5649711574556004 -40.30508652763321 +31 0.27052603405912107 5.921263061818676 -41.3463391477004 +32 0.2792526803190927 6.286518479181689 -42.35925505221146 +33 0.28797932657906433 6.660487081726511 -43.343140039201764 +34 0.296705972839036 7.042912570053088 -44.29731980304736 +35 0.30543261909900765 7.43353284883431 -45.221140396600426 +36 0.3141592653589793 7.832080206443008 -46.11396867937202 +37 0.32288591161895097 8.238281498428181 -46.97519275145486 +38 0.33161255787892263 8.651858334714479 -47.804222372889186 +39 0.3403392041388943 9.072527270396964 -48.60048936818326 +40 0.3490658503988659 9.499999999999996 -49.363448015713004 +41 0.35779249665883756 9.933983555067444 -50.09257542173202 +42 0.3665191429188092 10.374180504948619 -50.78737187873696 +43 0.3752457891787809 10.820289160642394 -51.44736120794205 +44 0.3839724354387525 11.272003781559789 -52.072091085628244 +45 0.39269908169872414 11.729014785063297 -52.661133353143356 +46 0.40142572795869574 12.191008958639282 -53.2140843103405 +47 0.41015237421866746 12.657669674558354 -53.73056499225416 +48 0.41887902047863906 13.128677106876003 -54.21022142882373 +49 0.42760566673861067 13.60370845062547 -54.652724887486976 +50 0.4363323129985824 14.08243814305211 -55.057772098476896 +51 0.445058959258554 14.564538086737787 -55.425085462667575 +52 0.45378560551852565 15.049677874462569 -55.75441324182693 +53 0.4625122517784973 15.537525015649193 -56.04552973114542 +54 0.47123889803846897 16.02774516423561 -56.29823541392285 +55 0.4799655442984406 16.520002347819023 -56.5123570983072 +56 0.4886921905584123 17.01395919791458 -56.68774803599159 +57 0.4974188368183839 17.509277181170944 -56.8242880227883 +58 0.5061454830783556 18.00561683138407 -56.9218834810107 +59 0.5148721293383272 18.502637982150404 -56.980467523606755 +60 0.5235987755982988 18.999999999999993 -57.0 +61 0.5323254218582705 19.497362017849582 -56.980467523606755 +62 0.5410520681182421 19.99438316861594 -56.9218834810107 +63 0.5497787143782138 20.490722818829056 -56.824288022788316 +64 0.5585053606381855 20.98604080208542 -56.68774803599158 +65 0.5672320068981571 21.479997652180987 -56.512357098307206 +66 0.5759586531581287 21.972254835764378 -56.298235413922846 +67 0.5846852994181004 22.462474984350806 -56.04552973114542 +68 0.593411945678072 22.950322125537433 -55.75441324182692 +69 0.6021385919380438 23.43546191326221 -55.42508546266756 +70 0.6108652381980153 23.91756185694789 -55.0577720984769 +71 0.619591884457987 24.39629154937453 -54.652724887487004 +72 0.6283185307179586 24.871322893124002 -54.21022142882376 +73 0.6370451769779303 25.342330325441647 -53.73056499225416 +74 0.6457718232379019 25.808991041360706 -53.21408431034048 +75 0.6544984694978736 26.270985214936708 -52.66113335314334 +76 0.6632251157578453 26.727996218440204 -52.07209108562825 +77 0.6719517620178168 27.17971083935761 -51.44736120794204 +78 0.6806784082777886 27.625819495051392 -50.78737187873697 +79 0.6894050545377601 28.066016444932558 -50.092575421732015 +80 0.6981317007977318 28.5 -49.363448015713004 +81 0.7068583470577035 28.92747272960303 -48.600489368183254 +82 0.7155849933176751 29.348141665285514 -47.804222372889186 +83 0.7243116395776468 29.761718501571824 -46.9751927514549 +84 0.7330382858376184 30.167919793556994 -46.11396867937201 +85 0.74176493209759 30.56646715116569 -45.22114039660041 +86 0.7504915783575618 30.957087429946917 -44.29731980304733 +87 0.7592182246175333 31.339512918273492 -43.343140039201764 +88 0.767944870877505 31.713481520818306 -42.35925505221146 +89 0.7766715171374766 32.07873693818132 -41.34633914770038 +90 0.7853981633974483 32.435028842544405 -40.305086527633215 +91 0.7941248096574199 32.78211304923346 -39.23621081454397 +92 0.8028514559173915 33.119751684070486 -38.14044456245491 +93 0.8115781021773633 33.44771334640059 -37.018538754820476 +94 0.8203047484373349 33.76577326768245 -35.87126228984075 +95 0.8290313946973066 34.073713465533466 -34.699401453497096 +96 0.8377580409572781 34.371322893123995 -33.503759380671 +97 0.8464846872172498 34.658397583818285 -32.2851555047155 +98 0.8552113334772213 34.93474079096305 -31.044424995856545 +99 0.8639379797371932 35.200163122727766 -29.782418188809064 +100 0.8726646259971648 35.45448267190434 -28.500000000000025 +101 0.8813912722571364 35.69752514057734 -27.198049334797666 +102 0.890117918517108 35.92912395957899 -25.877458485154172 +103 0.8988445647770796 36.149120402647355 -24.539132518072854 +104 0.9075712110370513 36.357363695209415 -23.18398865532062 +105 0.9162978572970231 36.55371111771445 -21.8129556448101 +106 0.9250245035569946 36.73802810344684 -20.426973124082153 +107 0.9337511498169663 36.91018833075138 -19.026990976324942 +108 0.9424777960769379 37.07007380960792 -17.613968679372 +109 0.9512044423369095 37.21757496249566 -16.188874648123598 +110 0.9599310885968813 37.3525906994923 -14.752685570843665 +111 0.9686577348568529 37.47502848755586 -13.30638573978659 +112 0.9773843811168246 37.58480441394231 -11.850966376612277 +113 0.9861110273767961 37.681843243715136 -10.3874249530524 +114 0.9948376736367678 37.76607847130762 -8.916764507293173 +115 1.0035643198967394 37.8374523661024 -7.4399929565429685 +116 1.0122909661567112 37.895916011997194 -5.958122406256257 +117 1.0210176124166828 37.94142934092944 -4.472168456487164 +118 1.0297442586766543 37.9739611603369 -2.9831495058478152 +119 1.038470904936626 37.99348917453559 -1.4920860535487916 +120 1.0471975511965976 37.99999999999999 -6.328271240363392e-15 +121 1.0559241974565694 37.99348917453558 1.4920860535487601 +122 1.064650843716541 37.9739611603369 2.983149505847755 +123 1.0733774899765127 37.94142934092943 4.472168456487155 +124 1.0821041362364843 37.895916011997194 5.95812240625626 +125 1.0908307824964558 37.8374523661024 7.439992956542908 +126 1.0995574287564276 37.766078471307615 8.916764507293164 +127 1.1082840750163994 37.681843243715136 10.387424953052426 +128 1.117010721276371 37.58480441394231 11.850966376612291 +129 1.1257373675363425 37.47502848755585 13.306385739786583 +130 1.1344640137963142 37.3525906994923 14.752685570843688 +131 1.1431906600562858 37.21757496249566 16.188874648123573 +132 1.1519173063162573 37.07007380960792 17.613968679371972 +133 1.160643952576229 36.91018833075139 19.026990976324946 +134 1.1693705988362009 36.73802810344684 20.426973124082156 +135 1.1780972450961724 36.55371111771445 21.812955644810103 +136 1.186823891356144 36.35736369520942 23.183988655320608 +137 1.1955505376161157 36.149120402647355 24.53913251807282 +138 1.2042771838760875 35.92912395957898 25.87745848515419 +139 1.213003830136059 35.69752514057734 27.198049334797666 +140 1.2217304763960306 35.454482671904344 28.499999999999993 +141 1.2304571226560024 35.20016312272775 29.782418188809107 +142 1.239183768915974 34.934740790963055 31.04442499585653 +143 1.2479104151759455 34.6583975838183 32.28515550471546 +144 1.2566370614359172 34.371322893124 33.50375938067097 +145 1.265363707695889 34.073713465533466 34.69940145349708 +146 1.2740903539558606 33.76577326768245 35.871262289840736 +147 1.2828170002158321 33.4477133464006 37.01853875482045 +148 1.2915436464758039 33.119751684070486 38.14044456245494 +149 1.3002702927357754 32.782113049233466 39.23621081454397 +150 1.3089969389957472 32.435028842544405 40.305086527633215 +151 1.3177235852557188 32.07873693818133 41.34633914770039 +152 1.3264502315156905 31.713481520818302 42.35925505221147 +153 1.335176877775662 31.3395129182735 43.34314003920175 +154 1.3439035240356336 30.957087429946913 44.29731980304732 +155 1.3526301702956054 30.566467151165693 45.22114039660041 +156 1.3613568165555772 30.167919793556987 46.11396867937202 +157 1.3700834628155487 29.761718501571828 46.975192751454905 +158 1.3788101090755203 29.348141665285517 47.80422237288917 +159 1.3875367553354918 28.92747272960304 48.600489368183226 +160 1.3962634015954636 28.500000000000007 49.363448015713004 +161 1.4049900478554354 28.066016444932558 50.092575421732036 +162 1.413716694115407 27.625819495051395 50.78737187873696 +163 1.4224433403753785 27.17971083935762 51.447361207942045 +164 1.4311699866353502 26.727996218440204 52.07209108562826 +165 1.4398966328953218 26.27098521493672 52.661133353143356 +166 1.4486232791552935 25.808991041360706 53.21408431034052 +167 1.457349925415265 25.342330325441655 53.73056499225417 +168 1.4660765716752369 24.871322893124002 54.21022142882374 +169 1.4748032179352084 24.396291549374535 54.65272488748699 +170 1.48352986419518 23.917561856947902 55.05777209847689 +171 1.4922565104551517 23.43546191326221 55.42508546266758 +172 1.5009831567151235 22.95032212553742 55.75441324182692 +173 1.509709802975095 22.462474984350813 56.04552973114541 +174 1.5184364492350666 21.972254835764392 56.298235413922846 +175 1.5271630954950384 21.479997652180984 56.512357098307184 +176 1.53588974175501 20.986040802085427 56.68774803599157 +177 1.5446163880149815 20.490722818829063 56.824288022788295 +178 1.5533430342749532 19.99438316861594 56.92188348101071 +179 1.562069680534925 19.49736201784959 56.98046752360676 +180 1.5707963267948966 19.0 57.0 +181 1.579522973054868 18.502637982150418 56.98046752360676 +182 1.5882496193148399 18.005616831384067 56.92188348101071 +183 1.5969762655748114 17.509277181170955 56.824288022788295 +184 1.605702911834783 17.0139591979146 56.68774803599157 +185 1.6144295580947547 16.520002347819023 56.51235709830721 +186 1.6231562043547265 16.02774516423561 56.298235413922846 +187 1.6318828506146983 15.53752501564919 56.04552973114541 +188 1.6406094968746698 15.049677874462574 55.75441324182692 +189 1.6493361431346414 14.564538086737803 55.425085462667596 +190 1.6580627893946132 14.082438143052102 55.057772098476896 +191 1.6667894356545847 13.60370845062547 54.65272488748701 +192 1.6755160819145563 13.128677106876012 54.21022142882375 +193 1.684242728174528 12.657669674558354 53.730564992254195 +194 1.6929693744344996 12.191008958639303 53.214084310340525 +195 1.7016960206944711 11.729014785063306 52.66113335314337 +196 1.7104226669544427 11.272003781559807 52.07209108562828 +197 1.7191493132144147 10.82028916064239 51.44736120794205 +198 1.7278759594743864 10.3741805049486 50.787371878736955 +199 1.736602605734358 9.933983555067439 50.09257542173203 +200 1.7453292519943295 9.5 49.36344801571302 +201 1.7540558982543013 9.072527270396973 48.60048936818325 +202 1.7627825445142729 8.651858334714483 47.80422237288917 +203 1.7715091907742444 8.238281498428183 46.97519275145491 +204 1.780235837034216 7.832080206443017 46.11396867937202 +205 1.7889624832941877 7.433532848834307 45.22114039660041 +206 1.7976891295541593 7.042912570053092 44.297319803047365 +207 1.8064157758141308 6.660487081726523 43.34314003920181 +208 1.8151424220741026 6.286518479181698 42.35925505221147 +209 1.8238690683340746 5.921263061818669 41.346339147700355 +210 1.8325957145940461 5.56497115745559 40.30508652763321 +211 1.8413223608540177 5.2178869507665375 39.23621081454397 +212 1.8500490071139892 4.880248315929514 38.14044456245494 +213 1.858775653373961 4.552286653599414 37.01853875482047 +214 1.8675022996339325 4.234226732317555 35.87126228984075 +215 1.876228945893904 3.926286534466536 34.69940145349708 +216 1.8849555921538759 3.6286771068760006 33.503759380670985 +217 1.8936822384138474 3.3416024161817104 32.28515550471549 +218 1.902408884673819 3.0652592090369453 31.04442499585658 +219 1.9111355309337907 2.7998368772722464 29.782418188809107 +220 1.9198621771937625 2.545517328095671 28.500000000000014 +221 1.9285888234537343 2.30247485942266 27.198049334797666 +222 1.9373154697137058 2.070876040421008 25.877458485154165 +223 1.9460421159736774 1.8508795973526502 24.53913251807284 +224 1.9547687622336491 1.6426363047905814 23.18398865532062 +225 1.9634954084936207 1.446288882285552 21.812955644810113 +226 1.9722220547535922 1.2619718965531648 20.426973124082156 +227 1.980948701013564 1.089811669248612 19.026990976324946 +228 1.9896753472735356 0.9299261903920935 17.613968679372025 +229 1.9984019935335071 0.7824250375043404 16.188874648123623 +230 2.007128639793479 0.6474093005077042 14.752685570843717 +231 2.015855286053451 0.5249715124441412 13.306385739786565 +232 2.0245819323134224 0.4151955860576919 11.850966376612254 +233 2.033308578573394 0.3181567562848644 10.387424953052395 +234 2.0420352248333655 0.23392152869238236 8.916764507293164 +235 2.050761871093337 0.16254763389760696 7.439992956542993 +236 2.0594885173533086 0.10408398800280749 5.958122406256298 +237 2.0682151636132806 0.05857065907056658 4.472168456487155 +238 2.076941809873252 0.026038839663103497 2.9831495058478055 +239 2.0856684561332237 0.006510825464414172 1.4920860535487885 +240 2.0943951023931953 -4.218847493575595e-15 4.746203430272544e-14 +241 2.103121748653167 0.006510825464405734 -1.4920860535486842 +242 2.111848394913139 0.026038839663101387 -2.983149505847796 +243 2.1205750411731104 0.05857065907056236 -4.472168456487164 +244 2.129301687433082 0.10408398800281171 -5.958122406256223 +245 2.138028333693054 0.16254763389759852 -7.4399929565429685 +246 2.1467549799530254 0.23392152869238236 -8.916764507293156 +247 2.155481626212997 0.3181567562848644 -10.3874249530524 +248 2.1642082724729685 0.4151955860576919 -11.850966376612277 +249 2.17293491873294 0.524971512444137 -13.306385739786535 +250 2.1816615649929116 0.6474093005077021 -14.752685570843635 +251 2.1903882112528836 0.7824250375043257 -16.188874648123583 +252 2.199114857512855 0.9299261903920829 -17.613968679371986 +253 2.2078415037728267 1.08981166924861 -19.026990976324914 +254 2.2165681500327987 1.2619718965531668 -20.426973124082135 +255 2.2252947962927703 1.446288882285552 -21.8129556448101 +256 2.234021442552742 1.6426363047905814 -23.18398865532062 +257 2.2427480888127134 1.8508795973526437 -24.539132518072815 +258 2.251474735072685 2.0708760404210036 -25.87745848515415 +259 2.260201381332657 2.3024748594226683 -27.198049334797687 +260 2.2689280275926285 2.5455173280956647 -28.500000000000025 +261 2.2776546738526 2.7998368772722424 -29.782418188809057 +262 2.2863813201125716 3.065259209036937 -31.0444249958565 +263 2.295107966372543 3.3416024161816953 -32.28515550471543 +264 2.3038346126325147 3.6286771068759878 -33.503759380670914 +265 2.3125612588924866 3.92628653446653 -34.699401453497096 +266 2.321287905152458 4.234226732317542 -35.871262289840715 +267 2.33001455141243 4.552286653599419 -37.018538754820476 +268 2.3387411976724017 4.880248315929514 -38.14044456245494 +269 2.3474678439323733 5.217886950766541 -39.23621081454397 +270 2.356194490192345 5.564971157455594 -40.305086527633215 +271 2.3649211364523164 5.921263061818663 -41.34633914770037 +272 2.373647782712288 6.286518479181683 -42.359255052211445 +273 2.3823744289722595 6.660487081726489 -43.343140039201714 +274 2.3911010752322315 7.042912570053083 -44.29731980304733 +275 2.399827721492203 7.433532848834301 -45.221140396600376 +276 2.408554367752175 7.832080206443023 -46.11396867937202 +277 2.4172810140121466 8.238281498428181 -46.97519275145488 +278 2.426007660272118 8.651858334714486 -47.80422237288917 +279 2.4347343065320897 9.072527270396957 -48.60048936818324 +280 2.443460952792061 9.499999999999991 -49.36344801571299 +281 2.4521875990520328 9.933983555067424 -50.092575421732015 +282 2.4609142453120048 10.374180504948615 -50.78737187873697 +283 2.4696408915719763 10.82028916064238 -51.44736120794204 +284 2.478367537831948 11.272003781559789 -52.072091085628244 +285 2.4870941840919194 11.729014785063281 -52.66113335314334 +286 2.495820830351891 12.19100895863928 -53.21408431034047 +287 2.504547476611863 12.657669674558353 -53.73056499225416 +288 2.5132741228718345 13.128677106875985 -54.21022142882376 +289 2.522000769131806 13.603708450625465 -54.65272488748699 +290 2.530727415391778 14.08243814305211 -55.0577720984769 +291 2.5394540616517496 14.5645380867378 -55.42508546266757 +292 2.548180707911721 15.049677874462558 -55.75441324182691 +293 2.5569073541716927 15.537525015649193 -56.04552973114542 +294 2.5656340004316642 16.02774516423559 -56.298235413922846 +295 2.574360646691636 16.520002347819002 -56.51235709830719 +296 2.5830872929516078 17.013959197914588 -56.687748035991575 +297 2.5918139392115793 17.509277181170944 -56.824288022788316 +298 2.600540585471551 18.00561683138406 -56.9218834810107 +299 2.609267231731523 18.50263798215042 -56.980467523606755 +300 2.6179938779914944 18.999999999999996 -56.999999999999986 +301 2.626720524251466 19.49736201784959 -56.98046752360675 +302 2.6354471705114375 19.99438316861592 -56.9218834810107 +303 2.644173816771409 20.49072281882904 -56.824288022788274 +304 2.652900463031381 20.98604080208542 -56.68774803599159 +305 2.6616271092913526 21.47999765218098 -56.51235709830719 +306 2.670353755551324 21.97225483576439 -56.29823541392285 +307 2.6790804018112957 22.462474984350784 -56.04552973114541 +308 2.6878070480712672 22.950322125537408 -55.754413241826924 +309 2.696533694331239 23.435461913262177 -55.42508546266756 +310 2.705260340591211 23.91756185694789 -55.057772098476896 +311 2.7139869868511823 24.396291549374514 -54.652724887487004 +312 2.7227136331111543 24.871322893124002 -54.21022142882374 +313 2.731440279371126 25.342330325441647 -53.73056499225416 +314 2.7401669256310974 25.808991041360702 -53.2140843103405 +315 2.748893571891069 26.2709852149367 -52.661133353143356 +316 2.7576202181510405 26.7279962184402 -52.07209108562829 +317 2.766346864411012 27.179710839357597 -51.44736120794207 +318 2.7750735106709836 27.625819495051363 -50.787371878737005 +319 2.7838001569309556 28.066016444932558 -50.09257542173202 +320 2.792526803190927 28.499999999999986 -49.36344801571302 +321 2.801253449450899 28.92747272960303 -48.60048936818324 +322 2.8099800957108707 29.34814166528552 -47.804222372889164 +323 2.8187067419708423 29.76171850157182 -46.97519275145486 +324 2.827433388230814 30.167919793556987 -46.113968679372014 +325 2.8361600344907854 30.56646715116569 -45.221140396600426 +326 2.844886680750757 30.9570874299469 -44.29731980304736 +327 2.853613327010729 31.33951291827349 -43.343140039201764 +328 2.8623399732707004 31.71348152081831 -42.35925505221146 +329 2.871066619530672 32.078736938181315 -41.346339147700434 +330 2.8797932657906435 32.435028842544384 -40.30508652763322 +331 2.888519912050615 32.78211304923345 -39.23621081454402 +332 2.897246558310587 33.119751684070486 -38.14044456245494 +333 2.9059732045705586 33.44771334640059 -37.0185387548205 +334 2.91469985083053 33.76577326768244 -35.871262289840786 +335 2.923426497090502 34.07371346553347 -34.699401453497074 +336 2.9321531433504737 34.371322893124 -33.503759380670985 +337 2.9408797896104453 34.65839758381829 -32.28515550471547 +338 2.949606435870417 34.934740790963055 -31.044424995856577 +339 2.9583330821303884 35.200163122727744 -29.78241818880912 +340 2.96705972839036 35.45448267190432 -28.500000000000064 +341 2.975786374650332 35.69752514057734 -27.198049334797663 +342 2.9845130209103035 35.92912395957898 -25.877458485154182 +343 2.993239667170275 36.14912040264735 -24.53913251807287 +344 3.001966313430247 36.35736369520942 -23.183988655320608 +345 3.0106929596902186 36.55371111771444 -21.812955644810117 +346 3.01941960595019 36.73802810344682 -20.426973124082142 +347 3.0281462522101616 36.910188330751396 -19.02699097632497 +348 3.036872898470133 37.07007380960791 -17.61396867937205 +349 3.045599544730105 37.217574962495675 -16.188874648123573 +350 3.0543261909900767 37.3525906994923 -14.752685570843681 +351 3.0630528372500483 37.47502848755585 -13.306385739786627 +352 3.07177948351002 37.5848044139423 -11.850966376612341 +353 3.0805061297699914 37.68184324371513 -10.387424953052465 +354 3.089232776029963 37.76607847130761 -8.916764507293214 +355 3.097959422289935 37.8374523661024 -7.439992956542961 +356 3.1066860685499065 37.895916011997194 -5.958122406256279 +357 3.1154127148098785 37.94142934092943 -4.472168456487114 +358 3.12413936106985 37.973961160336906 -2.9831495058477806 +359 3.1328660073298216 37.9934891745356 -1.4920860535487606 +360 3.141592653589793 38.0 -3.7969627442180354e-14 +361 3.1503192998497647 37.9934891745356 1.4920860535487415 +362 3.159045946109736 37.973961160336906 2.9831495058477424 +363 3.1677725923697078 37.94142934092943 4.472168456487095 +364 3.1764992386296798 37.895916011997194 5.958122406256241 +365 3.1852258848896513 37.8374523661024 7.439992956542923 +366 3.193952531149623 37.76607847130761 8.916764507293102 +367 3.2026791774095944 37.68184324371514 10.387424953052331 +368 3.211405823669566 37.58480441394232 11.850966376612213 +369 3.2201324699295375 37.47502848755587 13.306385739786519 +370 3.2288591161895095 37.3525906994923 14.752685570843644 +371 3.237585762449481 37.217574962495675 16.188874648123534 +372 3.246312408709453 37.07007380960791 17.61396867937201 +373 3.255039054969425 36.910188330751396 19.02699097632501 +374 3.2637657012293966 36.73802810344682 20.42697312408216 +375 3.272492347489368 36.55371111771444 21.812955644810156 +376 3.2812189937493397 36.35736369520941 23.18398865532062 +377 3.2899456400093112 36.149120402647355 24.53913251807283 +378 3.2986722862692828 35.929123959578995 25.877458485154147 +379 3.3073989325292543 35.69752514057734 27.19804933479764 +380 3.3161255787892263 35.45448267190433 28.500000000000025 +381 3.324852225049198 35.200163122727744 29.78241818880909 +382 3.3335788713091694 34.93474079096306 31.044424995856538 +383 3.342305517569141 34.65839758381831 32.285155504715455 +384 3.3510321638291125 34.37132289312402 33.50375938067094 +385 3.359758810089084 34.07371346553349 34.699401453497025 +386 3.368485456349056 33.76577326768244 35.87126228984072 +387 3.3772121026090276 33.44771334640059 37.01853875482045 +388 3.385938748868999 33.1197516840705 38.14044456245489 +389 3.3946653951289707 32.78211304923348 39.23621081454393 +390 3.4033920413889422 32.43502884254442 40.305086527633144 +391 3.412118687648914 32.07873693818135 41.34633914770035 +392 3.4208453339088853 31.71348152081833 42.35925505221141 +393 3.4295719801688573 31.339512918273503 43.34314003920174 +394 3.4382986264288293 30.95708742994691 44.29731980304736 +395 3.447025272688801 30.566467151165696 45.22114039660039 +396 3.455751918948773 30.167919793556976 46.11396867937202 +397 3.4644785652087444 29.761718501571814 46.97519275145493 +398 3.473205211468716 29.348141665285514 47.804222372889164 +399 3.4819318577286875 28.92747272960303 48.60048936818326 +400 3.490658503988659 28.500000000000004 49.363448015713004 +401 3.4993851502486306 28.06601644493257 50.09257542173199 +402 3.5081117965086026 27.62581949505138 50.78737187873699 +403 3.516838442768574 27.179710839357604 51.44736120794205 +404 3.5255650890285457 26.72799621844021 52.072091085628244 +405 3.5342917352885173 26.270985214936715 52.66113335314334 +406 3.543018381548489 25.80899104136071 53.214084310340496 +407 3.5517450278084604 25.342330325441658 53.730564992254145 +408 3.560471674068432 24.871322893124027 54.21022142882373 +409 3.569198320328404 24.396291549374524 54.65272488748699 +410 3.5779249665883754 23.917561856947902 55.05777209847688 +411 3.586651612848347 23.435461913262223 55.42508546266754 +412 3.5953782591083185 22.950322125537447 55.75441324182689 +413 3.60410490536829 22.462474984350827 56.04552973114539 +414 3.6128315516282616 21.972254835764414 56.29823541392282 +415 3.6215581978882336 21.479997652180998 56.51235709830719 +416 3.630284844148205 20.98604080208543 56.687748035991554 +417 3.639011490408177 20.49072281882906 56.82428802278828 +418 3.647738136668149 19.994383168615915 56.92188348101071 +419 3.6564647829281207 19.497362017849575 56.98046752360676 +420 3.6651914291880923 18.999999999999993 57.0 +421 3.673918075448064 18.502637982150407 56.98046752360676 +422 3.6826447217080354 18.00561683138407 56.92188348101071 +423 3.691371367968007 17.50927718117096 56.82428802278828 +424 3.7000980142279785 17.01395919791459 56.68774803599157 +425 3.7088246604879505 16.520002347819013 56.512357098307184 +426 3.717551306747922 16.027745164235615 56.29823541392285 +427 3.7262779530078936 15.5375250156492 56.04552973114541 +428 3.735004599267865 15.04967787446258 55.754413241826924 +429 3.7437312455278366 14.564538086737812 55.42508546266756 +430 3.752457891787808 14.082438143052123 55.057772098476896 +431 3.76118453804778 13.603708450625465 54.65272488748699 +432 3.7699111843077517 13.128677106876005 54.21022142882375 +433 3.7786378305677233 12.657669674558363 53.730564992254166 +434 3.787364476827695 12.191008958639312 53.2140843103405 +435 3.7960911230876664 11.72901478506332 52.66113335314334 +436 3.804817769347638 11.272003781559823 52.07209108562826 +437 3.8135444156076095 10.820289160642425 51.447361207942116 +438 3.8222710618675815 10.37418050494863 50.78737187873697 +439 3.8309977081275535 9.933983555067435 50.092575421732015 +440 3.839724354387525 9.500000000000004 49.363448015713 +441 3.848451000647497 9.072527270396956 48.60048936818322 +442 3.8571776469074686 8.651858334714477 47.804222372889136 +443 3.86590429316744 8.238281498428174 46.975192751454884 +444 3.8746309394274117 7.832080206443008 46.11396867937201 +445 3.883357585687383 7.433532848834316 45.221140396600426 +446 3.8920842319473548 7.042912570053096 44.29731980304733 +447 3.9008108782073267 6.660487081726508 43.34314003920174 +448 3.9095375244672983 6.286518479181689 42.35925505221146 +449 3.91826417072727 5.921263061818676 41.34633914770038 +450 3.9269908169872414 5.5649711574556004 40.305086527633215 +451 3.935717463247213 5.21788695076655 39.236210814543995 +452 3.9444441095071845 4.880248315929524 38.140444562454974 +453 3.953170755767156 4.552286653599431 37.01853875482053 +454 3.961897402027128 4.234226732317555 35.87126228984075 +455 3.9706240482870996 3.9262865344665423 34.699401453497096 +456 3.979350694547071 3.628677106876011 33.50375938067101 +457 3.9880773408070427 3.3416024161817184 32.28515550471551 +458 3.9968039870670142 3.06525920903696 31.044424995856602 +459 4.005530633326986 2.7998368772722655 29.78241818880915 +460 4.014257279586958 2.545517328095671 28.500000000000025 +461 4.022983925846929 2.3024748594226874 27.19804933479779 +462 4.031710572106902 2.0708760404210036 25.877458485154097 +463 4.040437218366873 1.8508795973526522 24.53913251807284 +464 4.049163864626845 1.6426363047905814 23.183988655320576 +465 4.057890510886816 1.4462888822855604 21.81295564481017 +466 4.066617157146788 1.261971896553169 20.426973124082114 +467 4.07534380340676 1.0898116692486055 19.026990976324896 +468 4.084070449666731 0.929926190392085 17.613968679372025 +469 4.092797095926703 0.7824250375043278 16.188874648123548 +470 4.101523742186674 0.6474093005077105 14.752685570843724 +471 4.110250388446646 0.5249715124441433 13.30638573978659 +472 4.118977034706617 0.41519558605770035 11.850966376612366 +473 4.127703680966589 0.3181567562848623 10.387424953052445 +474 4.136430327226561 0.23392152869238447 8.91676450729314 +475 4.145156973486532 0.16254763389760907 7.439992956543022 +476 4.153883619746504 0.10408398800280749 5.9581224062562415 +477 4.162610266006475 0.058570659070575015 4.472168456487284 +478 4.171336912266447 0.026038839663099278 2.983149505847856 +479 4.1800635585264185 0.006510825464416281 1.492086053548912 +480 4.1887902047863905 4.218847493575595e-15 6.961098364399732e-14 +481 4.1975168510463625 0.006510825464414172 -1.4920860535487472 +482 4.206243497306334 0.02603883966308873 -2.9831495058476825 +483 4.214970143566306 0.05857065907056658 -4.472168456487126 +484 4.223696789826278 0.10408398800280327 -5.95812240625626 +485 4.23242343608625 0.16254763389761118 -7.439992956543012 +486 4.241150082346221 0.23392152869238236 -8.91676450729314 +487 4.249876728606193 0.3181567562848644 -10.387424953052426 +488 4.258603374866164 0.4151955860576919 -11.850966376612229 +489 4.267330021126136 0.5249715124441539 -13.306385739786606 +490 4.276056667386108 0.6474093005077126 -14.75268557084374 +491 4.284783313646079 0.7824250375043278 -16.188874648123548 +492 4.293509959906051 0.929926190392085 -17.613968679372004 +493 4.302236606166022 1.0898116692486055 -19.02699097632487 +494 4.310963252425994 1.2619718965531648 -20.426973124082096 +495 4.319689898685965 1.4462888822855435 -21.812955644810025 +496 4.328416544945937 1.642636304790571 -23.18398865532059 +497 4.337143191205909 1.8508795973526502 -24.53913251807284 +498 4.34586983746588 2.070876040420999 -25.87745848515411 +499 4.354596483725852 2.302474859422656 -27.198049334797663 +500 4.363323129985823 2.5455173280956456 -28.499999999999915 +501 4.372049776245795 2.799836877272236 -29.78241818880902 +502 4.380776422505767 3.0652592090369453 -31.04442499585653 +503 4.389503068765738 3.341602416181689 -32.2851555047154 +504 4.39822971502571 3.62867710687599 -33.50375938067096 +505 4.4069563612856815 3.9262865344665148 -34.699401453496975 +506 4.4156830075456535 4.234226732317538 -35.87126228984067 +507 4.4244096538056255 4.552286653599414 -37.01853875482047 +508 4.4331363000655974 4.8802483159295225 -38.140444562454974 +509 4.4418629463255686 5.217886950766524 -39.23621081454396 +510 4.4505895925855405 5.564971157455602 -40.30508652763322 +511 4.4593162388455125 5.9212630618186886 -41.346339147700455 +512 4.468042885105484 6.286518479181689 -42.359255052211466 +513 4.476769531365456 6.660487081726528 -43.343140039201785 +514 4.485496177625427 7.042912570053074 -44.2973198030473 +515 4.494222823885399 7.433532848834307 -45.22114039660041 +516 4.50294947014537 7.8320802064429875 -46.113968679371936 +517 4.511676116405342 8.238281498428176 -46.97519275145486 +518 4.520402762665314 8.651858334714497 -47.80422237288918 +519 4.529129408925285 9.07252727039696 -48.600489368183226 +520 4.537856055185257 9.5 -49.36344801571302 +521 4.546582701445228 9.933983555067417 -50.092575421731986 +522 4.5553093477052 10.3741805049486 -50.787371878736955 +523 4.564035993965171 10.820289160642355 -51.44736120794202 +524 4.572762640225143 11.272003781559773 -52.07209108562822 +525 4.581489286485115 11.729014785063294 -52.661133353143356 +526 4.590215932745086 12.191008958639264 -53.21408431034045 +527 4.598942579005058 12.657669674558337 -53.73056499225417 +528 4.607669225265029 13.12867710687596 -54.2102214288237 +529 4.616395871525002 13.603708450625495 -54.65272488748703 +530 4.625122517784973 14.082438143052102 -55.057772098476896 +531 4.633849164044945 14.56453808673781 -55.425085462667596 +532 4.642575810304916 15.049677874462555 -55.75441324182691 +533 4.651302456564888 15.537525015649203 -56.04552973114541 +534 4.66002910282486 16.027745164235636 -56.29823541392285 +535 4.6687557490848315 16.520002347819013 -56.512357098307184 +536 4.6774823953448035 17.013959197914595 -56.68774803599157 +537 4.686209041604775 17.509277181170923 -56.824288022788295 +538 4.694935687864747 18.005616831384067 -56.92188348101071 +539 4.703662334124718 18.502637982150382 -56.98046752360676 +540 4.71238898038469 18.999999999999986 -57.0 +541 4.721115626644662 19.497362017849596 -56.98046752360676 +542 4.729842272904633 19.994383168615915 -56.92188348101071 +543 4.738568919164605 20.490722818829052 -56.824288022788295 +544 4.747295565424576 20.986040802085387 -56.687748035991575 +545 4.756022211684548 21.47999765218096 -56.51235709830719 +546 4.764748857944519 21.972254835764343 -56.29823541392286 +547 4.773475504204491 22.462474984350774 -56.04552973114545 +548 4.782202150464463 22.95032212553742 -55.75441324182692 +549 4.790928796724434 23.43546191326217 -55.4250854626676 +550 4.799655442984406 23.91756185694788 -55.057772098476896 +551 4.808382089244377 24.396291549374485 -54.65272488748704 +552 4.81710873550435 24.871322893124027 -54.210221428823715 +553 4.825835381764321 25.342330325441647 -53.730564992254195 +554 4.834562028024293 25.808991041360713 -53.21408431034047 +555 4.843288674284264 26.270985214936694 -52.66113335314337 +556 4.852015320544236 26.727996218440204 -52.07209108562826 +557 4.860741966804208 27.17971083935762 -51.447361207942045 +558 4.869468613064179 27.62581949505138 -50.78737187873697 +559 4.878195259324151 28.06601644493257 -50.092575421732015 +560 4.886921905584122 28.499999999999986 -49.36344801571303 +561 4.895648551844094 28.92747272960303 -48.60048936818324 +562 4.9043751981040655 29.34814166528548 -47.804222372889214 +563 4.9131018443640375 29.761718501571814 -46.97519275145491 +564 4.9218284906240095 30.167919793556994 -46.11396867937201 +565 4.930555136883981 30.566467151165668 -45.221140396600454 +566 4.939281783143953 30.9570874299469 -44.29731980304733 +567 4.948008429403924 31.339512918273467 -43.34314003920183 +568 4.956735075663896 31.71348152081829 -42.359255052211495 +569 4.965461721923867 32.078736938181294 -41.34633914770049 +570 4.974188368183839 32.435028842544384 -40.30508652763325 +571 4.982915014443811 32.78211304923346 -39.23621081454397 +572 4.991641660703782 33.11975168407046 -38.140444562455 +573 5.000368306963754 33.44771334640058 -37.018538754820504 +574 5.009094953223726 33.76577326768245 -35.871262289840736 +575 5.017821599483698 34.07371346553348 -34.69940145349704 +576 5.026548245743669 34.371322893123995 -33.50375938067099 +577 5.035274892003641 34.6583975838183 -32.28515550471546 +578 5.044001538263612 34.93474079096304 -31.044424995856605 +579 5.052728184523584 35.200163122727744 -29.782418188809082 +580 5.061454830783556 35.454482671904344 -28.499999999999993 +581 5.070181477043527 35.69752514057733 -27.19804933479771 +582 5.078908123303499 35.929123959578995 -25.87745848515414 +583 5.08763476956347 36.14912040264735 -24.539132518072904 +584 5.096361415823442 36.357363695209415 -23.18398865532063 +585 5.105088062083414 36.55371111771445 -21.812955644810067 +586 5.113814708343385 36.73802810344684 -20.426973124082156 +587 5.122541354603357 36.91018833075139 -19.026990976324946 +588 5.1312680008633285 37.07007380960791 -17.613968679372093 +589 5.1399946471233005 37.21757496249566 -16.18887464812361 +590 5.148721293383272 37.35259069949229 -14.752685570843791 +591 5.1574479396432436 37.475028487555846 -13.30638573978667 +592 5.1661745859032155 37.58480441394231 -11.850966376612291 +593 5.174901232163187 37.68184324371513 -10.387424953052491 +594 5.183627878423159 37.766078471307615 -8.91676450729317 +595 5.19235452468313 37.83745236610239 -7.439992956543076 +596 5.201081170943102 37.89591601199719 -5.95812240625633 +597 5.209807817203074 37.94142934092943 -4.472168456487173 +598 5.218534463463046 37.9739611603369 -2.983149505847755 +599 5.227261109723017 37.99348917453559 -1.4920860535488485 +600 5.235987755982989 37.99999999999999 6.328271240363392e-15 +601 5.244714402242961 37.9934891745356 1.492086053548836 +602 5.253441048502932 37.9739611603369 2.983149505847796 +603 5.262167694762904 37.94142934092943 4.472168456487202 +604 5.270894341022875 37.89591601199719 5.958122406256194 +605 5.279620987282847 37.8374523661024 7.4399929565429685 +606 5.288347633542818 37.766078471307615 8.916764507293072 +607 5.29707427980279 37.681843243715136 10.3874249530524 +608 5.305800926062762 37.58480441394231 11.850966376612302 +609 5.314527572322733 37.47502848755586 13.306385739786547 +610 5.323254218582705 37.35259069949229 14.752685570843678 +611 5.331980864842676 37.217574962495675 16.188874648123505 +612 5.340707511102648 37.070073809607926 17.61396867937196 +613 5.349434157362619 36.9101883307514 19.026990976324807 +614 5.358160803622591 36.73802810344683 20.426973124082057 +615 5.366887449882563 36.55371111771444 21.81295564481008 +616 5.3756140961425345 36.35736369520943 23.183988655320487 +617 5.3843407424025065 36.149120402647355 24.53913251807278 +618 5.393067388662478 35.929123959579 25.877458485154047 +619 5.4017940349224505 35.69752514057733 27.198049334797766 +620 5.410520681182422 35.45448267190434 28.499999999999986 +621 5.419247327442394 35.200163122727744 29.782418188809125 +622 5.427973973702365 34.93474079096306 31.044424995856488 +623 5.436700619962337 34.658397583818285 32.2851555047155 +624 5.445427266222309 34.37132289312399 33.50375938067101 +625 5.45415391248228 34.07371346553348 34.69940145349705 +626 5.462880558742252 33.76577326768244 35.87126228984075 +627 5.471607205002223 33.4477133464006 37.01853875482042 +628 5.480333851262195 33.11975168407049 38.14044456245491 +629 5.489060497522166 32.78211304923349 39.23621081454388 +630 5.497787143782138 32.435028842544405 40.30508652763319 +631 5.50651379004211 32.078736938181315 41.346339147700434 +632 5.515240436302081 31.713481520818323 42.359255052211424 +633 5.523967082562053 31.339512918273492 43.34314003920174 +634 5.532693728822024 30.957087429946938 44.29731980304728 +635 5.541420375081996 30.566467151165703 45.221140396600376 +636 5.550147021341967 30.167919793557026 46.1139686793719 +637 5.558873667601939 29.76171850157185 46.97519275145485 +638 5.567600313861911 29.34814166528552 47.804222372889136 +639 5.576326960121882 28.927472729603057 48.60048936818322 +640 5.585053606381854 28.500000000000007 49.36344801571299 +641 5.593780252641825 28.0660164449326 50.09257542173198 +642 5.602506898901798 27.625819495051363 50.78737187873699 +643 5.611233545161769 27.17971083935761 51.44736120794204 +644 5.619960191421741 26.7279962184402 52.07209108562825 +645 5.6286868376817125 26.270985214936722 52.66113335314332 +646 5.6374134839416845 25.808991041360706 53.21408431034048 +647 5.6461401302016565 25.342330325441623 53.7305649922542 +648 5.654866776461628 24.87132289312401 54.21022142882374 +649 5.6635934227216 24.396291549374517 54.652724887487 +650 5.672320068981571 23.917561856947923 55.057772098476846 +651 5.681046715241543 23.435461913262213 55.42508546266754 +652 5.689773361501514 22.950322125537454 55.754413241826896 +653 5.698500007761486 22.462474984350816 56.04552973114541 +654 5.707226654021458 21.972254835764378 56.298235413922846 +655 5.715953300281429 21.479997652181005 56.51235709830717 +656 5.724679946541401 20.98604080208542 56.68774803599157 +657 5.733406592801372 20.490722818829102 56.82428802278828 +658 5.742133239061344 19.99438316861595 56.9218834810107 +659 5.750859885321315 19.49736201784964 56.98046752360678 +660 5.759586531581287 19.00000000000003 57.0 +661 5.768313177841259 18.502637982150418 56.98046752360678 +662 5.77703982410123 18.00561683138411 56.92188348101071 +663 5.785766470361202 17.509277181170972 56.8242880227883 +664 5.794493116621174 17.01395919791458 56.68774803599159 +665 5.803219762881146 16.520002347819005 56.51235709830719 +666 5.811946409141117 16.027745164235622 56.29823541392285 +667 5.820673055401089 15.537525015649193 56.04552973114542 +668 5.82939970166106 15.049677874462601 55.754413241826924 +669 5.838126347921032 14.564538086737805 55.42508546266756 +670 5.846852994181004 14.082438143052098 55.05777209847688 +671 5.8555796404409755 13.603708450625486 54.65272488748703 +672 5.8643062867009474 13.128677106875998 54.21022142882374 +673 5.8730329329609186 12.657669674558383 53.7305649922542 +674 5.8817595792208905 12.1910089586393 53.21408431034052 +675 5.890486225480862 11.729014785063333 52.66113335314337 +676 5.899212871740834 11.272003781559814 52.07209108562829 +677 5.907939518000806 10.820289160642394 51.44736120794205 +678 5.916666164260777 10.374180504948637 50.787371878737005 +679 5.925392810520749 9.933983555067451 50.092575421732064 +680 5.93411945678072 9.50000000000004 49.363448015713075 +681 5.942846103040692 9.072527270396998 48.60048936818327 +682 5.951572749300664 8.651858334714479 47.804222372889186 +683 5.960299395560635 8.238281498428206 46.97519275145497 +684 5.969026041820607 7.832080206443023 46.11396867937202 +685 5.977752688080578 7.4335328488343375 45.22114039660051 +686 5.98647933434055 7.042912570053117 44.297319803047394 +687 5.995205980600522 6.660487081726511 43.343140039201764 +688 6.003932626860494 6.286518479181683 42.359255052211424 +689 6.012659273120465 5.921263061818684 41.346339147700434 +690 6.021385919380437 5.5649711574556004 40.30508652763321 +691 6.030112565640409 5.217886950766516 39.23621081454393 +692 6.03883921190038 4.880248315929518 38.14044456245493 +693 6.047565858160352 4.5522866535994 37.01853875482045 +694 6.056292504420323 4.234226732317561 35.871262289840786 +695 6.065019150680295 3.92628653446653 34.699401453497074 +696 6.073745796940266 3.628677106876007 33.50375938067105 +697 6.082472443200238 3.3416024161816997 32.28515550471551 +698 6.09119908946021 3.0652592090369324 31.04442499585652 +699 6.0999257357201815 2.799836877272261 29.78241818880914 +700 6.1086523819801535 2.5455173280956624 28.500000000000014 +701 6.117379028240125 2.3024748594226727 27.198049334797776 +702 6.126105674500097 2.0708760404210143 25.877458485154218 +703 6.134832320760068 1.8508795973526586 24.53913251807294 +704 6.14355896702004 1.6426363047905856 23.183988655320686 +705 6.152285613280012 1.4462888822855477 21.81295564481014 +706 6.161012259539983 1.2619718965531712 20.42697312408222 +707 6.169738905799955 1.0898116692486077 19.02699097632499 +708 6.178465552059926 0.9299261903921019 17.61396867937214 +709 6.187192198319899 0.7824250375043278 16.188874648123534 +710 6.19591884457987 0.6474093005076978 14.75268557084372 +711 6.204645490839842 0.524971512444137 13.306385739786574 +712 6.213372137099813 0.41519558605769824 11.850966376612341 +713 6.222098783359785 0.3181567562848644 10.387424953052408 +714 6.230825429619757 0.2339215286923887 8.916764507293102 +715 6.239552075879728 0.16254763389760063 7.439992956542977 +716 6.2482787221397 0.10408398800281804 5.9581224062562175 +717 6.257005368399671 0.058570659070577125 4.4721684564872275 +718 6.265732014659643 0.02603883966309506 2.9831495058477993 +719 6.274458660919614 0.006510825464412062 1.4920860535488742 From b7296b6d0b456bb1f7520934b2c45a36cfbd3fb0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 23 Mar 2021 13:49:37 -0400 Subject: [PATCH 119/257] consolidate documentation for dihedral styles table and table/cut into one file --- doc/src/Commands_bond.rst | 2 +- doc/src/dihedral_style.rst | 2 +- doc/src/dihedral_table.rst | 89 ++++++++++--- doc/src/dihedral_table_cut.rst | 229 --------------------------------- 4 files changed, 72 insertions(+), 250 deletions(-) delete mode 100644 doc/src/dihedral_table_cut.rst diff --git a/doc/src/Commands_bond.rst b/doc/src/Commands_bond.rst index a826228219..70a021849d 100644 --- a/doc/src/Commands_bond.rst +++ b/doc/src/Commands_bond.rst @@ -126,7 +126,7 @@ OPT. * :doc:`quadratic (o) ` * :doc:`spherical ` * :doc:`table (o) ` - * :doc:`table/cut ` + * :doc:`table/cut ` .. _improper: diff --git a/doc/src/dihedral_style.rst b/doc/src/dihedral_style.rst index bf3cf4902a..4301824b40 100644 --- a/doc/src/dihedral_style.rst +++ b/doc/src/dihedral_style.rst @@ -113,7 +113,7 @@ more of (g,i,k,o,t) to indicate which accelerated styles exist. * :doc:`quadratic ` - dihedral with quadratic term in angle * :doc:`spherical ` - dihedral which includes angle terms to avoid singularities * :doc:`table ` - tabulated dihedral -* :doc:`table/cut ` - tabulated dihedral with analytic cutoff +* :doc:`table/cut ` - tabulated dihedral with analytic cutoff ---------- diff --git a/doc/src/dihedral_table.rst b/doc/src/dihedral_table.rst index ff3e61baee..f1b14065fd 100644 --- a/doc/src/dihedral_table.rst +++ b/doc/src/dihedral_table.rst @@ -1,19 +1,24 @@ .. index:: dihedral_style table .. index:: dihedral_style table/omp +.. index:: dihedral_style table/cut dihedral_style table command ============================ Accelerator Variants: *table/omp* +dihedral_style table/cut command +================================ + Syntax """""" .. code-block:: LAMMPS - dihedral_style table style Ntable + dihedral_style style interp Ntable -* style = *linear* or *spline* = method of interpolation +* style = *table* or *table/cut* +* interp = *linear* or *spline* = method of interpolation * Ntable = size of the internal lookup table Examples @@ -26,13 +31,21 @@ Examples dihedral_coeff 1 file.table DIH_TABLE1 dihedral_coeff 2 file.table DIH_TABLE2 + dihedral_style table/cut spline 400 + dihedral_style table/cut linear 1000 + dihedral_coeff 1 aat 1.0 177 180 file.table DIH_TABLE1 + dihedral_coeff 2 aat 0.5 170 180 file.table DIH_TABLE2 + Description """"""""""" -The *table* dihedral style creates interpolation tables of length -*Ntable* from dihedral potential and derivative values listed in a -file(s) as a function of the dihedral angle "phi". The files are read -by the :doc:`dihedral_coeff ` command. +The *table* and *table/cut* dihedral styles create interpolation tables +of length *Ntable* from dihedral potential and derivative values listed +in a file(s) as a function of the dihedral angle "phi". The files are +read by the :doc:`dihedral_coeff ` command. For +dihedral style *table/cut* additionally an analytic cutoff that is +quadratic in the bond-angle (theta) is applied in order to regularize +the dihedral interaction. The interpolation tables are created by fitting cubic splines to the file values and interpolating energy and derivative values at each of @@ -51,16 +64,53 @@ interpolated table. For a given dihedral angle (phi), the appropriate coefficients are chosen from this list, and a cubic polynomial is used to compute the energy and the derivative at this angle. -The following coefficients must be defined for each dihedral type via -the :doc:`dihedral_coeff ` command as in the example -above. +For dihedral style *table* the following coefficients must be defined +for each dihedral type via the :doc:`dihedral_coeff ` +command as in the example above. * filename * keyword -The filename specifies a file containing tabulated energy and -derivative values. The keyword specifies a section of the file. The -format of this file is described below. +The filename specifies a file containing tabulated energy and derivative +values. The keyword specifies which section of the file to read. The +format of this file is the same for both dihedral styles and described +below. + +For dihedral style *table/cut* the following coefficients must be +defined for each dihedral type via the :doc:`dihedral_coeff +` command as in the example above. + +* style (aat) +* cutoff prefactor +* cutoff angle1 +* cutoff angle2 +* filename +* keyword + +The cutoff dihedral style uses a tabulated dihedral interaction with a +cutoff function: + +.. math:: + + f(\theta) & = K \qquad\qquad\qquad\qquad\qquad\qquad \theta < \theta_1 \\ + f(\theta) & = K \left(1-\frac{(\theta - \theta_1)^2}{(\theta_2 - \theta_1)^2}\right) \qquad \theta_1 < \theta < \theta_2 + +The cutoff specifies an prefactor to the cutoff function. While this +value would ordinarily equal 1 there may be situations where the value +should change. + +The cutoff :math:`\theta_1` specifies the angle (in degrees) below which +the dihedral interaction is unmodified, i.e. the cutoff function is 1. + +The cutoff function is applied between :math:`\theta_1` and +:math:`\theta_2`, which is the angle at which the cutoff function drops +to zero. The value of zero effectively "turns off" the dihedral +interaction. + +The filename specifies a file containing tabulated energy and derivative +values. The keyword specifies which section of the file to read. The +format of this file is the same for both dihedral styles and described +below. ---------- @@ -182,18 +232,19 @@ that matches the specified keyword. Restart, fix_modify, output, run start/stop, minimize info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" -This dihedral style writes the settings for the "dihedral_style table" -command to :doc:`binary restart files `, so a dihedral_style -command does not need to specified in an input script that reads a -restart file. However, the coefficient information is not stored in -the restart file, since it is tabulated in the potential files. Thus, +These dihedral styles write the settings for the "dihedral_style table" +or "dihedral_style table/cut" command to :doc:`binary restart files +`, so a dihedral_style command does not need to specified in an +input script that reads a restart file. However, the coefficient +information loaded from the table file(s) is not stored in the restart +file, since it is tabulated in the potential files. Thus, suitable dihedral_coeff commands do need to be specified in the restart input -script. +script after reading the restart file. Restrictions """""""""""" -This dihedral style can only be used if LAMMPS was built with the +These dihedral styles can only be used if LAMMPS was built with the USER-MISC package. See the :doc:`Build package ` doc page for more info. diff --git a/doc/src/dihedral_table_cut.rst b/doc/src/dihedral_table_cut.rst deleted file mode 100644 index a29844da19..0000000000 --- a/doc/src/dihedral_table_cut.rst +++ /dev/null @@ -1,229 +0,0 @@ -.. index:: dihedral_style table/cut - -dihedral_style table/cut command -================================ - -Syntax -"""""" - -.. code-block:: LAMMPS - - dihedral_style table/cut style Ntable - -* style = *linear* or *spline* = method of interpolation -* Ntable = size of the internal lookup table - -Examples -"""""""" - -.. code-block:: LAMMPS - - dihedral_style table/cut spline 400 - dihedral_style table/cut linear 1000 - dihedral_coeff 1 aat 1.0 177 180 file.table DIH_TABLE1 - dihedral_coeff 2 aat 0.5 170 180 file.table DIH_TABLE2 - -Description -""""""""""" - -The *table/cut* dihedral style creates interpolation tables of length -*Ntable* from dihedral potential and derivative values listed in a -file(s) as a function of the dihedral angle "phi". In addition, an -analytic cutoff that is quadratic in the bond-angle (theta) is applied -in order to regularize the dihedral interaction. The dihedral table -files are read by the :doc:`dihedral_coeff ` command. - -The interpolation tables are created by fitting cubic splines to the -file values and interpolating energy and derivative values at each of -*Ntable* dihedral angles. During a simulation, these tables are used -to interpolate energy and force values on individual atoms as -needed. The interpolation is done in one of 2 styles: *linear* or -*spline*\ . - -For the *linear* style, the dihedral angle (phi) is used to find 2 -surrounding table values from which an energy or its derivative is -computed by linear interpolation. - -For the *spline* style, cubic spline coefficients are computed and -stored at each of the *Ntable* evenly-spaced values in the -interpolated table. For a given dihedral angle (phi), the appropriate -coefficients are chosen from this list, and a cubic polynomial is used -to compute the energy and the derivative at this angle. - -The following coefficients must be defined for each dihedral type via -the :doc:`dihedral_coeff ` command as in the example -above. - -* style (aat) -* cutoff prefactor -* cutoff angle1 -* cutoff angle2 -* filename -* keyword - -The cutoff dihedral style uses a tabulated dihedral interaction with a -cutoff function: - -.. math:: - - f(\theta) & = K \qquad\qquad\qquad\qquad\qquad\qquad \theta < \theta_1 \\ - f(\theta) & = K \left(1-\frac{(\theta - \theta_1)^2}{(\theta_2 - \theta_1)^2}\right) \qquad \theta_1 < \theta < \theta_2 - -The cutoff specifies an prefactor to the cutoff function. While this value -would ordinarily equal 1 there may be situations where the value should change. - -The cutoff :math:`\theta_1` specifies the angle (in degrees) below which the dihedral -interaction is unmodified, i.e. the cutoff function is 1. - -The cutoff function is applied between :math:`\theta_1` and :math:`\theta_2`, which is -the angle at which the cutoff function drops to zero. The value of zero effectively -"turns off" the dihedral interaction. - -The filename specifies a file containing tabulated energy and -derivative values. The keyword specifies a section of the file. The -format of this file is described below. - ----------- - -The format of a tabulated file is as follows (without the -parenthesized comments). It can begin with one or more comment -or blank lines. - -.. parsed-literal:: - - # Table of the potential and its negative derivative - - DIH_TABLE1 (keyword is the first text on line) - N 30 DEGREES (N, NOF, DEGREES, RADIANS, CHECKU/F) - (blank line) - 1 -168.0 -1.40351172223 0.0423346818422 - 2 -156.0 -1.70447981034 0.00811786522531 - 3 -144.0 -1.62956100432 -0.0184129719987 - ... - 30 180.0 -0.707106781187 0.0719306095245 - - # Example 2: table of the potential. Forces omitted - - DIH_TABLE2 - N 30 NOF CHECKU testU.dat CHECKF testF.dat - - 1 -168.0 -1.40351172223 - 2 -156.0 -1.70447981034 - 3 -144.0 -1.62956100432 - ... - 30 180.0 -0.707106781187 - -A section begins with a non-blank line whose first character is not a -"#"; blank lines or lines starting with "#" can be used as comments -between sections. The first line begins with a keyword which -identifies the section. The line can contain additional text, but the -initial text must match the argument specified in the -:doc:`dihedral_coeff ` command. The next line lists (in -any order) one or more parameters for the table. Each parameter is a -keyword followed by one or more numeric values. - -Following a blank line, the next N lines list the tabulated values. On -each line, the first value is the index from 1 to N, the second value is -the angle value, the third value is the energy (in energy units), and -the fourth is -dE/d(phi) also in energy units). The third term is the -energy of the 4-atom configuration for the specified angle. The fourth -term (when present) is the negative derivative of the energy with -respect to the angle (in degrees, or radians depending on whether the -user selected DEGREES or RADIANS). Thus the units of the last term -are still energy, not force. The dihedral angle values must increase -from one line to the next. - -Dihedral table splines are cyclic. There is no discontinuity at 180 -degrees (or at any other angle). Although in the examples above, the -angles range from -180 to 180 degrees, in general, the first angle in -the list can have any value (positive, zero, or negative). However -the *range* of angles represented in the table must be *strictly* less -than 360 degrees (2pi radians) to avoid angle overlap. (You may not -supply entries in the table for both 180 and -180, for example.) If -the user's table covers only a narrow range of dihedral angles, -strange numerical behavior can occur in the large remaining gap. - -**Parameters:** - -The parameter "N" is required and its value is the number of table -entries that follow. Note that this may be different than the N -specified in the :doc:`dihedral_style table ` command. -Let *Ntable* is the number of table entries requested dihedral_style -command, and let *Nfile* be the parameter following "N" in the -tabulated file ("30" in the sparse example above). What LAMMPS does -is a preliminary interpolation by creating splines using the *Nfile* -tabulated values as nodal points. It uses these to interpolate as -needed to generate energy and derivative values at *Ntable* different -points (which are evenly spaced over a 360 degree range, even if the -angles in the file are not). The resulting tables of length *Ntable* -are then used as described above, when computing energy and force for -individual dihedral angles and their atoms. This means that if you -want the interpolation tables of length *Ntable* to match exactly what -is in the tabulated file (with effectively nopreliminary -interpolation), you should set *Ntable* = *Nfile*\ . To insure the -nodal points in the user's file are aligned with the interpolated -table entries, the angles in the table should be integer multiples of -360/\ *Ntable* degrees, or 2\*PI/\ *Ntable* radians (depending on your -choice of angle units). - -The optional "NOF" keyword allows the user to omit the forces -(negative energy derivatives) from the table file (normally located in -the fourth column). In their place, forces will be calculated -automatically by differentiating the potential energy function -indicated by the third column of the table (using either linear or -spline interpolation). - -The optional "DEGREES" keyword allows the user to specify angles in -degrees instead of radians (default). - -The optional "RADIANS" keyword allows the user to specify angles in -radians instead of degrees. (Note: This changes the way the forces -are scaled in the fourth column of the data file.) - -The optional "CHECKU" keyword is followed by a filename. This allows -the user to save all of the *Ntable* different entries in the -interpolated energy table to a file to make sure that the interpolated -function agrees with the user's expectations. (Note: You can -temporarily increase the *Ntable* parameter to a high value for this -purpose. "\ *Ntable*\ " is explained above.) - -The optional "CHECKF" keyword is analogous to the "CHECKU" keyword. -It is followed by a filename, and it allows the user to check the -interpolated force table. This option is available even if the user -selected the "NOF" option. - -Note that one file can contain many sections, each with a tabulated -potential. LAMMPS reads the file section by section until it finds one -that matches the specified keyword. - -Restart, fix_modify, output, run start/stop, minimize info -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -This dihedral style writes the settings for the "dihedral_style table/cut" -command to :doc:`binary restart files `, so a dihedral_style -command does not need to specified in an input script that reads a -restart file. However, the coefficient information is not stored in -the restart file, since it is tabulated in the potential files. Thus, -dihedral_coeff commands do need to be specified in the restart input -script. - -Restrictions -"""""""""""" - -This dihedral style can only be used if LAMMPS was built with the -USER-MISC package. See the :doc:`Build package ` doc -page for more info. - -Related commands -"""""""""""""""" - -:doc:`dihedral_coeff `, :doc:`dihedral_style table ` - -Default -""""""" - -none - -.. _dihedralcut-Salerno: - -**(Salerno)** Salerno, Bernstein, J Chem Theory Comput, --, ---- (2018). From 08d4fec1429e197494a895446f18b20198b7c32f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 23 Mar 2021 14:38:54 -0400 Subject: [PATCH 120/257] add framework for testing the variable command --- unittest/commands/CMakeLists.txt | 4 + unittest/commands/test_variables.cpp | 185 +++++++++++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 unittest/commands/test_variables.cpp diff --git a/unittest/commands/CMakeLists.txt b/unittest/commands/CMakeLists.txt index ee0e89d7e9..b2b8a3b130 100644 --- a/unittest/commands/CMakeLists.txt +++ b/unittest/commands/CMakeLists.txt @@ -11,6 +11,10 @@ add_executable(test_groups test_groups.cpp) target_link_libraries(test_groups PRIVATE lammps GTest::GMock GTest::GTest) add_test(NAME Groups COMMAND test_groups WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_executable(test_variables test_variables.cpp) +target_link_libraries(test_variables PRIVATE lammps GTest::GMock GTest::GTest) +add_test(NAME Variables COMMAND test_variables WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + add_executable(test_kim_commands test_kim_commands.cpp) if(KIM_EXTRA_UNITTESTS) if(CURL_FOUND) diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp new file mode 100644 index 0000000000..32d4a7fa13 --- /dev/null +++ b/unittest/commands/test_variables.cpp @@ -0,0 +1,185 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://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 "lammps.h" + +#include "atom.h" +#include "domain.h" +#include "group.h" +#include "info.h" +#include "input.h" +#include "region.h" +#include "variable.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include +#include + +// whether to print verbose output (i.e. not capturing LAMMPS screen output). +bool verbose = false; + +#if defined(OMPI_MAJOR_VERSION) +const bool have_openmpi = true; +#else +const bool have_openmpi = false; +#endif + +using LAMMPS_NS::utils::split_words; + +namespace LAMMPS_NS { +using ::testing::ExitedWithCode; +using ::testing::MatchesRegex; +using ::testing::StrEq; + +#define TEST_FAILURE(errmsg, ...) \ + if (Info::has_exceptions()) { \ + ::testing::internal::CaptureStdout(); \ + ASSERT_ANY_THROW({__VA_ARGS__}); \ + auto mesg = ::testing::internal::GetCapturedStdout(); \ + if (verbose) std::cout << mesg; \ + ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ + } else { \ + if (!have_openmpi) { \ + ::testing::internal::CaptureStdout(); \ + ASSERT_DEATH({__VA_ARGS__}, ""); \ + auto mesg = ::testing::internal::GetCapturedStdout(); \ + if (verbose) std::cout << mesg; \ + ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ + } \ + } + +class VariableTest : public ::testing::Test { +protected: + LAMMPS *lmp; + Group *group; + Domain *domain; + Variable *variable; + + void SetUp() override + { + const char *args[] = {"VariableTest", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); + if (!verbose) ::testing::internal::CaptureStdout(); + lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + if (!verbose) ::testing::internal::GetCapturedStdout(); + group = lmp->group; + domain = lmp->domain; + variable = lmp->input->variable; + } + + void TearDown() override + { + if (!verbose) ::testing::internal::CaptureStdout(); + delete lmp; + if (!verbose) ::testing::internal::GetCapturedStdout(); + std::cout.flush(); + } + + void command(const std::string &cmd) { lmp->input->one(cmd); } + + void atomic_system() + { + if (!verbose) ::testing::internal::CaptureStdout(); + command("units real"); + command("lattice sc 1.0 origin 0.125 0.125 0.125"); + command("region box block -2 2 -2 2 -2 2"); + command("create_box 8 box"); + command("create_atoms 1 box"); + command("mass * 1.0"); + command("region left block -2.0 -1.0 INF INF INF INF"); + command("region right block 0.5 2.0 INF INF INF INF"); + command("region top block INF INF -2.0 -1.0 INF INF"); + command("set region left type 2"); + command("set region right type 3"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + void molecular_system() + { + if (!verbose) ::testing::internal::CaptureStdout(); + command("fix props all property/atom mol rmass q"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + atomic_system(); + if (!verbose) ::testing::internal::CaptureStdout(); + command("variable molid atom floor(id/4)+1"); + command("variable charge atom 2.0*sin(PI/32*id)"); + command("set atom * mol v_molid"); + command("set atom * charge v_charge"); + command("set type 1 mass 0.5"); + command("set type 2*4 mass 2.0"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } +}; + +TEST_F(VariableTest, NoBox) +{ + ASSERT_EQ(variable->nvar, 0); + if (!verbose) ::testing::internal::CaptureStdout(); + command("variable one index 1"); + command("variable two equal 2"); + command("variable three string three"); + command("variable four loop 4"); + command("variable five loop 100 pad"); + command("variable six world one"); + command("variable seven format two \"%5.2f\""); + command("variable eight getenv HOME"); + command("variable dummy index 0"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + ASSERT_EQ(variable->nvar, 9); + if (!verbose) ::testing::internal::CaptureStdout(); + command("variable dummy delete"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + ASSERT_EQ(variable->nvar, 8); + + TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable");); +} + +TEST_F(VariableTest, AtomicSystem) +{ + atomic_system(); + + if (!verbose) ::testing::internal::CaptureStdout(); + command("variable id atom id"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + ASSERT_EQ(variable->nvar, 1); +} +} // namespace LAMMPS_NS + +int main(int argc, char **argv) +{ + MPI_Init(&argc, &argv); + ::testing::InitGoogleMock(&argc, argv); + + if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + std::cout << "Warning: using OpenMPI without exceptions. " + "Death tests will be skipped\n"; + + // handle arguments passed via environment variable + if (const char *var = getenv("TEST_ARGS")) { + std::vector env = split_words(var); + for (auto arg : env) { + if (arg == "-v") { + verbose = true; + } + } + } + + if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; + + int rv = RUN_ALL_TESTS(); + MPI_Finalize(); + return rv; +} From 16c08516a7947c377ca550a734e8bbc36bc9117c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 23 Mar 2021 16:14:40 -0400 Subject: [PATCH 121/257] test definition of more different variable styles --- unittest/commands/test_variables.cpp | 86 ++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 18 deletions(-) diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 32d4a7fa13..85108da4da 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -75,8 +75,8 @@ protected: if (!verbose) ::testing::internal::CaptureStdout(); lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); if (!verbose) ::testing::internal::GetCapturedStdout(); - group = lmp->group; - domain = lmp->domain; + group = lmp->group; + domain = lmp->domain; variable = lmp->input->variable; } @@ -86,6 +86,8 @@ protected: delete lmp; if (!verbose) ::testing::internal::GetCapturedStdout(); std::cout.flush(); + unlink("test_variable.file"); + unlink("test_variable.atomfile"); } void command(const std::string &cmd) { lmp->input->one(cmd); } @@ -122,39 +124,87 @@ protected: command("set type 2*4 mass 2.0"); if (!verbose) ::testing::internal::GetCapturedStdout(); } + + void file_vars() + { + FILE *fp = fopen("test_variable.file", "w"); + fputs("# test file for file style variable\n\n\none\n two \n\n" + "three # with comment\nfour ! with non-comment\n" + "# comments only\n five\n#END\n", + fp); + fclose(fp); + fp = fopen("test_variable.atomfile", "w"); + + fputs("# test file for atomfile style variable\n\n" + "4 # four lines\n4 0.5 #with comment\n" + "2 -0.5 \n3 1.5\n1 -1.5\n\n" + "2\n10 1.0 # test\n13 1.0\n\n######\n" + "4\n1 4.0 # test\n2 3.0\n3 2.0\n4 1.0\n#END\n", + fp); + fclose(fp); + } }; -TEST_F(VariableTest, NoBox) +TEST_F(VariableTest, CreateDelete) { + file_vars(); ASSERT_EQ(variable->nvar, 0); if (!verbose) ::testing::internal::CaptureStdout(); - command("variable one index 1"); - command("variable two equal 2"); - command("variable three string three"); - command("variable four loop 4"); - command("variable five loop 100 pad"); - command("variable six world one"); - command("variable seven format two \"%5.2f\""); - command("variable eight getenv HOME"); - command("variable dummy index 0"); + command("variable one index 1 2 3 4"); + command("variable two equal 1"); + command("variable two equal 2"); + command("variable three string four"); + command("variable three string three"); + command("variable four1 loop 4"); + command("variable four2 loop 2 4"); + command("variable five1 loop 100 pad"); + command("variable five2 loop 100 200 pad"); + command("variable six world one"); + command("variable seven format two \"%5.2f\""); + command("variable eight getenv PWD"); + command("variable eight getenv HOME"); + command("variable nine file test_variable.file"); + command("variable dummy index 0"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 9); + ASSERT_EQ(variable->nvar, 12); if (!verbose) ::testing::internal::CaptureStdout(); - command("variable dummy delete"); + command("variable dummy delete"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 8); - + ASSERT_EQ(variable->nvar, 11); + TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable");); + TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy index");); + TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy delete xxx");); + TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", + command("variable two string xxx");); + TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", + command("variable two getenv xxx");); + TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", + command("variable one equal 2");); + TEST_FAILURE(".*ERROR: Cannot use atomfile-style variable unless an atom map exists.*", + command("variable ten atomfile test_variable.atomfile");); + TEST_FAILURE(".*ERROR on proc 0: Cannot open file variable file test_variable.xxx.*", + command("variable nine1 file test_variable.xxx");); } TEST_F(VariableTest, AtomicSystem) { + command("atom_modify map array"); atomic_system(); + file_vars(); if (!verbose) ::testing::internal::CaptureStdout(); - command("variable id atom id"); + command("variable one index 1 2 3 4"); + command("variable id atom type"); + command("variable id atom id"); + command("variable ten atomfile test_variable.atomfile"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 1); + ASSERT_EQ(variable->nvar, 3); + + TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", + command("variable one atom x");); + TEST_FAILURE(".*ERROR on proc 0: Cannot open file variable file test_variable.xxx.*", + command("variable ten1 atomfile test_variable.xxx");); } } // namespace LAMMPS_NS From 014f9ad527fa5231e0b7bc1b9b10118bbdbadcfa Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 23 Mar 2021 16:47:04 -0400 Subject: [PATCH 122/257] simplify Variable::parse_args() by using Tokenizer class --- src/variable.cpp | 33 +++++---------------------------- src/variable.h | 1 - 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/src/variable.cpp b/src/variable.cpp index 1af4a4728a..6766a67a9a 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -4708,42 +4708,19 @@ double Variable::constant(char *word) int Variable::parse_args(char *str, char **args) { - char *ptrnext; int narg = 0; - char *ptr = str; + Tokenizer values(str,","); - while (ptr && narg < MAXFUNCARG) { - ptrnext = find_next_comma(ptr); - if (ptrnext) *ptrnext = '\0'; - args[narg] = utils::strdup(ptr); + while (values.has_next() && narg < MAXFUNCARG) { + args[narg] = utils::strdup(values.next()); narg++; - ptr = ptrnext; - if (ptr) ptr++; } - if (ptr) error->all(FLERR,"Too many args in variable function"); + if (values.has_next()) + error->all(FLERR,"Too many args in variable function"); return narg; } - -/* ---------------------------------------------------------------------- - find next comma in str - skip commas inside one or more nested parenthesis - only return ptr to comma at level 0, else nullptr if not found -------------------------------------------------------------------------- */ - -char *Variable::find_next_comma(char *str) -{ - int level = 0; - for (char *p = str; *p; ++p) { - if ('(' == *p) level++; - else if (')' == *p) level--; - else if (',' == *p && !level) return p; - } - return nullptr; -} - - /* ---------------------------------------------------------------------- helper routine for printing variable name with error message ------------------------------------------------------------------------- */ diff --git a/src/variable.h b/src/variable.h index 2519bc7ac9..cb74e71b51 100644 --- a/src/variable.h +++ b/src/variable.h @@ -125,7 +125,6 @@ class Variable : protected Pointers { int is_constant(char *); double constant(char *); int parse_args(char *, char **); - char *find_next_comma(char *); void print_var_error(const std::string &, int, const std::string &, int, int global=1); void print_tree(Tree *, int); From 1ebb600829360140e3b0d72ffa08e1b938d56196 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 23 Mar 2021 16:47:40 -0400 Subject: [PATCH 123/257] add tests for expressions and functions --- unittest/commands/test_variables.cpp | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 85108da4da..5a77c75a6c 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -18,6 +18,7 @@ #include "group.h" #include "info.h" #include "input.h" +#include "math_const.h" #include "region.h" #include "variable.h" @@ -37,6 +38,7 @@ const bool have_openmpi = false; #endif using LAMMPS_NS::utils::split_words; +using LAMMPS_NS::MathConst::MY_PI; namespace LAMMPS_NS { using ::testing::ExitedWithCode; @@ -206,6 +208,40 @@ TEST_F(VariableTest, AtomicSystem) TEST_FAILURE(".*ERROR on proc 0: Cannot open file variable file test_variable.xxx.*", command("variable ten1 atomfile test_variable.xxx");); } + +TEST_F(VariableTest, Expressions) +{ + ASSERT_EQ(variable->nvar, 0); + if (!verbose) ::testing::internal::CaptureStdout(); + command("variable one index 1"); + command("variable two equal 2"); + command("variable three equal v_one+v_two"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + ASSERT_EQ(variable->nvar, 3); + + int ivar = variable->find("one"); + ASSERT_FALSE(variable->equalstyle(ivar)); + ivar = variable->find("two"); + ASSERT_TRUE(variable->equalstyle(ivar)); + ASSERT_DOUBLE_EQ(variable->compute_equal(ivar),2.0); + ivar = variable->find("three"); + ASSERT_DOUBLE_EQ(variable->compute_equal(ivar),3.0); +} + +TEST_F(VariableTest, Functions) +{ + file_vars(); + ASSERT_EQ(variable->nvar, 0); + if (!verbose) ::testing::internal::CaptureStdout(); + command("variable one index 1"); + command("variable two equal PI"); + command("variable three equal atan2(v_one,1)"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + ASSERT_EQ(variable->nvar, 3); + + int ivar = variable->find("three"); + ASSERT_DOUBLE_EQ(variable->compute_equal(ivar),0.25*MY_PI); +} } // namespace LAMMPS_NS int main(int argc, char **argv) From 1efd72eb58cd0b61a7d265847b0c908d06432300 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 23 Mar 2021 16:55:05 -0400 Subject: [PATCH 124/257] a couple more expressions and functions --- unittest/commands/test_variables.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 5a77c75a6c..8c0a24bc0d 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -215,9 +215,10 @@ TEST_F(VariableTest, Expressions) if (!verbose) ::testing::internal::CaptureStdout(); command("variable one index 1"); command("variable two equal 2"); - command("variable three equal v_one+v_two"); + command("variable three equal v_one+v_two"); + command("variable four equal PI"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 3); + ASSERT_EQ(variable->nvar, 4); int ivar = variable->find("one"); ASSERT_FALSE(variable->equalstyle(ivar)); @@ -226,6 +227,8 @@ TEST_F(VariableTest, Expressions) ASSERT_DOUBLE_EQ(variable->compute_equal(ivar),2.0); ivar = variable->find("three"); ASSERT_DOUBLE_EQ(variable->compute_equal(ivar),3.0); + ivar = variable->find("four"); + ASSERT_DOUBLE_EQ(variable->compute_equal(ivar),MY_PI); } TEST_F(VariableTest, Functions) @@ -234,12 +237,15 @@ TEST_F(VariableTest, Functions) ASSERT_EQ(variable->nvar, 0); if (!verbose) ::testing::internal::CaptureStdout(); command("variable one index 1"); - command("variable two equal PI"); + command("variable two equal random(1,2,643532)"); command("variable three equal atan2(v_one,1)"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(variable->nvar, 3); - int ivar = variable->find("three"); + int ivar = variable->find("two"); + ASSERT_GT(variable->compute_equal(ivar),0.99); + ASSERT_LT(variable->compute_equal(ivar),2.01); + ivar = variable->find("three"); ASSERT_DOUBLE_EQ(variable->compute_equal(ivar),0.25*MY_PI); } } // namespace LAMMPS_NS From 346c36e227d152f8bd22d88a83341fdeaaef8eef Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 23 Mar 2021 17:48:47 -0400 Subject: [PATCH 125/257] replace redundant functions to handle constants with (unordered) map --- src/variable.cpp | 60 ++++++++++------------------ src/variable.h | 2 - unittest/commands/test_variables.cpp | 12 +++++- 3 files changed, 32 insertions(+), 42 deletions(-) diff --git a/src/variable.cpp b/src/variable.cpp index 6766a67a9a..eb1deaae15 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include using namespace LAMMPS_NS; @@ -76,6 +77,20 @@ enum{SUM,XMIN,XMAX,AVE,TRAP,SLOPE}; #define BIG 1.0e20 +// constants for variable expressions. customize by adding new items. +// if needed (cf. 'version') initialize in Variable class constructor. + +static std::unordered_map constants = { + {"PI", MY_PI }, + {"version", -1 }, + {"yes", 1 }, + {"no", 0 }, + {"on", 1 }, + {"off", 0 }, + {"true", 1 }, + {"false", 0 } +}; + /* ---------------------------------------------------------------------- */ Variable::Variable(LAMMPS *lmp) : Pointers(lmp) @@ -98,6 +113,10 @@ Variable::Variable(LAMMPS *lmp) : Pointers(lmp) randomequal = nullptr; randomatom = nullptr; + // override initializer since LAMMPS class needs to be instantiated + + constants["version"] = lmp->num_ver; + // customize by assigning a precedence level precedence[DONE] = 0; @@ -2093,8 +2112,8 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) // constant // ---------------- - } else if (is_constant(word)) { - value1 = constant(word); + } else if (constants.find(word) != constants.end()) { + value1 = constants[word]; if (tree) { Tree *newtree = new Tree(); newtree->type = VALUE; @@ -4663,43 +4682,6 @@ void Variable::atom_vector(char *word, Tree **tree, } } -/* ---------------------------------------------------------------------- - check if word matches a constant - return 1 if yes, else 0 - customize by adding a constant: PI, version -------------------------------------------------------------------------- */ - -int Variable::is_constant(char *word) -{ - if (strcmp(word,"PI") == 0) return 1; - if (strcmp(word,"version") == 0) return 1; - if (strcmp(word,"yes") == 0) return 1; - if (strcmp(word,"no") == 0) return 1; - if (strcmp(word,"on") == 0) return 1; - if (strcmp(word,"off") == 0) return 1; - if (strcmp(word,"true") == 0) return 1; - if (strcmp(word,"false") == 0) return 1; - return 0; -} - -/* ---------------------------------------------------------------------- - process a constant in formula - customize by adding a constant: PI, version -------------------------------------------------------------------------- */ - -double Variable::constant(char *word) -{ - if (strcmp(word,"PI") == 0) return MY_PI; - if (strcmp(word,"version") == 0) return lmp->num_ver; - if (strcmp(word,"yes") == 0) return 1.0; - if (strcmp(word,"no") == 0) return 0.0; - if (strcmp(word,"on") == 0) return 1.0; - if (strcmp(word,"off") == 0) return 0.0; - if (strcmp(word,"true") == 0) return 1.0; - if (strcmp(word,"false") == 0) return 0.0; - return 0.0; -} - /* ---------------------------------------------------------------------- parse string for comma-separated args store copy of each arg in args array diff --git a/src/variable.h b/src/variable.h index cb74e71b51..5dc8748936 100644 --- a/src/variable.h +++ b/src/variable.h @@ -122,8 +122,6 @@ class Variable : protected Pointers { Tree **, Tree **, int &, double *, int &); int is_atom_vector(char *); void atom_vector(char *, Tree **, Tree **, int &); - int is_constant(char *); - double constant(char *); int parse_args(char *, char **); void print_var_error(const std::string &, int, const std::string &, int, int global=1); diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 8c0a24bc0d..cc20ea2b96 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -211,14 +211,17 @@ TEST_F(VariableTest, AtomicSystem) TEST_F(VariableTest, Expressions) { + atomic_system(); ASSERT_EQ(variable->nvar, 0); if (!verbose) ::testing::internal::CaptureStdout(); command("variable one index 1"); command("variable two equal 2"); command("variable three equal v_one+v_two"); command("variable four equal PI"); + command("variable five equal version"); + command("variable six equal XXX"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 4); + ASSERT_EQ(variable->nvar, 6); int ivar = variable->find("one"); ASSERT_FALSE(variable->equalstyle(ivar)); @@ -229,11 +232,18 @@ TEST_F(VariableTest, Expressions) ASSERT_DOUBLE_EQ(variable->compute_equal(ivar),3.0); ivar = variable->find("four"); ASSERT_DOUBLE_EQ(variable->compute_equal(ivar),MY_PI); + ivar = variable->find("five"); + ASSERT_GE(variable->compute_equal(ivar),20210310); + + TEST_FAILURE(".*ERROR: Variable six: Invalid thermo keyword 'XXX' in variable formula.*", + command("print \"${six}\"");); } TEST_F(VariableTest, Functions) { + atomic_system(); file_vars(); + ASSERT_EQ(variable->nvar, 0); if (!verbose) ::testing::internal::CaptureStdout(); command("variable one index 1"); From 4f46ee30a2dd19fa018fe3c61c6c41018ce6aee4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 23 Mar 2021 18:13:01 -0400 Subject: [PATCH 126/257] avoid crash when functions expecting an argument are used without --- src/variable.cpp | 7 ++++++- src/variable.h | 2 +- unittest/commands/test_variables.cpp | 21 ++++++++++++--------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/variable.cpp b/src/variable.cpp index eb1deaae15..9a8236fdb4 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -1234,6 +1234,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar) int i = 0; int expect = ARG; + if (str == nullptr) + print_var_error(FLERR,"Invalid syntax in variable formula",ivar); + while (1) { onechar = str[i]; @@ -4688,9 +4691,11 @@ void Variable::atom_vector(char *word, Tree **tree, max allowed # of args = MAXFUNCARG ------------------------------------------------------------------------- */ -int Variable::parse_args(char *str, char **args) +int Variable::parse_args(const std::string &str, char **args) { int narg = 0; + args[0] = nullptr; + Tokenizer values(str,","); while (values.has_next() && narg < MAXFUNCARG) { diff --git a/src/variable.h b/src/variable.h index 5dc8748936..50d276bb14 100644 --- a/src/variable.h +++ b/src/variable.h @@ -122,7 +122,7 @@ class Variable : protected Pointers { Tree **, Tree **, int &, double *, int &); int is_atom_vector(char *); void atom_vector(char *, Tree **, Tree **, int &); - int parse_args(char *, char **); + int parse_args(const std::string &, char **); void print_var_error(const std::string &, int, const std::string &, int, int global=1); void print_tree(Tree *, int); diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index cc20ea2b96..90a0fe00e7 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -37,8 +37,8 @@ const bool have_openmpi = true; const bool have_openmpi = false; #endif -using LAMMPS_NS::utils::split_words; using LAMMPS_NS::MathConst::MY_PI; +using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { using ::testing::ExitedWithCode; @@ -227,13 +227,13 @@ TEST_F(VariableTest, Expressions) ASSERT_FALSE(variable->equalstyle(ivar)); ivar = variable->find("two"); ASSERT_TRUE(variable->equalstyle(ivar)); - ASSERT_DOUBLE_EQ(variable->compute_equal(ivar),2.0); + ASSERT_DOUBLE_EQ(variable->compute_equal(ivar), 2.0); ivar = variable->find("three"); - ASSERT_DOUBLE_EQ(variable->compute_equal(ivar),3.0); + ASSERT_DOUBLE_EQ(variable->compute_equal(ivar), 3.0); ivar = variable->find("four"); - ASSERT_DOUBLE_EQ(variable->compute_equal(ivar),MY_PI); + ASSERT_DOUBLE_EQ(variable->compute_equal(ivar), MY_PI); ivar = variable->find("five"); - ASSERT_GE(variable->compute_equal(ivar),20210310); + ASSERT_GE(variable->compute_equal(ivar), 20210310); TEST_FAILURE(".*ERROR: Variable six: Invalid thermo keyword 'XXX' in variable formula.*", command("print \"${six}\"");); @@ -249,14 +249,17 @@ TEST_F(VariableTest, Functions) command("variable one index 1"); command("variable two equal random(1,2,643532)"); command("variable three equal atan2(v_one,1)"); + command("variable four equal atan2()"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 3); + ASSERT_EQ(variable->nvar, 4); int ivar = variable->find("two"); - ASSERT_GT(variable->compute_equal(ivar),0.99); - ASSERT_LT(variable->compute_equal(ivar),2.01); + ASSERT_GT(variable->compute_equal(ivar), 0.99); + ASSERT_LT(variable->compute_equal(ivar), 2.01); ivar = variable->find("three"); - ASSERT_DOUBLE_EQ(variable->compute_equal(ivar),0.25*MY_PI); + ASSERT_DOUBLE_EQ(variable->compute_equal(ivar), 0.25 * MY_PI); + TEST_FAILURE(".*ERROR: Variable four: Invalid syntax in variable formula.*", + command("print \"${four}\"");); } } // namespace LAMMPS_NS From 180e8168862f0d50cd5a6cbed8e5f1a6c8553708 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Mar 2021 19:55:08 -0400 Subject: [PATCH 127/257] Simplify PythonPackage tests --- unittest/python/test_python_package.cpp | 44 +++++++++++++------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/unittest/python/test_python_package.cpp b/unittest/python/test_python_package.cpp index cba77ee2b0..5974592997 100644 --- a/unittest/python/test_python_package.cpp +++ b/unittest/python/test_python_package.cpp @@ -40,6 +40,8 @@ protected: LAMMPS *lmp; Info *info; + void command(const std::string &line) { lmp->input->one(line.c_str()); } + void SetUp() override { const char *args[] = {"PythonPackageTest", "-log", "none", "-echo", "screen", "-nocite"}; @@ -51,16 +53,16 @@ protected: ASSERT_NE(lmp, nullptr); info = new Info(lmp); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units real"); - lmp->input->one("dimension 3"); - lmp->input->one("region box block -4 4 -4 4 -4 4"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 single 0.0 0.0 0.0 units box"); - lmp->input->one("create_atoms 1 single 1.9 -1.9 1.9999 units box"); - lmp->input->one("pair_style zero 2.0"); - lmp->input->one("pair_coeff * *"); - lmp->input->one("mass * 1.0"); - lmp->input->one("variable input_dir index " + INPUT_FOLDER); + command("units real"); + command("dimension 3"); + command("region box block -4 4 -4 4 -4 4"); + command("create_box 1 box"); + command("create_atoms 1 single 0.0 0.0 0.0 units box"); + command("create_atoms 1 single 1.9 -1.9 1.9999 units box"); + command("pair_style zero 2.0"); + command("pair_coeff * *"); + command("mass * 1.0"); + command("variable input_dir index " + INPUT_FOLDER); if (!verbose) ::testing::internal::GetCapturedStdout(); } @@ -78,31 +80,31 @@ TEST_F(PythonPackageTest, python_invoke) if (!info->has_style("command", "python")) GTEST_SKIP(); // execute python function from file if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("python printnum file ${input_dir}/func.py"); + command("python printnum file ${input_dir}/func.py"); if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - lmp->input->one("python printnum invoke"); + command("python printnum invoke"); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; ASSERT_THAT(output, MatchesRegex("python.*2.25.*")); // execute another python function from same file if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("python printtxt exists"); + command("python printtxt exists"); if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - lmp->input->one("python printtxt invoke"); + command("python printtxt invoke"); output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; ASSERT_THAT(output, MatchesRegex("python.*sometext.*")); // execute python function that uses the LAMMPS python module if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("variable idx equal 2.25"); - lmp->input->one("python getidxvar input 1 SELF format p exists"); + command("variable idx equal 2.25"); + command("python getidxvar input 1 SELF format p exists"); if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - lmp->input->one("python getidxvar invoke"); + command("python getidxvar invoke"); output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; ASSERT_THAT(output, MatchesRegex("python.*2.25.*")); @@ -112,12 +114,12 @@ TEST_F(PythonPackageTest, python_variable) { if (!info->has_style("command", "python")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("variable sq python square"); - lmp->input->one("variable val index 1.5"); - lmp->input->one("python square input 1 v_val return v_sq format ff file ${input_dir}/func.py"); + command("variable sq python square"); + command("variable val index 1.5"); + command("python square input 1 v_val return v_sq format ff file ${input_dir}/func.py"); if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - lmp->input->one("print \"${sq}\""); + command("print \"${sq}\""); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; ASSERT_THAT(output, MatchesRegex("print.*2.25.*")); From 6b24006d43f71f5368d3feedd66e7f48e29de9f1 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Mar 2021 19:56:18 -0400 Subject: [PATCH 128/257] Use Info::has_package to check for PYTHON support --- unittest/python/test_python_package.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittest/python/test_python_package.cpp b/unittest/python/test_python_package.cpp index 5974592997..110ea24dbc 100644 --- a/unittest/python/test_python_package.cpp +++ b/unittest/python/test_python_package.cpp @@ -77,7 +77,7 @@ protected: TEST_F(PythonPackageTest, python_invoke) { - if (!info->has_style("command", "python")) GTEST_SKIP(); + if (!info->has_package("PYTHON")) GTEST_SKIP(); // execute python function from file if (!verbose) ::testing::internal::CaptureStdout(); command("python printnum file ${input_dir}/func.py"); @@ -112,7 +112,7 @@ TEST_F(PythonPackageTest, python_invoke) TEST_F(PythonPackageTest, python_variable) { - if (!info->has_style("command", "python")) GTEST_SKIP(); + if (!info->has_package("PYTHON")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); command("variable sq python square"); command("variable val index 1.5"); From 359a369573121f9101c0651384a9efd835ffba39 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Mar 2021 19:57:45 -0400 Subject: [PATCH 129/257] Ensure that global Py_UnbufferedStdioFlag is set when PYTHONUNBUFFERED=1 --- src/PYTHON/python_impl.cpp | 10 ++++++++++ unittest/python/CMakeLists.txt | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/PYTHON/python_impl.cpp b/src/PYTHON/python_impl.cpp index d1f602a1ea..1f45ca6635 100644 --- a/src/PYTHON/python_impl.cpp +++ b/src/PYTHON/python_impl.cpp @@ -55,6 +55,16 @@ PythonImpl::PythonImpl(LAMMPS *lmp) : Pointers(lmp) nfunc = 0; pfuncs = nullptr; + + // check for PYTHONUNBUFFERED environment variable + const char * PYTHONUNBUFFERED = getenv("PYTHONUNBUFFERED"); + + if (PYTHONUNBUFFERED != nullptr && strcmp(PYTHONUNBUFFERED, "1") == 0) { + // Python Global configuration variable + // Force the stdout and stderr streams to be unbuffered. + Py_UnbufferedStdioFlag = 1; + } + // one-time initialization of Python interpreter // pyMain stores pointer to main module external_interpreter = Py_IsInitialized(); diff --git a/unittest/python/CMakeLists.txt b/unittest/python/CMakeLists.txt index d508602c93..d1db17c941 100644 --- a/unittest/python/CMakeLists.txt +++ b/unittest/python/CMakeLists.txt @@ -8,7 +8,7 @@ add_executable(test_python_package test_python_package.cpp) target_link_libraries(test_python_package PRIVATE lammps GTest::GMock GTest::GTest) target_compile_definitions(test_python_package PRIVATE -DTEST_INPUT_FOLDER=${TEST_INPUT_FOLDER}) add_test(NAME PythonPackage COMMAND test_python_package WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -set_tests_properties(PythonPackage PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:${LAMMPS_PYTHON_DIR}:$ENV{PYTHONPATH}") +set_tests_properties(PythonPackage PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:${LAMMPS_PYTHON_DIR}:$ENV{PYTHONPATH};PYTHONUNBUFFERED=1") # we must have shared libraries enabled for testing the python module if(NOT BUILD_SHARED_LIBS) From 23c8d8ccfb9ec206e7acf6035c3adcd0919929b6 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 23 Mar 2021 20:13:39 -0400 Subject: [PATCH 130/257] Use HasSubstr since output order is dependent on buffering --- unittest/python/test_python_package.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/unittest/python/test_python_package.cpp b/unittest/python/test_python_package.cpp index 110ea24dbc..723271c589 100644 --- a/unittest/python/test_python_package.cpp +++ b/unittest/python/test_python_package.cpp @@ -34,6 +34,7 @@ using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { using ::testing::MatchesRegex; using ::testing::StrEq; +using ::testing::HasSubstr; class PythonPackageTest : public ::testing::Test { protected: @@ -86,7 +87,7 @@ TEST_F(PythonPackageTest, python_invoke) command("python printnum invoke"); std::string output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; - ASSERT_THAT(output, MatchesRegex("python.*2.25.*")); + ASSERT_THAT(output, HasSubstr("2.25\n")); // execute another python function from same file if (!verbose) ::testing::internal::CaptureStdout(); @@ -96,7 +97,7 @@ TEST_F(PythonPackageTest, python_invoke) command("python printtxt invoke"); output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; - ASSERT_THAT(output, MatchesRegex("python.*sometext.*")); + ASSERT_THAT(output, HasSubstr("sometext\n")); // execute python function that uses the LAMMPS python module if (!verbose) ::testing::internal::CaptureStdout(); @@ -107,7 +108,7 @@ TEST_F(PythonPackageTest, python_invoke) command("python getidxvar invoke"); output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; - ASSERT_THAT(output, MatchesRegex("python.*2.25.*")); + ASSERT_THAT(output, HasSubstr("2.25\n")); } TEST_F(PythonPackageTest, python_variable) From 85d1257222797041e7186580d91c931889bc7f3c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 23 Mar 2021 21:41:50 -0400 Subject: [PATCH 131/257] move redundant enumerator to Variable class definition in variable.h --- src/info.cpp | 11 +++++------ src/variable.cpp | 4 +--- src/variable.h | 4 ++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/info.cpp b/src/info.cpp index 98ad5a3097..948073bb10 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -64,9 +64,6 @@ #endif namespace LAMMPS_NS { -// same as in variable.cpp -enum {INDEX,LOOP,WORLD,UNIVERSE,ULOOP,STRING,GETENV, - SCALARFILE,ATOMFILE,FORMAT,EQUAL,ATOM,VECTOR,PYTHON,INTERNAL}; enum {COMPUTES=1<<0, DUMPS=1<<1, @@ -106,9 +103,11 @@ static const int STYLES = ATOM_STYLES | INTEGRATE_STYLES | MINIMIZE_STYLES using namespace LAMMPS_NS; +// must match enumerator in variable.h static const char *varstyles[] = { "index", "loop", "world", "universe", "uloop", "string", "getenv", - "file", "atomfile", "format", "equal", "atom", "vector", "python", "internal", "(unknown)"}; + "file", "atomfile", "format", "equal", "atom", "vector", "python", + "internal", "(unknown)"}; static const char *mapstyles[] = { "none", "array", "hash", "yes" }; @@ -649,11 +648,11 @@ void Info::command(int narg, char **arg) fmt::print(out,"Variable[{:3d}]: {:16} style = {:16} def =", i,std::string(names[i])+',', std::string(varstyles[style[i]])+','); - if (style[i] == INTERNAL) { + if (style[i] == Variable::INTERNAL) { fmt::print(out,"{:.8}\n",input->variable->dvalue[i]); continue; } - if ((style[i] != LOOP) && (style[i] != ULOOP)) + if ((style[i] != Variable::LOOP) && (style[i] != Variable::ULOOP)) ndata = input->variable->num[i]; for (int j=0; j < ndata; ++j) if (data[i][j]) fmt::print(out," {}",data[i][j]); diff --git a/src/variable.cpp b/src/variable.cpp index 9a8236fdb4..4646bf98b2 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -54,8 +54,6 @@ using namespace MathConst; #define MYROUND(a) (( a-floor(a) ) >= .5) ? ceil(a) : floor(a) -enum{INDEX,LOOP,WORLD,UNIVERSE,ULOOP,STRING,GETENV, - SCALARFILE,ATOMFILE,FORMAT,EQUAL,ATOM,VECTOR,PYTHON,INTERNAL}; enum{ARG,OP}; // customize by adding a function @@ -5023,7 +5021,7 @@ VarReader::VarReader(LAMMPS *lmp, char *name, char *file, int flag) : id_fix = nullptr; buffer = nullptr; - if (style == ATOMFILE) { + if (style == Variable::ATOMFILE) { if (atom->map_style == Atom::MAP_NONE) error->all(FLERR,"Cannot use atomfile-style " "variable unless an atom map exists"); diff --git a/src/variable.h b/src/variable.h index 50d276bb14..e311380971 100644 --- a/src/variable.h +++ b/src/variable.h @@ -53,6 +53,10 @@ class Variable : protected Pointers { int nvar; // # of defined variables char **names; // name of each variable + // must match "varstyles" array in info.cpp + enum{INDEX,LOOP,WORLD,UNIVERSE,ULOOP,STRING,GETENV, + SCALARFILE,ATOMFILE,FORMAT,EQUAL,ATOM,VECTOR,PYTHON,INTERNAL}; + private: int me; int maxvar; // max # of variables following lists can hold From 67f1f12c20134b6db3ea1bf10d6aa45aa61a42d7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 23 Mar 2021 21:42:45 -0400 Subject: [PATCH 132/257] more tests for expressions --- src/variable.cpp | 15 ++++----- src/variable.h | 2 +- unittest/commands/test_variables.cpp | 46 ++++++++++++++++++++++------ 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/variable.cpp b/src/variable.cpp index 4646bf98b2..76a4b84f89 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -534,12 +534,10 @@ void Variable::set(int narg, char **arg) if (replaceflag) return; + if (!utils::is_id(arg[0])) + error->all(FLERR,fmt::format("Variable name '{}' must have only alphanu" + "meric characters or underscores",arg[0])); names[nvar] = utils::strdup(arg[0]); - for (auto c : std::string(arg[0])) - if (!isalnum(c) && (c != '_')) - error->all(FLERR,fmt::format("Variable name '{}' must have only " - "alphanumeric characters or underscores", - names[nvar])); nvar++; } @@ -983,9 +981,12 @@ double Variable::compute_equal(int ivar) don't need to flag eval_in_progress since is an immediate variable ------------------------------------------------------------------------- */ -double Variable::compute_equal(char *str) +double Variable::compute_equal(const std::string &str) { - return evaluate(str,nullptr,-1); + char *ptr = utils::strdup(str); + double val = evaluate(ptr,nullptr,-1); + delete[] ptr; + return val; } /* ---------------------------------------------------------------------- diff --git a/src/variable.h b/src/variable.h index e311380971..a43e7f3ad7 100644 --- a/src/variable.h +++ b/src/variable.h @@ -41,7 +41,7 @@ class Variable : protected Pointers { char *retrieve(const char *); double compute_equal(int); - double compute_equal(char *); + double compute_equal(const std::string &); void compute_atom(int, int, double *, int, int); int compute_vector(int, double **); void internal_set(int, double); diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 90a0fe00e7..9f8d08fa31 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -166,13 +166,15 @@ TEST_F(VariableTest, CreateDelete) command("variable eight getenv PWD"); command("variable eight getenv HOME"); command("variable nine file test_variable.file"); + command("variable ten internal 1.0"); + command("variable ten internal 10.0"); command("variable dummy index 0"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 12); + ASSERT_EQ(variable->nvar, 13); if (!verbose) ::testing::internal::CaptureStdout(); command("variable dummy delete"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 11); + ASSERT_EQ(variable->nvar, 12); TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable");); TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy index");); @@ -183,8 +185,10 @@ TEST_F(VariableTest, CreateDelete) command("variable two getenv xxx");); TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", command("variable one equal 2");); + TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", + command("variable one internal 2");); TEST_FAILURE(".*ERROR: Cannot use atomfile-style variable unless an atom map exists.*", - command("variable ten atomfile test_variable.atomfile");); + command("variable eleven atomfile test_variable.atomfile");); TEST_FAILURE(".*ERROR on proc 0: Cannot open file variable file test_variable.xxx.*", command("variable nine1 file test_variable.xxx");); } @@ -220,20 +224,42 @@ TEST_F(VariableTest, Expressions) command("variable four equal PI"); command("variable five equal version"); command("variable six equal XXX"); + command("variable seven equal -v_one"); + command("variable eight equal v_three-0.5"); + command("variable nine equal v_two*(v_one+v_three)"); + command("variable ten equal (1.0/v_two)^2"); + command("variable eleven equal v_three%2"); + command("variable twelve equal 1==2"); + command("variable ten3 equal 1!=v_two"); + command("variable ten4 equal 1<2"); + command("variable ten5 equal 2>1"); + command("variable ten6 equal (1<=v_one)&&(v_ten>=0.2)"); + command("variable ten7 equal !(1nvar, 6); + ASSERT_EQ(variable->nvar, 18); int ivar = variable->find("one"); ASSERT_FALSE(variable->equalstyle(ivar)); ivar = variable->find("two"); ASSERT_TRUE(variable->equalstyle(ivar)); ASSERT_DOUBLE_EQ(variable->compute_equal(ivar), 2.0); - ivar = variable->find("three"); - ASSERT_DOUBLE_EQ(variable->compute_equal(ivar), 3.0); - ivar = variable->find("four"); - ASSERT_DOUBLE_EQ(variable->compute_equal(ivar), MY_PI); - ivar = variable->find("five"); - ASSERT_GE(variable->compute_equal(ivar), 20210310); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_three"), 3.0); + ASSERT_FLOAT_EQ(variable->compute_equal("v_four"), MY_PI); + ASSERT_GE(variable->compute_equal("v_five"), 20210310); + EXPECT_DOUBLE_EQ(variable->compute_equal("v_seven"), -1); + EXPECT_DOUBLE_EQ(variable->compute_equal("v_eight"), 2.5); + EXPECT_DOUBLE_EQ(variable->compute_equal("v_nine"), 8); + EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten"), 0.25); + EXPECT_DOUBLE_EQ(variable->compute_equal("v_eleven"), 1); + EXPECT_DOUBLE_EQ(variable->compute_equal("v_twelve"), 0); + EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten3"), 1); + EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten4"), 1); + EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten5"), 1); + EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten6"), 1); + EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten7"), 0); + EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten8"), 1); TEST_FAILURE(".*ERROR: Variable six: Invalid thermo keyword 'XXX' in variable formula.*", command("print \"${six}\"");); From b6a030532d4f1259279562c3df71456fed11edc4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 24 Mar 2021 10:33:00 -0400 Subject: [PATCH 133/257] add tests for boolean evaluation in "if" command --- unittest/commands/test_variables.cpp | 71 +++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 12 deletions(-) diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 9f8d08fa31..5a1d249bd5 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -248,18 +248,18 @@ TEST_F(VariableTest, Expressions) ASSERT_DOUBLE_EQ(variable->compute_equal("v_three"), 3.0); ASSERT_FLOAT_EQ(variable->compute_equal("v_four"), MY_PI); ASSERT_GE(variable->compute_equal("v_five"), 20210310); - EXPECT_DOUBLE_EQ(variable->compute_equal("v_seven"), -1); - EXPECT_DOUBLE_EQ(variable->compute_equal("v_eight"), 2.5); - EXPECT_DOUBLE_EQ(variable->compute_equal("v_nine"), 8); - EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten"), 0.25); - EXPECT_DOUBLE_EQ(variable->compute_equal("v_eleven"), 1); - EXPECT_DOUBLE_EQ(variable->compute_equal("v_twelve"), 0); - EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten3"), 1); - EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten4"), 1); - EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten5"), 1); - EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten6"), 1); - EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten7"), 0); - EXPECT_DOUBLE_EQ(variable->compute_equal("v_ten8"), 1); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_seven"), -1); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_eight"), 2.5); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_nine"), 8); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten"), 0.25); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_eleven"), 1); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_twelve"), 0); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten3"), 1); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten4"), 1); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten5"), 1); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten6"), 1); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten7"), 0); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten8"), 1); TEST_FAILURE(".*ERROR: Variable six: Invalid thermo keyword 'XXX' in variable formula.*", command("print \"${six}\"");); @@ -287,6 +287,53 @@ TEST_F(VariableTest, Functions) TEST_FAILURE(".*ERROR: Variable four: Invalid syntax in variable formula.*", command("print \"${four}\"");); } + +TEST_F(VariableTest, IfCommand) +{ + if (!verbose) ::testing::internal::CaptureStdout(); + command("variable one index 1"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + ::testing::internal::CaptureStdout(); + command("if 1>0 then 'print \".*bingo!\"'"); + auto text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text,MatchesRegex(".*bingo!.*")); + + ::testing::internal::CaptureStdout(); + command("if (1>=0) then 'print \"bingo!\"'"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text,MatchesRegex(".*bingo!.*")); + + ::testing::internal::CaptureStdout(); + command("if (-1.0e-1<0.0E+0) then 'print \"bingo!\"'"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text,MatchesRegex(".*bingo!.*")); + + ::testing::internal::CaptureStdout(); + command("if (${one}==1.0)&&(2>=1) then 'print \"bingo!\"'"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text,MatchesRegex(".*bingo!.*")); + + ::testing::internal::CaptureStdout(); + command("if !((${one}!=1.0)||(2|^1)) then 'print \"missed\"' else 'print \"bingo!\"'"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text,MatchesRegex(".*bingo!.*")); + + TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", + command("if () then 'print \"bingo!\"'");); + TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", + command("if (1)( then 'print \"bingo!\"'");); + TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", + command("if (1)1 then 'print \"bingo!\"'");); + TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", + command("if (v_one==1.0)&&(2>=1) then 'print \"bingo!\"'");); +} + } // namespace LAMMPS_NS int main(int argc, char **argv) From 8790ecc141cfe52f01d3ec77bcf687bb3808c9da Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 24 Mar 2021 11:18:21 -0400 Subject: [PATCH 134/257] Refactor existing tests --- unittest/python/test_python_package.cpp | 130 ++++++++++++++---------- 1 file changed, 76 insertions(+), 54 deletions(-) diff --git a/unittest/python/test_python_package.cpp b/unittest/python/test_python_package.cpp index 723271c589..137278a9d2 100644 --- a/unittest/python/test_python_package.cpp +++ b/unittest/python/test_python_package.cpp @@ -20,6 +20,7 @@ #include #include #include +#include // location of '*.py' files required by tests #define STRINGIFY(val) XSTR(val) @@ -43,86 +44,107 @@ protected: void command(const std::string &line) { lmp->input->one(line.c_str()); } + void HIDE_OUTPUT(std::function f) { + if (!verbose) ::testing::internal::CaptureStdout(); + f(); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + std::string CAPTURE_OUTPUT(std::function f) { + ::testing::internal::CaptureStdout(); + f(); + auto output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + return output; + } + void SetUp() override { const char *args[] = {"PythonPackageTest", "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + HIDE_OUTPUT([&] { + lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + }); ASSERT_NE(lmp, nullptr); info = new Info(lmp); - if (!verbose) ::testing::internal::CaptureStdout(); - command("units real"); - command("dimension 3"); - command("region box block -4 4 -4 4 -4 4"); - command("create_box 1 box"); - command("create_atoms 1 single 0.0 0.0 0.0 units box"); - command("create_atoms 1 single 1.9 -1.9 1.9999 units box"); - command("pair_style zero 2.0"); - command("pair_coeff * *"); - command("mass * 1.0"); - command("variable input_dir index " + INPUT_FOLDER); - if (!verbose) ::testing::internal::GetCapturedStdout(); + if (!info->has_package("PYTHON")) GTEST_SKIP(); + HIDE_OUTPUT([&] { + command("units real"); + command("dimension 3"); + command("region box block -4 4 -4 4 -4 4"); + command("create_box 1 box"); + command("create_atoms 1 single 0.0 0.0 0.0 units box"); + command("create_atoms 1 single 1.9 -1.9 1.9999 units box"); + command("pair_style zero 2.0"); + command("pair_coeff * *"); + command("mass * 1.0"); + command("variable input_dir index " + INPUT_FOLDER); + }); } void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete info; - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); + HIDE_OUTPUT([&] { + delete info; + delete lmp; + info = nullptr; + lmp = nullptr; + }); } }; -TEST_F(PythonPackageTest, python_invoke) +TEST_F(PythonPackageTest, InvokeFunctionFromFile) { - if (!info->has_package("PYTHON")) GTEST_SKIP(); // execute python function from file - if (!verbose) ::testing::internal::CaptureStdout(); - command("python printnum file ${input_dir}/func.py"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - ::testing::internal::CaptureStdout(); - command("python printnum invoke"); - std::string output = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << output; + HIDE_OUTPUT([&] { + command("python printnum file ${input_dir}/func.py"); + }); + + auto output = CAPTURE_OUTPUT([&]() { + command("python printnum invoke"); + }); ASSERT_THAT(output, HasSubstr("2.25\n")); +} +TEST_F(PythonPackageTest, InvokeOtherFunctionFromFile) +{ // execute another python function from same file - if (!verbose) ::testing::internal::CaptureStdout(); - command("python printtxt exists"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - ::testing::internal::CaptureStdout(); - command("python printtxt invoke"); - output = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << output; - ASSERT_THAT(output, HasSubstr("sometext\n")); + HIDE_OUTPUT([&] { + command("python printnum file ${input_dir}/func.py"); + command("python printtxt exists"); + }); + auto output = CAPTURE_OUTPUT([&] { + command("python printtxt invoke"); + }); + ASSERT_THAT(output, HasSubstr("sometext\n")); +} + +TEST_F(PythonPackageTest, InvokeFunctionThatUsesLAMMPSModule) +{ // execute python function that uses the LAMMPS python module - if (!verbose) ::testing::internal::CaptureStdout(); - command("variable idx equal 2.25"); - command("python getidxvar input 1 SELF format p exists"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - ::testing::internal::CaptureStdout(); - command("python getidxvar invoke"); - output = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << output; + HIDE_OUTPUT([&] { + command("python printnum file ${input_dir}/func.py"); + command("variable idx equal 2.25"); + command("python getidxvar input 1 SELF format p exists"); + }); + auto output = CAPTURE_OUTPUT([&] { + command("python getidxvar invoke"); + }); ASSERT_THAT(output, HasSubstr("2.25\n")); } TEST_F(PythonPackageTest, python_variable) { - if (!info->has_package("PYTHON")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); - command("variable sq python square"); - command("variable val index 1.5"); - command("python square input 1 v_val return v_sq format ff file ${input_dir}/func.py"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - ::testing::internal::CaptureStdout(); - command("print \"${sq}\""); - std::string output = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << output; + HIDE_OUTPUT([&] { + command("variable sq python square"); + command("variable val index 1.5"); + command("python square input 1 v_val return v_sq format ff file ${input_dir}/func.py"); + }); + std::string output = CAPTURE_OUTPUT([&] { + command("print \"${sq}\""); + }); ASSERT_THAT(output, MatchesRegex("print.*2.25.*")); } From 487c55edf0d4a5e2811a430d8ac7429d1e63ef92 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 24 Mar 2021 11:24:55 -0400 Subject: [PATCH 135/257] simplify and apply clang-format --- unittest/c-library/test_library_mpi.cpp | 2 +- unittest/commands/test_groups.cpp | 2 +- unittest/commands/test_kim_commands.cpp | 612 ++++++++---------- unittest/commands/test_lattice_region.cpp | 259 ++++---- unittest/commands/test_reset_ids.cpp | 132 ++-- unittest/commands/test_simple_commands.cpp | 126 ++-- unittest/commands/test_variables.cpp | 10 +- unittest/force-styles/test_angle_style.cpp | 4 +- unittest/force-styles/test_bond_style.cpp | 4 +- unittest/force-styles/test_config_reader.cpp | 14 +- unittest/force-styles/test_dihedral_style.cpp | 4 +- unittest/force-styles/test_improper_style.cpp | 4 +- unittest/force-styles/test_pair_style.cpp | 9 +- unittest/formats/test_atom_styles.cpp | 5 +- unittest/formats/test_file_operations.cpp | 8 +- unittest/formats/test_image_flags.cpp | 235 +++---- unittest/formats/test_molecule_file.cpp | 21 +- unittest/formats/test_pair_unit_convert.cpp | 500 +++++++------- .../formats/test_potential_file_reader.cpp | 34 +- unittest/utils/test_tokenizer.cpp | 6 +- unittest/utils/test_utils.cpp | 8 +- 21 files changed, 983 insertions(+), 1016 deletions(-) diff --git a/unittest/c-library/test_library_mpi.cpp b/unittest/c-library/test_library_mpi.cpp index 7502da767a..6fdec7b7e4 100644 --- a/unittest/c-library/test_library_mpi.cpp +++ b/unittest/c-library/test_library_mpi.cpp @@ -191,7 +191,7 @@ TEST(MPI, multi_partition) EXPECT_EQ(lammps_extract_setting(lmp, "world_rank"), 0); char *part_id = (char *)lammps_extract_variable(lmp, "partition", nullptr); - ASSERT_THAT(part_id, StrEq(std::to_string(me+1))); + ASSERT_THAT(part_id, StrEq(std::to_string(me + 1))); lammps_close(lmp); }; diff --git a/unittest/commands/test_groups.cpp b/unittest/commands/test_groups.cpp index 7fa7ee721f..3ae1722f4d 100644 --- a/unittest/commands/test_groups.cpp +++ b/unittest/commands/test_groups.cpp @@ -73,7 +73,7 @@ protected: if (!verbose) ::testing::internal::CaptureStdout(); lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); if (!verbose) ::testing::internal::GetCapturedStdout(); - group = lmp->group; + group = lmp->group; domain = lmp->domain; } diff --git a/unittest/commands/test_kim_commands.cpp b/unittest/commands/test_kim_commands.cpp index 311ce6acf1..2d044b86eb 100644 --- a/unittest/commands/test_kim_commands.cpp +++ b/unittest/commands/test_kim_commands.cpp @@ -59,6 +59,7 @@ using ::testing::StrEq; class KimCommandsTest : public ::testing::Test { protected: LAMMPS *lmp; + Variable *variable; void SetUp() override { @@ -68,6 +69,7 @@ protected: if (!verbose) ::testing::internal::CaptureStdout(); lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); if (!verbose) ::testing::internal::GetCapturedStdout(); + variable = lmp->input->variable; } void TearDown() override @@ -76,53 +78,45 @@ protected: delete lmp; if (!verbose) ::testing::internal::GetCapturedStdout(); } + + void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(KimCommandsTest, kim) { if (!LAMMPS::is_installed_pkg("KIM")) GTEST_SKIP(); - TEST_FAILURE(".*ERROR: Illegal kim command.*", - lmp->input->one("kim");); - TEST_FAILURE(".*ERROR: Unknown kim subcommand.*", - lmp->input->one("kim unknown");); - TEST_FAILURE(".*kim_init.*has been renamed to.*", - lmp->input->one("kim_init");); - TEST_FAILURE(".*kim_interactions.*has been renamed to.*", - lmp->input->one("kim_interactions");); - TEST_FAILURE(".*kim_param.*has been renamed to.*", - lmp->input->one("kim_param");); - TEST_FAILURE(".*kim_property.*has been renamed to.*", - lmp->input->one("kim_property");); - TEST_FAILURE(".*kim_query.*has been renamed to.*", - lmp->input->one("kim_query");); + TEST_FAILURE(".*ERROR: Illegal kim command.*", command("kim");); + TEST_FAILURE(".*ERROR: Unknown kim subcommand.*", command("kim unknown");); + TEST_FAILURE(".*kim_init.*has been renamed to.*", command("kim_init");); + TEST_FAILURE(".*kim_interactions.*has been renamed to.*", command("kim_interactions");); + TEST_FAILURE(".*kim_param.*has been renamed to.*", command("kim_param");); + TEST_FAILURE(".*kim_property.*has been renamed to.*", command("kim_property");); + TEST_FAILURE(".*kim_query.*has been renamed to.*", command("kim_query");); } TEST_F(KimCommandsTest, kim_init) { if (!LAMMPS::is_installed_pkg("KIM")) GTEST_SKIP(); + TEST_FAILURE(".*ERROR: Illegal 'kim init' command.*", command("kim init");); TEST_FAILURE(".*ERROR: Illegal 'kim init' command.*", - lmp->input->one("kim init");); - TEST_FAILURE(".*ERROR: Illegal 'kim init' command.*", - lmp->input->one("kim init LennardJones_Ar real si");); + command("kim init LennardJones_Ar real si");); TEST_FAILURE(".*ERROR: LAMMPS unit_style lj not supported by KIM models.*", - lmp->input->one("kim init LennardJones_Ar lj");); + command("kim init LennardJones_Ar lj");); TEST_FAILURE(".*ERROR: LAMMPS unit_style micro not supported by KIM models.*", - lmp->input->one("kim init LennardJones_Ar micro");); + command("kim init LennardJones_Ar micro");); TEST_FAILURE(".*ERROR: LAMMPS unit_style nano not supported by KIM models.*", - lmp->input->one("kim init LennardJones_Ar nano");); - TEST_FAILURE(".*ERROR: Unknown unit_style.*", - lmp->input->one("kim init LennardJones_Ar new_style");); - TEST_FAILURE(".*ERROR: KIM Model name not found.*", - lmp->input->one("kim init Unknown_Model real");); + command("kim init LennardJones_Ar nano");); + TEST_FAILURE(".*ERROR: Unknown unit_style.*", command("kim init LennardJones_Ar new_style");); + TEST_FAILURE(".*ERROR: KIM Model name not found.*", command("kim init Unknown_Model real");); TEST_FAILURE(".*ERROR: Incompatible units for KIM Simulator Model, required units = metal.*", - lmp->input->one("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu real");); + command("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu real");); // TEST_FAILURE(".*ERROR: KIM Model does not support the requested unit system.*", - // lmp->input->one("kim init ex_model_Ar_P_Morse real");); + // command("kim init ex_model_Ar_P_Morse real");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("kim init LennardJones_Ar real"); + command("kim init LennardJones_Ar real"); if (!verbose) ::testing::internal::GetCapturedStdout(); int ifix = lmp->modify->find_fix("KIM_MODEL_STORE"); @@ -133,124 +127,122 @@ TEST_F(KimCommandsTest, kim_interactions) { if (!LAMMPS::is_installed_pkg("KIM")) GTEST_SKIP(); - TEST_FAILURE(".*ERROR: Illegal 'kim interactions' command.*", - lmp->input->one("kim interactions");); + TEST_FAILURE(".*ERROR: Illegal 'kim interactions' command.*", command("kim interactions");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("kim init LennardJones_Ar real"); + command("kim init LennardJones_Ar real"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Must use 'kim interactions' command " "after simulation box is defined.*", - lmp->input->one("kim interactions Ar");); + command("kim interactions Ar");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("kim init LennardJones_Ar real"); - lmp->input->one("lattice fcc 4.4300"); - lmp->input->one("region box block 0 10 0 10 0 10"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 box"); + command("kim init LennardJones_Ar real"); + command("lattice fcc 4.4300"); + command("region box block 0 10 0 10 0 10"); + command("create_box 1 box"); + command("create_atoms 1 box"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal 'kim interactions' command.*", - lmp->input->one("kim interactions Ar Ar");); + command("kim interactions Ar Ar");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("lattice fcc 4.4300"); - lmp->input->one("region box block 0 20 0 20 0 20"); - lmp->input->one("create_box 4 box"); - lmp->input->one("create_atoms 4 box"); + command("clear"); + command("lattice fcc 4.4300"); + command("region box block 0 20 0 20 0 20"); + command("create_box 4 box"); + command("create_atoms 4 box"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal 'kim interactions' command.*", - lmp->input->one("kim interactions Ar Ar");); + command("kim interactions Ar Ar");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("lattice fcc 4.4300"); - lmp->input->one("region box block 0 10 0 10 0 10"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 box"); + command("clear"); + command("lattice fcc 4.4300"); + command("region box block 0 10 0 10 0 10"); + command("create_box 1 box"); + command("create_atoms 1 box"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Must use 'kim init' before 'kim interactions'.*", - lmp->input->one("kim interactions Ar");); + command("kim interactions Ar");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("kim init LennardJones_Ar real"); - lmp->input->one("lattice fcc 4.4300"); - lmp->input->one("region box block 0 10 0 10 0 10"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 box"); + command("clear"); + command("kim init LennardJones_Ar real"); + command("lattice fcc 4.4300"); + command("region box block 0 10 0 10 0 10"); + command("create_box 1 box"); + command("create_atoms 1 box"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: fixed_types cannot be used with a KIM Portable Model.*", - lmp->input->one("kim interactions fixed_types");); + command("kim interactions fixed_types");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("pair_style kim LennardJones_Ar"); - lmp->input->one("region box block 0 1 0 1 0 1"); - lmp->input->one("create_box 4 box"); - lmp->input->one("pair_coeff * * Ar Ar Ar Ar"); + command("clear"); + command("units real"); + command("pair_style kim LennardJones_Ar"); + command("region box block 0 1 0 1 0 1"); + command("create_box 4 box"); + command("pair_coeff * * Ar Ar Ar Ar"); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal"); - lmp->input->one("lattice fcc 4.920"); - lmp->input->one("region box block 0 10 0 10 0 10"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 box"); + command("clear"); + command("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal"); + command("lattice fcc 4.920"); + command("region box block 0 10 0 10 0 10"); + command("create_box 1 box"); + command("create_atoms 1 box"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Species 'Ar' is not supported by this KIM Simulator Model.*", - lmp->input->one("kim interactions Ar");); + command("kim interactions Ar");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal"); - lmp->input->one("lattice fcc 4.08"); - lmp->input->one("region box block 0 10 0 10 0 10"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 box"); - lmp->input->one("kim interactions Au"); + command("clear"); + command("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal"); + command("lattice fcc 4.08"); + command("region box block 0 10 0 10 0 10"); + command("create_box 1 box"); + command("create_atoms 1 box"); + command("kim interactions Au"); if (!verbose) ::testing::internal::GetCapturedStdout(); // ASSERT_EQ(lmp->output->var_kim_periodic, 1); // TEST_FAILURE(".*ERROR: Incompatible units for KIM Simulator Model.*", - // lmp->input->one("kim interactions Au");); - + // command("kim interactions Au");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("kim init LennardJones_Ar real"); - lmp->input->one("lattice fcc 4.4300"); - lmp->input->one("region box block 0 10 0 10 0 10"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 box"); - lmp->input->one("kim interactions Ar"); - lmp->input->one("mass 1 39.95"); + command("clear"); + command("kim init LennardJones_Ar real"); + command("lattice fcc 4.4300"); + command("region box block 0 10 0 10 0 10"); + command("create_box 1 box"); + command("create_atoms 1 box"); + command("kim interactions Ar"); + command("mass 1 39.95"); if (!verbose) ::testing::internal::GetCapturedStdout(); int ifix = lmp->modify->find_fix("KIM_MODEL_STORE"); ASSERT_GE(ifix, 0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("kim init LennardJones_Ar real"); - lmp->input->one("lattice fcc 4.4300"); - lmp->input->one("region box block 0 10 0 10 0 10"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 box"); - lmp->input->one("kim interactions Ar"); - lmp->input->one("mass 1 39.95"); - lmp->input->one("run 1"); - lmp->input->one("kim interactions Ar"); - lmp->input->one("run 1"); + command("clear"); + command("kim init LennardJones_Ar real"); + command("lattice fcc 4.4300"); + command("region box block 0 10 0 10 0 10"); + command("create_box 1 box"); + command("create_atoms 1 box"); + command("kim interactions Ar"); + command("mass 1 39.95"); + command("run 1"); + command("kim interactions Ar"); + command("run 1"); if (!verbose) ::testing::internal::GetCapturedStdout(); } @@ -258,189 +250,188 @@ TEST_F(KimCommandsTest, kim_param) { if (!LAMMPS::is_installed_pkg("KIM")) GTEST_SKIP(); - TEST_FAILURE(".*ERROR: Illegal 'kim param' command.*", - lmp->input->one("kim param");); + TEST_FAILURE(".*ERROR: Illegal 'kim param' command.*", command("kim param");); TEST_FAILURE(".*ERROR: Incorrect arguments in 'kim param' command.\n" "'kim param get/set' is mandatory.*", - lmp->input->one("kim param unknown shift 1 shift");); + command("kim param unknown shift 1 shift");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal"); + command("clear"); + command("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: 'kim param' can only be used with a KIM Portable Model.*", - lmp->input->one("kim param get shift 1 shift");); + command("kim param get shift 1 shift");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real"); + command("clear"); + command("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal 'kim param get' command.\nTo get the new " "parameter values, pair style must be assigned.\nMust use 'kim" " interactions' or 'pair_style kim' before 'kim param get'.*", - lmp->input->one("kim param get shift 1 shift");); + command("kim param get shift 1 shift");); TEST_FAILURE(".*ERROR: Illegal 'kim param set' command.\nTo set the new " "parameter values, pair style must be assigned.\nMust use 'kim" " interactions' or 'pair_style kim' before 'kim param set'.*", - lmp->input->one("kim param set shift 1 2");); + command("kim param set shift 1 2");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real"); - lmp->input->one("lattice fcc 4.4300"); - lmp->input->one("region box block 0 10 0 10 0 10"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 box"); - lmp->input->one("kim interactions Ar"); - lmp->input->one("mass 1 39.95"); + command("clear"); + command("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real"); + command("lattice fcc 4.4300"); + command("region box block 0 10 0 10 0 10"); + command("create_box 1 box"); + command("create_atoms 1 box"); + command("kim interactions Ar"); + command("mass 1 39.95"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Illegal index '0' for " "'shift' parameter with the extent of '1'.*", - lmp->input->one("kim param get shift 0 shift");); + command("kim param get shift 0 shift");); TEST_FAILURE(".*ERROR: Illegal index '2' for " "'shift' parameter with the extent of '1'.*", - lmp->input->one("kim param get shift 2 shift");); + command("kim param get shift 2 shift");); TEST_FAILURE(".*ERROR: Illegal index_range.\nExpected integer " "parameter\\(s\\) instead of '1.' in index_range.*", - lmp->input->one("kim param get shift 1. shift");); + command("kim param get shift 1. shift");); TEST_FAILURE(".*ERROR: Illegal index_range '1-2' for 'shift' " "parameter with the extent of '1'.*", - lmp->input->one("kim param get shift 1:2 shift");); + command("kim param get shift 1:2 shift");); TEST_FAILURE(".*ERROR: Illegal index_range.\nExpected integer " "parameter\\(s\\) instead of '1-2' in index_range.*", - lmp->input->one("kim param get shift 1-2 shift");); + command("kim param get shift 1-2 shift");); TEST_FAILURE(".*ERROR: Wrong number of arguments in 'kim param " "get' command.\nThe LAMMPS '3' variable names or " "'s1 split' is mandatory.*", - lmp->input->one("kim param get sigmas 1:3 s1 s2");); + command("kim param get sigmas 1:3 s1 s2");); TEST_FAILURE(".*ERROR: Wrong argument in 'kim param get' command.\nThis " "Model does not have the requested 'unknown' parameter.*", - lmp->input->one("kim param get unknown 1 unknown");); + command("kim param get unknown 1 unknown");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("kim param get shift 1 shift"); + command("kim param get shift 1 shift"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_FALSE(lmp->input->variable->find("shift") == -1); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("shift")) == "1"); + ASSERT_FALSE(variable->find("shift") == -1); + ASSERT_THAT(variable->retrieve("shift"), StrEq("1")); TEST_FAILURE(".*ERROR: Illegal index '2' for " "'shift' parameter with the extent of '1'.*", - lmp->input->one("kim param set shift 2 2");); + command("kim param set shift 2 2");); TEST_FAILURE(".*ERROR: Illegal index_range.\nExpected integer " "parameter\\(s\\) instead of '1.' in index_range.*", - lmp->input->one("kim param set shift 1. shift");); + command("kim param set shift 1. shift");); TEST_FAILURE(".*ERROR: Illegal index_range '1-2' for " "'shift' parameter with the extent of '1'.*", - lmp->input->one("kim param set shift 1:2 2");); + command("kim param set shift 1:2 2");); TEST_FAILURE(".*ERROR: Wrong number of variable values for pair coefficients.*", - lmp->input->one("kim param set sigmas 1:3 0.5523570 0.4989030");); + command("kim param set sigmas 1:3 0.5523570 0.4989030");); TEST_FAILURE(".*ERROR: Wrong argument for pair coefficients.\nThis " "Model does not have the requested '0.4989030' parameter.*", - lmp->input->one("kim param set sigmas 1:1 0.5523570 0.4989030");); + command("kim param set sigmas 1:1 0.5523570 0.4989030");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("variable new_shift equal 2"); - lmp->input->one("kim param set shift 1 ${new_shift}"); - lmp->input->one("kim param get shift 1 shift"); + command("variable new_shift equal 2"); + command("kim param set shift 1 ${new_shift}"); + command("kim param get shift 1 shift"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("shift")) == "2"); + ASSERT_THAT(variable->retrieve("shift"), StrEq("2")); TEST_FAILURE(".*ERROR: Illegal variable name in 'kim param get'.*", - lmp->input->one("kim param get cutoffs 1:3 list");); + command("kim param get cutoffs 1:3 list");); TEST_FAILURE(".*ERROR: Illegal variable name in 'kim param get'.*", - lmp->input->one("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 list");); + command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 list");); TEST_FAILURE(".*ERROR: Illegal variable name in 'kim param get'.*", - lmp->input->one("kim param get cutoffs 1:3 split");); + command("kim param get cutoffs 1:3 split");); TEST_FAILURE(".*ERROR: Illegal variable name in 'kim param get'.*", - lmp->input->one("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 split");); + command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 split");); TEST_FAILURE(".*ERROR: Illegal variable name in 'kim param get'.*", - lmp->input->one("kim param get cutoffs 1:3 explicit");); + command("kim param get cutoffs 1:3 explicit");); TEST_FAILURE(".*ERROR: Illegal variable name in 'kim param get'.*", - lmp->input->one("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 explicit");); + command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 explicit");); TEST_FAILURE(".*ERROR: Wrong number of arguments in 'kim param get' " "command.\nThe LAMMPS '3' variable names or 'cutoffs " "split/list' is mandatory.*", - lmp->input->one("kim param get cutoffs 1:3 cutoffs");); + command("kim param get cutoffs 1:3 cutoffs");); TEST_FAILURE(".*ERROR: Wrong number of arguments in 'kim param get' " "command.\nThe LAMMPS '3' variable names or 'cutoffs_1 " "split' is mandatory.*", - lmp->input->one("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2");); + command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 cutoffs_3"); + command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 cutoffs_3"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("cutoffs_1")) == "2.20943"); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("cutoffs_2")) == "2.10252"); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("cutoffs_3")) == "5.666115"); + ASSERT_THAT(variable->retrieve("cutoffs_1"), StrEq("2.20943")); + ASSERT_THAT(variable->retrieve("cutoffs_2"), StrEq("2.10252")); + ASSERT_THAT(variable->retrieve("cutoffs_3"), StrEq("5.666115")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 cutoffs_3 explicit"); + command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 cutoffs_3 explicit"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("cutoffs_1")) == "2.20943"); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("cutoffs_2")) == "2.10252"); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("cutoffs_3")) == "5.666115"); + ASSERT_THAT(variable->retrieve("cutoffs_1"), StrEq("2.20943")); + ASSERT_THAT(variable->retrieve("cutoffs_2"), StrEq("2.10252")); + ASSERT_THAT(variable->retrieve("cutoffs_3"), StrEq("5.666115")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("kim param get cutoffs 1:3 cutoffs split"); + command("kim param get cutoffs 1:3 cutoffs split"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("cutoffs_1")) == "2.20943"); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("cutoffs_2")) == "2.10252"); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("cutoffs_3")) == "5.666115"); + ASSERT_THAT(variable->retrieve("cutoffs_1"), StrEq("2.20943")); + ASSERT_THAT(variable->retrieve("cutoffs_2"), StrEq("2.10252")); + ASSERT_THAT(variable->retrieve("cutoffs_3"), StrEq("5.666115")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("kim param get cutoffs 1:3 cutoffs list"); + command("kim param get cutoffs 1:3 cutoffs list"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("cutoffs")) == "2.20943 2.10252 5.666115"); + ASSERT_THAT(variable->retrieve("cutoffs"), StrEq("2.20943 2.10252 5.666115")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("kim param set cutoffs 1 2.21 cutoffs 2 2.11"); - lmp->input->one("kim param get cutoffs 1:2 cutoffs list"); + command("kim param set cutoffs 1 2.21 cutoffs 2 2.11"); + command("kim param get cutoffs 1:2 cutoffs list"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("cutoffs")) == "2.21 2.11"); + ASSERT_THAT(variable->retrieve("cutoffs"), StrEq("2.21 2.11")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("kim param set cutoffs 1:3 2.3 2.2 5.7"); - lmp->input->one("kim param get cutoffs 1:3 cutoffs list"); + command("kim param set cutoffs 1:3 2.3 2.2 5.7"); + command("kim param get cutoffs 1:3 cutoffs list"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("cutoffs")) == "2.3 2.2 5.7"); + ASSERT_THAT(variable->retrieve("cutoffs"), StrEq("2.3 2.2 5.7")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("lattice fcc 4.4300"); - lmp->input->one("region box block 0 10 0 10 0 10"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 box"); - lmp->input->one("mass 1 39.95"); - lmp->input->one("pair_style kim LennardJones612_UniversalShifted__MO_959249795837_003"); - lmp->input->one("pair_coeff * * Ar"); + command("clear"); + command("units real"); + command("lattice fcc 4.4300"); + command("region box block 0 10 0 10 0 10"); + command("create_box 1 box"); + command("create_atoms 1 box"); + command("mass 1 39.95"); + command("pair_style kim LennardJones612_UniversalShifted__MO_959249795837_003"); + command("pair_coeff * * Ar"); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("kim param get shift 1 shift"); + command("kim param get shift 1 shift"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("shift")) == "1"); + ASSERT_THAT(variable->retrieve("shift"), StrEq("1")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("variable new_shift equal 2"); - lmp->input->one("kim param set shift 1 ${new_shift}"); - lmp->input->one("kim param get shift 1 shift"); + command("variable new_shift equal 2"); + command("kim param set shift 1 ${new_shift}"); + command("kim param get shift 1 shift"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE(std::string(lmp->input->variable->retrieve("shift")) == "2"); + ASSERT_THAT(variable->retrieve("shift"), StrEq("2")); } TEST_F(KimCommandsTest, kim_property) @@ -452,38 +443,36 @@ TEST_F(KimCommandsTest, kim_property) TEST_FAILURE(".*ERROR: Invalid Python version.\n" "The kim-property Python package requires Python " "3 >= 3.6 support.*", - lmp->input->one("kim property");); + command("kim property");); } else { - TEST_FAILURE(".*ERROR: Invalid 'kim property' command.*", - lmp->input->one("kim property");); - TEST_FAILURE(".*ERROR: Invalid 'kim property' command.*", - lmp->input->one("kim property create");); + TEST_FAILURE(".*ERROR: Invalid 'kim property' command.*", command("kim property");); + TEST_FAILURE(".*ERROR: Invalid 'kim property' command.*", command("kim property create");); TEST_FAILURE(".*ERROR: Incorrect arguments in 'kim property' command." "\n'kim property create/destroy/modify/remove/dump' " "is mandatory.*", - lmp->input->one("kim property unknown 1 atomic-mass");); + command("kim property unknown 1 atomic-mass");); } #if defined(KIM_EXTRA_UNITTESTS) TEST_FAILURE(".*ERROR: Invalid 'kim property create' command.*", - lmp->input->one("kim property create 1");); + command("kim property create 1");); TEST_FAILURE(".*ERROR: Invalid 'kim property destroy' command.*", - lmp->input->one("kim property destroy 1 cohesive-potential-energy-cubic-crystal");); + command("kim property destroy 1 cohesive-potential-energy-cubic-crystal");); TEST_FAILURE(".*ERROR: Invalid 'kim property modify' command.*", - lmp->input->one("kim property modify 1 key short-name");); + command("kim property modify 1 key short-name");); TEST_FAILURE(".*ERROR: There is no property instance to modify the content.*", - lmp->input->one("kim property modify 1 key short-name source-value 1 fcc");); + command("kim property modify 1 key short-name source-value 1 fcc");); TEST_FAILURE(".*ERROR: Invalid 'kim property remove' command.*", - lmp->input->one("kim property remove 1 key");); + command("kim property remove 1 key");); TEST_FAILURE(".*ERROR: There is no property instance to remove the content.*", - lmp->input->one("kim property remove 1 key short-name");); + command("kim property remove 1 key short-name");); TEST_FAILURE(".*ERROR: There is no property instance to dump the content.*", - lmp->input->one("kim property dump results.edn");); + command("kim property dump results.edn");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real"); - lmp->input->one("kim property create 1 cohesive-potential-energy-cubic-crystal"); - lmp->input->one("kim property modify 1 key short-name source-value 1 fcc"); - lmp->input->one("kim property destroy 1"); + command("clear"); + command("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real"); + command("kim property create 1 cohesive-potential-energy-cubic-crystal"); + command("kim property modify 1 key short-name source-value 1 fcc"); + command("kim property destroy 1"); if (!verbose) ::testing::internal::GetCapturedStdout(); #endif } @@ -492,264 +481,233 @@ TEST_F(KimCommandsTest, kim_query) { if (!LAMMPS::is_installed_pkg("KIM")) GTEST_SKIP(); - TEST_FAILURE(".*ERROR: Illegal 'kim query' command.*", - lmp->input->one("kim query");); + TEST_FAILURE(".*ERROR: Illegal 'kim query' command.*", command("kim query");); TEST_FAILURE(".*ERROR: Illegal 'kim query' command.\nThe keyword 'split' " "must be followed by the name of the query function.*", - lmp->input->one("kim query a0 split");); + command("kim query a0 split");); TEST_FAILURE(".*ERROR: Illegal 'kim query' command.\nThe keyword 'list' " "must be followed by the name of the query function.*", - lmp->input->one("kim query a0 list");); + command("kim query a0 list");); TEST_FAILURE(".*ERROR: Illegal 'kim query' command.\nThe keyword 'index' " "must be followed by the name of the query function.*", - lmp->input->one("kim query a0 index");); + command("kim query a0 index");); TEST_FAILURE(".*ERROR: Illegal 'kim query' command.\nThe 'list' keyword " "can not be used after 'split'.*", - lmp->input->one("kim query a0 split list");); + command("kim query a0 split list");); TEST_FAILURE(".*ERROR: Illegal 'kim query' command.\nThe 'index' keyword " "can not be used after 'split'.*", - lmp->input->one("kim query a0 split index");); + command("kim query a0 split index");); TEST_FAILURE(".*ERROR: Illegal 'kim query' command.\nThe 'split' keyword " "can not be used after 'list'.*", - lmp->input->one("kim query a0 list split");); + command("kim query a0 list split");); TEST_FAILURE(".*ERROR: Illegal 'kim query' command.\nThe 'index' keyword " "can not be used after 'list'.*", - lmp->input->one("kim query a0 list index");); + command("kim query a0 list index");); TEST_FAILURE(".*ERROR: Illegal 'kim query' command.\nThe 'list' keyword " "can not be used after 'index'.*", - lmp->input->one("kim query a0 index list");); + command("kim query a0 index list");); TEST_FAILURE(".*ERROR: Illegal 'kim query' command.\nThe 'split' keyword " "can not be used after 'index'.*", - lmp->input->one("kim query a0 index split");); + command("kim query a0 index split");); TEST_FAILURE(".*ERROR: Illegal query format.\nInput argument of `crystal` " "to 'kim query' is wrong. The query format is the " "keyword=\\[value\\], where value is always an array of one " "or more comma-separated items.*", - lmp->input->one("kim query a0 get_lattice_constant_cubic " - "crystal");); + command("kim query a0 get_lattice_constant_cubic " + "crystal");); TEST_FAILURE(".*ERROR: Illegal query format.\nInput argument of `" "crystal=fcc` to 'kim query' is wrong. The query format is the " "keyword=\\[value\\], where value is always an array of one " "or more comma-separated items.*", - lmp->input->one("kim query a0 get_lattice_constant_cubic " - "crystal=fcc");); + command("kim query a0 get_lattice_constant_cubic " + "crystal=fcc");); TEST_FAILURE(".*ERROR: Illegal query format.\nInput argument of `" "crystal=\\[fcc` to 'kim query' is wrong. The query format is " "the keyword=\\[value\\], where value is always an array of " "one or more comma-separated items.*", - lmp->input->one("kim query a0 get_lattice_constant_cubic " - "crystal=[fcc");); - TEST_FAILURE(".*ERROR: Illegal query format.\nInput argument of `" + command("kim query a0 get_lattice_constant_cubic " + "crystal=[fcc");); + TEST_FAILURE(".*ERROR: Illegal query format.\nInput argument of `" "crystal=fcc\\]` to 'kim query' is wrong. The query format is " "the keyword=\\[value\\], where value is always an array of " "one or more comma-separated items.*", - lmp->input->one("kim query a0 get_lattice_constant_cubic " - "crystal=fcc]");); + command("kim query a0 get_lattice_constant_cubic " + "crystal=fcc]");); - std::string squery("kim query a0 get_lattice_constant_cubic "); - squery += "crystal=[\"fcc\"] species=\"Al\",\"Ni\" units=[\"angstrom\"]"; + std::string squery = "kim query a0 get_lattice_constant_cubic " + "crystal=[\"fcc\"] species=\"Al\",\"Ni\" units=[\"angstrom\"]"; TEST_FAILURE(".*ERROR: Illegal query format.\nInput argument of `species=" "\"Al\",\"Ni\"` to 'kim query' is wrong. The query format is " "the keyword=\\[value\\], where value is always an array of " "one or more comma-separated items.*", - lmp->input->one(squery);); + command(squery);); - squery = "kim query a0 get_lattice_constant_cubic "; - squery += "crystal=[fcc] species=Al,Ni units=[angstrom]"; + squery = "kim query a0 get_lattice_constant_cubic crystal=[fcc] species=Al,Ni units=[angstrom]"; TEST_FAILURE(".*ERROR: Illegal query format.\nInput argument of `species=" "Al,Ni` to 'kim query' is wrong. The query format is " "the keyword=\\[value\\], where value is always an array of " "one or more comma-separated items.*", - lmp->input->one(squery);); + command(squery);); - squery = "kim query a0 get_lattice_constant_cubic "; - squery += "crystal=[fcc] species=Al,Ni, units=[angstrom]"; + squery = + "kim query a0 get_lattice_constant_cubic crystal=[fcc] species=Al,Ni, units=[angstrom]"; TEST_FAILURE(".*ERROR: Illegal query format.\nInput argument of `species=" "Al,Ni,` to 'kim query' is wrong. The query format is " "the keyword=\\[value\\], where value is always an array of " "one or more comma-separated items.*", - lmp->input->one(squery);); + command(squery);); - squery = "kim query a0 get_lattice_constant_cubic "; - squery += "crystal=[fcc] species=[Al,Ni, units=[angstrom]"; + squery = + "kim query a0 get_lattice_constant_cubic crystal=[fcc] species=[Al,Ni, units=[angstrom]"; TEST_FAILURE(".*ERROR: Illegal query format.\nInput argument of `species=" "\\[Al,Ni,` to 'kim query' is wrong. The query format is " "the keyword=\\[value\\], where value is always an array of " "one or more comma-separated items.*", - lmp->input->one(squery);); + command(squery);); - squery = "kim query a0 get_lattice_constant_cubic "; - squery += "crystal=[fcc] species=Al,Ni], units=[angstrom]"; + squery = + "kim query a0 get_lattice_constant_cubic crystal=[fcc] species=Al,Ni], units=[angstrom]"; TEST_FAILURE(".*ERROR: Illegal query format.\nInput argument of `species=" "Al,Ni\\],` to 'kim query' is wrong. The query format is " "the keyword=\\[value\\], where value is always an array of " "one or more comma-separated items.*", - lmp->input->one(squery);); + command(squery);); - squery = "kim query a0 get_lattice_constant_cubic "; - squery += "crystal=[fcc] species=Al,\"Ni\"], units=[angstrom]"; + squery = "kim query a0 get_lattice_constant_cubic crystal=[fcc] species=Al,\"Ni\"], " + "units=[angstrom]"; TEST_FAILURE(".*ERROR: Illegal query format.\nInput argument of `species=" "Al,\"Ni\"\\],` to 'kim query' is wrong. The query format is " "the keyword=\\[value\\], where value is always an array of " "one or more comma-separated items.*", - lmp->input->one(squery);); + command(squery);); - squery = "kim query a0 get_lattice_constant_cubic "; - squery += "crystal=[fcc] species=\"Al\",Ni], units=[angstrom]"; + squery = "kim query a0 get_lattice_constant_cubic crystal=[fcc] species=\"Al\",Ni], " + "units=[angstrom]"; TEST_FAILURE(".*ERROR: Illegal query format.\nInput argument of `species=" "\"Al\",Ni\\],` to 'kim query' is wrong. The query format is " "the keyword=\\[value\\], where value is always an array of " "one or more comma-separated items.*", - lmp->input->one(squery);); + command(squery);); - squery = "kim query a0 get_lattice_constant_cubic crystal=[\"fcc\"] " - "species=[\"Al\"]"; + squery = "kim query a0 get_lattice_constant_cubic crystal=[\"fcc\"] species=[\"Al\"]"; TEST_FAILURE(".*ERROR: Illegal query format.\nMust use 'kim init' before " "'kim query' or must provide the model name after query " "function with the format of 'model=\\[model_name\\]'.*", - lmp->input->one(squery);); + command(squery);); - squery = "kim query a0 get_lattice_constant_cubic crystal=[fcc] " - "species=[Al]"; + squery = "kim query a0 get_lattice_constant_cubic crystal=[fcc] species=[Al]"; TEST_FAILURE(".*ERROR: Illegal query format.\nMust use 'kim init' before " "'kim query' or must provide the model name after query " "function with the format of 'model=\\[model_name\\]'.*", - lmp->input->one(squery);); + command(squery);); - squery = "kim query a0 get_lattice_constant_cubic crystal=[\"fcc\"] " - "species=[Al]"; + squery = "kim query a0 get_lattice_constant_cubic crystal=[\"fcc\"] species=[Al]"; TEST_FAILURE(".*ERROR: Illegal query format.\nMust use 'kim init' before " "'kim query' or must provide the model name after query " "function with the format of 'model=\\[model_name\\]'.*", - lmp->input->one(squery);); + command(squery);); #if defined(KIM_EXTRA_UNITTESTS) if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - - squery = "kim query latconst_1 get_lattice_constant_cubic "; - squery += "crystal=[fcc] species=[Al] units=[angstrom] "; - squery += "model=[EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005]"; - lmp->input->one(squery); + command("clear"); + command("kim query latconst_1 get_lattice_constant_cubic " + "crystal=[fcc] species=[Al] units=[angstrom] " + "model=[EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005]"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE((std::string(lmp->input->variable->retrieve("latconst_1")) == - "4.032082033157349")); + ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("4.032082033157349")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal"); + command("clear"); + command("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal"); + command("kim query latconst_1 get_lattice_constant_cubic crystal=[fcc] species=[Al] " + "units=[angstrom]"); - squery = "kim query latconst_1 get_lattice_constant_cubic "; - squery += "crystal=[fcc] species=[Al] units=[angstrom]"; - lmp->input->one(squery); - - squery = "kim query latconst_2 get_lattice_constant_cubic "; - squery += "crystal=[fcc] species=[Al] units=[angstrom] "; - squery += "model=[LennardJones612_UniversalShifted__MO_959249795837_003]"; - lmp->input->one(squery); + command("kim query latconst_2 get_lattice_constant_cubic crystal=[fcc] species=[Al] " + "units=[angstrom] " + "model=[LennardJones612_UniversalShifted__MO_959249795837_003]"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE((std::string(lmp->input->variable->retrieve("latconst_1")) == - "4.032082033157349")); - ASSERT_TRUE((std::string(lmp->input->variable->retrieve("latconst_2")) == - "3.328125931322575")); + ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("4.032082033157349")); + ASSERT_THAT(variable->retrieve("latconst_2"), StrEq("3.328125931322575")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000 metal"); + command("clear"); + command("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000 metal"); - squery = "kim query latconst split get_lattice_constant_hexagonal "; - squery += "crystal=[hcp] species=[Zr] units=[angstrom]"; - lmp->input->one(squery); + command("kim query latconst split get_lattice_constant_hexagonal crystal=[hcp] species=[Zr] " + "units=[angstrom]"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE((std::string(lmp->input->variable->retrieve("latconst_1")) == - "3.234055244384789")); - ASSERT_TRUE((std::string(lmp->input->variable->retrieve("latconst_2")) == - "5.167650199630013")); + ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("3.234055244384789")); + ASSERT_THAT(variable->retrieve("latconst_2"), StrEq("5.167650199630013")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); + command("clear"); - squery = "kim query latconst index get_lattice_constant_hexagonal "; - squery += "crystal=[hcp] species=[Zr] units=[angstrom] "; - squery += "model=[EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000]"; - lmp->input->one(squery); + command("kim query latconst index get_lattice_constant_hexagonal " + "crystal=[hcp] species=[Zr] units=[angstrom] " + "model=[EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000]"); if (!verbose) ::testing::internal::GetCapturedStdout(); - - ASSERT_TRUE((std::string(lmp->input->variable->retrieve("latconst")) == - "3.234055244384789")); + ASSERT_THAT(variable->retrieve("latconst"), StrEq("3.234055244384789")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("variable latconst delete"); - lmp->input->one("clear"); - lmp->input->one("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000 metal"); + command("variable latconst delete"); + command("clear"); + command("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000 metal"); - squery = "kim query latconst list get_lattice_constant_hexagonal "; - squery += "crystal=[hcp] species=[Zr] units=[angstrom]"; - lmp->input->one(squery); + command("kim query latconst list get_lattice_constant_hexagonal crystal=[hcp] species=[Zr] " + "units=[angstrom]"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE((std::string(lmp->input->variable->retrieve("latconst")) == - "3.234055244384789 5.167650199630013")); + ASSERT_THAT(variable->retrieve("latconst"), StrEq("3.234055244384789 5.167650199630013")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal"); + command("clear"); + command("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal"); - squery = "kim query alpha get_linear_thermal_expansion_coefficient_cubic "; - squery += "crystal=[fcc] species=[Al] units=[1/K] temperature=[293.15] "; - squery += "temperature_units=[K]"; - lmp->input->one(squery); + command("kim query alpha get_linear_thermal_expansion_coefficient_cubic " + "crystal=[fcc] species=[Al] units=[1/K] temperature=[293.15] " + "temperature_units=[K]"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_TRUE((std::string(lmp->input->variable->retrieve("alpha")) == - "1.654960564704273e-05")); + ASSERT_THAT(variable->retrieve("alpha"), StrEq("1.654960564704273e-05")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); + command("clear"); - squery = "kim query model_list list get_available_models "; - squery += "species=[Al]"; - lmp->input->one(squery); + command("kim query model_list list get_available_models species=[Al]"); if (!verbose) ::testing::internal::GetCapturedStdout(); - std::string model_list = lmp->input->variable->retrieve("model_list"); + std::string model_list = variable->retrieve("model_list"); auto n = model_list.find("EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005"); ASSERT_TRUE(n != std::string::npos); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); + command("clear"); - squery = "kim query model_name index get_available_models "; - squery += "species=[Al]"; - lmp->input->one(squery); - lmp->input->one("variable model_name delete"); + command("kim query model_name index get_available_models species=[Al]"); + command("variable model_name delete"); if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); + command("clear"); - squery = "kim query model_name index get_available_models "; - squery += "species=[Al] potential_type=[eam,meam]"; - lmp->input->one(squery); - lmp->input->one("variable model_name delete"); + command("kim query model_name index get_available_models " + "species=[Al] potential_type=[eam,meam]"); + command("variable model_name delete"); - squery = "kim query model_name index get_available_models "; - squery += "species=[Al] potential_type=[\"eam\",\"meam\"]"; - lmp->input->one(squery); - lmp->input->one("variable model_name delete"); + command("kim query model_name index get_available_models " + "species=[Al] potential_type=[\"eam\",\"meam\"]"); + command("variable model_name delete"); - squery = "kim query model_name index get_available_models "; - squery += "species=[Al] potential_type=[eam,\"meam\"]"; - lmp->input->one(squery); - lmp->input->one("variable model_name delete"); + command("kim query model_name index get_available_models " + "species=[Al] potential_type=[eam,\"meam\"]"); + command("variable model_name delete"); - squery = "kim query model_name index get_available_models "; - squery += "species=[Al] potential_type=[\"eam\",meam]"; - lmp->input->one(squery); - lmp->input->one("variable model_name delete"); + command("kim query model_name index get_available_models " + "species=[Al] potential_type=[\"eam\",meam]"); + command("variable model_name delete"); if (!verbose) ::testing::internal::GetCapturedStdout(); #endif } diff --git a/unittest/commands/test_lattice_region.cpp b/unittest/commands/test_lattice_region.cpp index b359c90c75..2924c75d9f 100644 --- a/unittest/commands/test_lattice_region.cpp +++ b/unittest/commands/test_lattice_region.cpp @@ -81,12 +81,14 @@ protected: delete lmp; if (!verbose) ::testing::internal::GetCapturedStdout(); } + + void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(LatticeRegionTest, lattice_none) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice none 2.0"); + command("lattice none 2.0"); if (!verbose) ::testing::internal::GetCapturedStdout(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::NONE); @@ -96,14 +98,14 @@ TEST_F(LatticeRegionTest, lattice_none) ASSERT_EQ(lattice->nbasis, 0); ASSERT_EQ(lattice->basis, nullptr); - TEST_FAILURE(".*ERROR: Illegal lattice command.*", lmp->input->one("lattice");); - TEST_FAILURE(".*ERROR: Illegal lattice command.*", lmp->input->one("lattice xxx");); - TEST_FAILURE(".*ERROR: Illegal lattice command.*", lmp->input->one("lattice none 1.0 origin");); - TEST_FAILURE(".*ERROR: Expected floating point.*", lmp->input->one("lattice none xxx");); + TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice");); + TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice xxx");); + TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice none 1.0 origin");); + TEST_FAILURE(".*ERROR: Expected floating point.*", command("lattice none xxx");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units lj"); - lmp->input->one("lattice none 1.0"); + command("units lj"); + command("lattice none 1.0"); if (!verbose) ::testing::internal::GetCapturedStdout(); lattice = lmp->domain->lattice; ASSERT_EQ(lattice->xlattice, 1.0); @@ -114,7 +116,7 @@ TEST_F(LatticeRegionTest, lattice_none) TEST_F(LatticeRegionTest, lattice_sc) { ::testing::internal::CaptureStdout(); - lmp->input->one("lattice sc 1.0 spacing 1.5 2.0 3.0"); + command("lattice sc 1.0 spacing 1.5 2.0 3.0"); auto output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; ASSERT_THAT(output, MatchesRegex(".*Lattice spacing in x,y,z = 1.50* 2.0* 3.0*.*")); @@ -125,7 +127,7 @@ TEST_F(LatticeRegionTest, lattice_sc) ASSERT_EQ(lattice->zlattice, 3.0); ::testing::internal::CaptureStdout(); - lmp->input->one("lattice sc 2.0"); + command("lattice sc 2.0"); output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; ASSERT_THAT(output, MatchesRegex(".*Lattice spacing in x,y,z = 2.0* 2.0* 2.0*.*")); @@ -151,25 +153,24 @@ TEST_F(LatticeRegionTest, lattice_sc) ASSERT_EQ(lattice->basis[0][2], 0.0); TEST_FAILURE(".*ERROR: Illegal lattice command.*", - lmp->input->one("lattice sc 1.0 origin 1.0 1.0 1.0");); + command("lattice sc 1.0 origin 1.0 1.0 1.0");); + TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice sc 1.0 origin 1.0");); TEST_FAILURE(".*ERROR: Illegal lattice command.*", - lmp->input->one("lattice sc 1.0 origin 1.0");); - TEST_FAILURE(".*ERROR: Illegal lattice command.*", - lmp->input->one("lattice sc 1.0 origin 0.0 0.0 0.0 xxx");); + command("lattice sc 1.0 origin 0.0 0.0 0.0 xxx");); TEST_FAILURE(".*ERROR: Expected floating point.*", - lmp->input->one("lattice sc 1.0 origin xxx 1.0 1.0");); + command("lattice sc 1.0 origin xxx 1.0 1.0");); TEST_FAILURE(".*ERROR: Lattice orient vectors are not orthogonal.*", - lmp->input->one("lattice sc 1.0 orient x 2 2 0");); + command("lattice sc 1.0 orient x 2 2 0");); TEST_FAILURE(".*ERROR: Lattice orient vectors are not right-handed.*", - lmp->input->one("lattice sc 1.0 orient y 0 -1 0");); + command("lattice sc 1.0 orient y 0 -1 0");); TEST_FAILURE(".*ERROR: Lattice spacings are invalid.*", - lmp->input->one("lattice sc 1.0 spacing 0.0 1.0 1.0");); + command("lattice sc 1.0 spacing 0.0 1.0 1.0");); TEST_FAILURE(".*ERROR: Lattice spacings are invalid.*", - lmp->input->one("lattice sc 1.0 spacing 1.0 -0.1 1.0");); + command("lattice sc 1.0 spacing 1.0 -0.1 1.0");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units lj"); - lmp->input->one("lattice sc 2.0"); + command("units lj"); + command("lattice sc 2.0"); if (!verbose) ::testing::internal::GetCapturedStdout(); lattice = lmp->domain->lattice; ASSERT_DOUBLE_EQ(lattice->xlattice, pow(0.5, 1.0 / 3.0)); @@ -177,16 +178,16 @@ TEST_F(LatticeRegionTest, lattice_sc) ASSERT_DOUBLE_EQ(lattice->zlattice, pow(0.5, 1.0 / 3.0)); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("dimension 2"); + command("dimension 2"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", - lmp->input->one("lattice sc 1.0");); + command("lattice sc 1.0");); } TEST_F(LatticeRegionTest, lattice_bcc) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice bcc 4.2 orient x 1 1 0 orient y -1 1 0"); + command("lattice bcc 4.2 orient x 1 1 0 orient y -1 1 0"); if (!verbose) ::testing::internal::GetCapturedStdout(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::BCC); @@ -202,16 +203,16 @@ TEST_F(LatticeRegionTest, lattice_bcc) ASSERT_EQ(lattice->basis[1][2], 0.5); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("dimension 2"); + command("dimension 2"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", - lmp->input->one("lattice bcc 1.0");); + command("lattice bcc 1.0");); } TEST_F(LatticeRegionTest, lattice_fcc) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice fcc 3.5 origin 0.5 0.5 0.5"); + command("lattice fcc 3.5 origin 0.5 0.5 0.5"); if (!verbose) ::testing::internal::GetCapturedStdout(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::FCC); @@ -233,23 +234,22 @@ TEST_F(LatticeRegionTest, lattice_fcc) ASSERT_EQ(lattice->basis[3][2], 0.5); TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*", - lmp->input->one("lattice fcc 1.0 basis 0.0 0.0 0.0");); + command("lattice fcc 1.0 basis 0.0 0.0 0.0");); TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*", - lmp->input->one("lattice fcc 1.0 a1 0.0 1.0 0.0");); - TEST_FAILURE(".*ERROR: Illegal lattice command.*", - lmp->input->one("lattice fcc 1.0 orient w 1 0 0");); + command("lattice fcc 1.0 a1 0.0 1.0 0.0");); + TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice fcc 1.0 orient w 1 0 0");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("dimension 2"); + command("dimension 2"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", - lmp->input->one("lattice fcc 1.0");); + command("lattice fcc 1.0");); } TEST_F(LatticeRegionTest, lattice_hcp) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice hcp 3.0 orient z 0 0 1"); + command("lattice hcp 3.0 orient z 0 0 1"); if (!verbose) ::testing::internal::GetCapturedStdout(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::HCP); @@ -280,20 +280,20 @@ TEST_F(LatticeRegionTest, lattice_hcp) ASSERT_DOUBLE_EQ(lattice->a3[2], sqrt(8.0 / 3.0)); TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*", - lmp->input->one("lattice hcp 1.0 a2 0.0 1.0 0.0");); + command("lattice hcp 1.0 a2 0.0 1.0 0.0");); TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*", - lmp->input->one("lattice hcp 1.0 a3 0.0 1.0 0.0");); + command("lattice hcp 1.0 a3 0.0 1.0 0.0");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("dimension 2"); + command("dimension 2"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", - lmp->input->one("lattice hcp 1.0");); + command("lattice hcp 1.0");); } TEST_F(LatticeRegionTest, lattice_diamond) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice diamond 4.1 orient x 1 1 2 orient y -1 1 0 orient z -1 -1 1"); + command("lattice diamond 4.1 orient x 1 1 2 orient y -1 1 0 orient z -1 -1 1"); if (!verbose) ::testing::internal::GetCapturedStdout(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::DIAMOND); @@ -336,17 +336,17 @@ TEST_F(LatticeRegionTest, lattice_diamond) ASSERT_EQ(lattice->a3[2], 1.0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("dimension 2"); + command("dimension 2"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", - lmp->input->one("lattice diamond 1.0");); + command("lattice diamond 1.0");); } TEST_F(LatticeRegionTest, lattice_sq) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("dimension 2"); - lmp->input->one("lattice sq 3.0"); + command("dimension 2"); + command("lattice sq 3.0"); if (!verbose) ::testing::internal::GetCapturedStdout(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::SQ); @@ -358,22 +358,21 @@ TEST_F(LatticeRegionTest, lattice_sq) ASSERT_EQ(lattice->basis[0][1], 0.0); ASSERT_EQ(lattice->basis[0][2], 0.0); - TEST_FAILURE( - ".*ERROR: Lattice settings are not compatible with 2d simulation.*", - lmp->input->one("lattice sq 1.0 orient x 1 1 2 orient y -1 1 0 orient z -1 -1 1");); + TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*", + command("lattice sq 1.0 orient x 1 1 2 orient y -1 1 0 orient z -1 -1 1");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("dimension 3"); + command("dimension 3"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", - lmp->input->one("lattice sq 1.0");); + command("lattice sq 1.0");); } TEST_F(LatticeRegionTest, lattice_sq2) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("dimension 2"); - lmp->input->one("lattice sq2 2.0"); + command("dimension 2"); + command("lattice sq2 2.0"); if (!verbose) ::testing::internal::GetCapturedStdout(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::SQ2); @@ -389,17 +388,17 @@ TEST_F(LatticeRegionTest, lattice_sq2) ASSERT_EQ(lattice->basis[1][2], 0.0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("dimension 3"); + command("dimension 3"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", - lmp->input->one("lattice sq2 1.0");); + command("lattice sq2 1.0");); } TEST_F(LatticeRegionTest, lattice_hex) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("dimension 2"); - lmp->input->one("lattice hex 2.0"); + command("dimension 2"); + command("lattice hex 2.0"); if (!verbose) ::testing::internal::GetCapturedStdout(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::HEX); @@ -424,32 +423,32 @@ TEST_F(LatticeRegionTest, lattice_hex) ASSERT_EQ(lattice->a3[2], 1.0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("dimension 3"); + command("dimension 3"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", - lmp->input->one("lattice hex 1.0");); + command("lattice hex 1.0");); } TEST_F(LatticeRegionTest, lattice_custom) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("variable a equal 4.34"); - lmp->input->one("variable b equal $a*sqrt(3.0)"); - lmp->input->one("variable c equal $a*sqrt(8.0/3.0)"); - lmp->input->one("variable t equal 1.0/3.0"); - lmp->input->one("variable f equal 5.0/6.0"); - lmp->input->one("lattice custom 1.0 " - "a1 $a 0.0 0.0 " - "a2 0.0 $b 0.0 " - "a3 0.0 0.0 $c " - "basis 0.0 0.0 0.0 " - "basis 0.5 0.5 0.0 " - "basis $t 0.0 0.5 " - "basis $f 0.5 0.5 " - "basis 0.0 0.0 0.625 " - "basis 0.5 0.5 0.625 " - "basis $t 0.0 0.125 " - "basis $f 0.5 0.125 "); + command("variable a equal 4.34"); + command("variable b equal $a*sqrt(3.0)"); + command("variable c equal $a*sqrt(8.0/3.0)"); + command("variable t equal 1.0/3.0"); + command("variable f equal 5.0/6.0"); + command("lattice custom 1.0 " + "a1 $a 0.0 0.0 " + "a2 0.0 $b 0.0 " + "a3 0.0 0.0 $c " + "basis 0.0 0.0 0.0 " + "basis 0.5 0.5 0.0 " + "basis $t 0.0 0.5 " + "basis $f 0.5 0.5 " + "basis 0.0 0.0 0.625 " + "basis 0.5 0.5 0.625 " + "basis $t 0.0 0.125 " + "basis $f 0.5 0.125 "); if (!verbose) ::testing::internal::GetCapturedStdout(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::CUSTOM); @@ -492,47 +491,47 @@ TEST_F(LatticeRegionTest, lattice_custom) ASSERT_DOUBLE_EQ(lattice->a3[2], 4.34 * sqrt(8.0 / 3.0)); TEST_FAILURE(".*ERROR: Illegal lattice command.*", - lmp->input->one("lattice custom 1.0 basis -0.1 0 0");); + command("lattice custom 1.0 basis -0.1 0 0");); TEST_FAILURE(".*ERROR: Illegal lattice command.*", - lmp->input->one("lattice custom 1.0 basis 0.0 1.0 0");); + command("lattice custom 1.0 basis 0.0 1.0 0");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("dimension 2"); + command("dimension 2"); if (!verbose) ::testing::internal::GetCapturedStdout(); - TEST_FAILURE(".*ERROR: No basis atoms in lattice.*", lmp->input->one("lattice custom 1.0");); + TEST_FAILURE(".*ERROR: No basis atoms in lattice.*", command("lattice custom 1.0");); TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*", - lmp->input->one("lattice custom 1.0 origin 0.5 0.5 0.5 basis 0.0 0.0 0.0");); + command("lattice custom 1.0 origin 0.5 0.5 0.5 basis 0.0 0.0 0.0");); TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*", - lmp->input->one("lattice custom 1.0 a1 1.0 1.0 1.0 basis 0.0 0.0 0.0");); + command("lattice custom 1.0 a1 1.0 1.0 1.0 basis 0.0 0.0 0.0");); TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*", - lmp->input->one("lattice custom 1.0 a2 1.0 1.0 1.0 basis 0.0 0.0 0.0");); + command("lattice custom 1.0 a2 1.0 1.0 1.0 basis 0.0 0.0 0.0");); TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*", - lmp->input->one("lattice custom 1.0 a3 1.0 1.0 1.0 basis 0.0 0.0 0.0");); + command("lattice custom 1.0 a3 1.0 1.0 1.0 basis 0.0 0.0 0.0");); } TEST_F(LatticeRegionTest, region_fail) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice none 2.0"); - lmp->input->one("region box block 0 1 0 1 0 1"); + command("lattice none 2.0"); + command("region box block 0 1 0 1 0 1"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Create_atoms command before simulation box is defined.*", - lmp->input->one("create_atoms 1 box");); + command("create_atoms 1 box");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("create_box 1 box"); + command("create_box 1 box"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR: Cannot create atoms with undefined lattice.*", - lmp->input->one("create_atoms 1 box");); + command("create_atoms 1 box");); } TEST_F(LatticeRegionTest, region_block_lattice) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice sc 1.5"); - lmp->input->one("region box block 0 2 0 2 0 2 units lattice"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 box"); + command("lattice sc 1.5"); + command("region box block 0 2 0 2 0 2 units lattice"); + command("create_box 1 box"); + command("create_atoms 1 box"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->domain->triclinic, 0); @@ -555,10 +554,10 @@ TEST_F(LatticeRegionTest, region_block_lattice) TEST_F(LatticeRegionTest, region_block_box) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice sc 1.5 origin 0.75 0.75 0.75"); - lmp->input->one("region box block 0 2 0 2 0 2 units box"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 box"); + command("lattice sc 1.5 origin 0.75 0.75 0.75"); + command("region box block 0 2 0 2 0 2 units box"); + command("create_box 1 box"); + command("create_atoms 1 box"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->domain->triclinic, 0); @@ -572,11 +571,11 @@ TEST_F(LatticeRegionTest, region_block_box) TEST_F(LatticeRegionTest, region_cone) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice fcc 2.5 origin 0.5 0.5 0.5"); - lmp->input->one("region box cone x 1.0 1.0 0.5 2.1 0.0 2.0"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 region box"); - lmp->input->one("write_dump all atom init.lammpstrj"); + command("lattice fcc 2.5 origin 0.5 0.5 0.5"); + command("region box cone x 1.0 1.0 0.5 2.1 0.0 2.0"); + command("create_box 1 box"); + command("create_atoms 1 region box"); + command("write_dump all atom init.lammpstrj"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 42); @@ -585,10 +584,10 @@ TEST_F(LatticeRegionTest, region_cone) TEST_F(LatticeRegionTest, region_cylinder) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice fcc 2.5 origin 0.5 0.5 0.5"); - lmp->input->one("region box cylinder z 1.0 1.0 2.1 0.0 2.0 "); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 region box"); + command("lattice fcc 2.5 origin 0.5 0.5 0.5"); + command("region box cylinder z 1.0 1.0 2.1 0.0 2.0 "); + command("create_box 1 box"); + command("create_atoms 1 region box"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 114); @@ -597,10 +596,10 @@ TEST_F(LatticeRegionTest, region_cylinder) TEST_F(LatticeRegionTest, region_prism) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice bcc 2.5 origin 0.75 0.75 0.75"); - lmp->input->one("region box prism 0 2 0 2 0 2 0.5 0.0 0.0"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 box"); + command("lattice bcc 2.5 origin 0.75 0.75 0.75"); + command("region box prism 0 2 0 2 0 2 0.5 0.0 0.0"); + command("create_box 1 box"); + command("create_atoms 1 box"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->domain->triclinic, 1); ASSERT_EQ(lmp->atom->natoms, 16); @@ -609,10 +608,10 @@ TEST_F(LatticeRegionTest, region_prism) TEST_F(LatticeRegionTest, region_sphere) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice fcc 2.5 origin 0.5 0.5 0.5"); - lmp->input->one("region box sphere 1.0 1.0 1.0 1.1"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 region box"); + command("lattice fcc 2.5 origin 0.5 0.5 0.5"); + command("region box sphere 1.0 1.0 1.0 1.1"); + command("create_box 1 box"); + command("create_atoms 1 region box"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 14); @@ -621,12 +620,12 @@ TEST_F(LatticeRegionTest, region_sphere) TEST_F(LatticeRegionTest, region_union) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice fcc 2.5 origin 0.5 0.5 0.5"); - lmp->input->one("region part1 sphere 2.0 1.0 1.0 1.1"); - lmp->input->one("region part2 block 0.0 2.0 0.0 2.0 0.0 2.0"); - lmp->input->one("region box union 2 part1 part2"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 region box"); + command("lattice fcc 2.5 origin 0.5 0.5 0.5"); + command("region part1 sphere 2.0 1.0 1.0 1.1"); + command("region part2 block 0.0 2.0 0.0 2.0 0.0 2.0"); + command("region box union 2 part1 part2"); + command("create_box 1 box"); + command("create_atoms 1 region box"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 67); @@ -635,12 +634,12 @@ TEST_F(LatticeRegionTest, region_union) TEST_F(LatticeRegionTest, region_intersect) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice fcc 2.5 origin 0.5 0.5 0.5"); - lmp->input->one("region part1 sphere 2.0 1.0 1.0 1.8"); - lmp->input->one("region part2 block 0.0 2.0 0.0 2.0 0.0 2.0"); - lmp->input->one("region box intersect 2 part1 part2"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 region box"); + command("lattice fcc 2.5 origin 0.5 0.5 0.5"); + command("region part1 sphere 2.0 1.0 1.0 1.8"); + command("region part2 block 0.0 2.0 0.0 2.0 0.0 2.0"); + command("region box intersect 2 part1 part2"); + command("create_box 1 box"); + command("create_atoms 1 region box"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 21); @@ -649,14 +648,14 @@ TEST_F(LatticeRegionTest, region_intersect) TEST_F(LatticeRegionTest, region_plane) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("lattice fcc 2.5 origin 0.5 0.5 0.5"); - lmp->input->one("region box block 0.0 2.0 0.0 2.0 0.0 2.0"); - lmp->input->one("region part1 plane 0.5 1.0 0.0 0.75 0.0 0.0"); - lmp->input->one("region part2 plane 1.5 1.0 0.0 0.75 0.0 0.0 side out"); - lmp->input->one("region atoms intersect 2 part1 part2"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 region atoms"); - lmp->input->one("write_dump all atom init.lammpstrj"); + command("lattice fcc 2.5 origin 0.5 0.5 0.5"); + command("region box block 0.0 2.0 0.0 2.0 0.0 2.0"); + command("region part1 plane 0.5 1.0 0.0 0.75 0.0 0.0"); + command("region part2 plane 1.5 1.0 0.0 0.75 0.0 0.0 side out"); + command("region atoms intersect 2 part1 part2"); + command("create_box 1 box"); + command("create_atoms 1 region atoms"); + command("write_dump all atom init.lammpstrj"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 16); diff --git a/unittest/commands/test_reset_ids.cpp b/unittest/commands/test_reset_ids.cpp index 3ea2f26cef..89e09b53a6 100644 --- a/unittest/commands/test_reset_ids.cpp +++ b/unittest/commands/test_reset_ids.cpp @@ -85,6 +85,8 @@ protected: delete lmp; if (!verbose) ::testing::internal::GetCapturedStdout(); } + + void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(ResetIDsTest, MolIDAll) @@ -125,7 +127,7 @@ TEST_F(ResetIDsTest, MolIDAll) // the original data file has two different molecule IDs // for two residues of the same molecule/fragment. if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("reset_mol_ids all"); + command("reset_mol_ids all"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(molid[GETIDX(1)], 1); @@ -167,10 +169,10 @@ TEST_F(ResetIDsTest, DeletePlusAtomID) // delete two water molecules if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("group allwater molecule 3:6"); - lmp->input->one("group twowater molecule 4:6:2"); - lmp->input->one("delete_atoms group twowater compress no bond yes"); - lmp->input->one("reset_mol_ids all"); + command("group allwater molecule 3:6"); + command("group twowater molecule 4:6:2"); + command("delete_atoms group twowater compress no bond yes"); + command("reset_mol_ids all"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->atom->natoms, 23); ASSERT_EQ(lmp->atom->map_tag_max, 26); @@ -229,7 +231,7 @@ TEST_F(ResetIDsTest, DeletePlusAtomID) ASSERT_GE(GETIDX(26), 0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("reset_atom_ids"); + command("reset_atom_ids"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->atom->map_tag_max, 23); @@ -245,9 +247,9 @@ TEST_F(ResetIDsTest, PartialOffset) // delete two water molecules if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("group allwater molecule 3:6"); - lmp->input->one("group nowater subtract all allwater"); - lmp->input->one("reset_mol_ids allwater offset 4"); + command("group allwater molecule 3:6"); + command("group nowater subtract all allwater"); + command("reset_mol_ids allwater offset 4"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->atom->natoms, 29); ASSERT_EQ(lmp->atom->map_tag_max, 29); @@ -283,7 +285,7 @@ TEST_F(ResetIDsTest, PartialOffset) ASSERT_EQ(molid[GETIDX(29)], 8); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("reset_mol_ids nowater offset 0"); + command("reset_mol_ids nowater offset 0"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(molid[GETIDX(1)], 1); @@ -325,11 +327,11 @@ TEST_F(ResetIDsTest, DeleteAdd) // delete two water molecules if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("group allwater molecule 3:6"); - lmp->input->one("group twowater molecule 4:6:2"); - lmp->input->one("group nowater subtract all allwater"); - lmp->input->one("delete_atoms group twowater compress no bond yes mol yes"); - lmp->input->one("reset_mol_ids allwater"); + command("group allwater molecule 3:6"); + command("group twowater molecule 4:6:2"); + command("group nowater subtract all allwater"); + command("delete_atoms group twowater compress no bond yes mol yes"); + command("reset_mol_ids allwater"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->atom->natoms, 23); ASSERT_EQ(lmp->atom->map_tag_max, 26); @@ -388,7 +390,7 @@ TEST_F(ResetIDsTest, DeleteAdd) ASSERT_GE(GETIDX(26), 0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("reset_atom_ids sort yes"); + command("reset_atom_ids sort yes"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->atom->map_tag_max, 23); @@ -396,7 +398,7 @@ TEST_F(ResetIDsTest, DeleteAdd) ASSERT_GE(GETIDX(i), 0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("reset_mol_ids nowater offset 1"); + command("reset_mol_ids nowater offset 1"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(molid[GETIDX(1)], 2); @@ -424,11 +426,11 @@ TEST_F(ResetIDsTest, DeleteAdd) ASSERT_EQ(molid[GETIDX(23)], 4); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("create_atoms 1 single 0.0 0.0 0.0"); - lmp->input->one("create_atoms 2 single 1.0 0.0 0.0"); - lmp->input->one("create_atoms 3 single 2.0 0.0 0.0"); - lmp->input->one("create_atoms 4 single 3.0 0.0 0.0"); - lmp->input->one("reset_mol_ids all single yes"); + command("create_atoms 1 single 0.0 0.0 0.0"); + command("create_atoms 2 single 1.0 0.0 0.0"); + command("create_atoms 3 single 2.0 0.0 0.0"); + command("create_atoms 4 single 3.0 0.0 0.0"); + command("reset_mol_ids all single yes"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->atom->natoms, 27); ASSERT_EQ(lmp->atom->map_tag_max, 27); @@ -442,7 +444,7 @@ TEST_F(ResetIDsTest, DeleteAdd) ASSERT_EQ(molid[GETIDX(27)], 7); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("reset_mol_ids all single no"); + command("reset_mol_ids all single no"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(molid[GETIDX(21)], 3); @@ -454,7 +456,7 @@ TEST_F(ResetIDsTest, DeleteAdd) ASSERT_EQ(molid[GETIDX(27)], 0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("reset_mol_ids all compress no single yes"); + command("reset_mol_ids all compress no single yes"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(molid[GETIDX(21)], 21); @@ -472,20 +474,20 @@ TEST_F(ResetIDsTest, TopologyData) // delete two water molecules if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("group allwater molecule 3:6"); - lmp->input->one("group twowater molecule 4:6:2"); - lmp->input->one("group nowater subtract all allwater"); - lmp->input->one("delete_atoms group twowater compress no bond yes mol yes"); + command("group allwater molecule 3:6"); + command("group twowater molecule 4:6:2"); + command("group nowater subtract all allwater"); + command("delete_atoms group twowater compress no bond yes mol yes"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->atom->natoms, 23); ASSERT_EQ(lmp->atom->map_tag_max, 26); - auto num_bond = lmp->atom->num_bond; - auto num_angle = lmp->atom->num_angle; - auto bond_atom = lmp->atom->bond_atom; - auto angle_atom1 = lmp->atom->angle_atom1; - auto angle_atom2 = lmp->atom->angle_atom2; - auto angle_atom3 = lmp->atom->angle_atom3; + auto num_bond = lmp->atom->num_bond; + auto num_angle = lmp->atom->num_angle; + auto bond_atom = lmp->atom->bond_atom; + auto angle_atom1 = lmp->atom->angle_atom1; + auto angle_atom2 = lmp->atom->angle_atom2; + auto angle_atom3 = lmp->atom->angle_atom3; ASSERT_EQ(num_bond[GETIDX(1)], 2); ASSERT_EQ(bond_atom[GETIDX(1)][0], 2); ASSERT_EQ(bond_atom[GETIDX(1)][1], 3); @@ -561,15 +563,15 @@ TEST_F(ResetIDsTest, TopologyData) ASSERT_EQ(angle_atom3[GETIDX(24)][0], 26); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("reset_atom_ids sort yes"); + command("reset_atom_ids sort yes"); if (!verbose) ::testing::internal::GetCapturedStdout(); - num_bond = lmp->atom->num_bond; - num_angle = lmp->atom->num_angle; - bond_atom = lmp->atom->bond_atom; - angle_atom1 = lmp->atom->angle_atom1; - angle_atom2 = lmp->atom->angle_atom2; - angle_atom3 = lmp->atom->angle_atom3; + num_bond = lmp->atom->num_bond; + num_angle = lmp->atom->num_angle; + bond_atom = lmp->atom->bond_atom; + angle_atom1 = lmp->atom->angle_atom1; + angle_atom2 = lmp->atom->angle_atom2; + angle_atom3 = lmp->atom->angle_atom3; ASSERT_EQ(num_bond[GETIDX(1)], 2); ASSERT_EQ(bond_atom[GETIDX(1)][0], 3); ASSERT_EQ(bond_atom[GETIDX(1)][1], 2); @@ -658,26 +660,23 @@ TEST_F(ResetIDsTest, DeathTests) { if (lmp->atom->natoms == 0) GTEST_SKIP(); - TEST_FAILURE(".*ERROR: Illegal reset_mol_ids command.*", lmp->input->one("reset_mol_ids");); + TEST_FAILURE(".*ERROR: Illegal reset_mol_ids command.*", command("reset_mol_ids");); TEST_FAILURE(".*ERROR: Illegal reset_mol_ids command.*", - lmp->input->one("reset_mol_ids all offset 1 1");); + command("reset_mol_ids all offset 1 1");); TEST_FAILURE(".*ERROR: Illegal reset_mol_ids command.*", - lmp->input->one("reset_mol_ids all offset -2");); + command("reset_mol_ids all offset -2");); + TEST_FAILURE(".*ERROR on proc 0: Expected integer.*", command("reset_mol_ids all offset xxx");); TEST_FAILURE(".*ERROR on proc 0: Expected integer.*", - lmp->input->one("reset_mol_ids all offset xxx");); - TEST_FAILURE(".*ERROR on proc 0: Expected integer.*", - lmp->input->one("reset_mol_ids all compress yes single no offset xxx");); + command("reset_mol_ids all compress yes single no offset xxx");); + TEST_FAILURE(".*ERROR: Illegal reset_mol_ids command.*", command("reset_mol_ids all offset");); TEST_FAILURE(".*ERROR: Illegal reset_mol_ids command.*", - lmp->input->one("reset_mol_ids all offset");); - TEST_FAILURE(".*ERROR: Illegal reset_mol_ids command.*", - lmp->input->one("reset_mol_ids all compress");); + command("reset_mol_ids all compress");); TEST_FAILURE(".*ERROR: Illegal reset_mol_ids command.*", - lmp->input->one("reset_mol_ids all compress xxx");); + command("reset_mol_ids all compress xxx");); + TEST_FAILURE(".*ERROR: Illegal reset_mol_ids command.*", command("reset_mol_ids all single");); TEST_FAILURE(".*ERROR: Illegal reset_mol_ids command.*", - lmp->input->one("reset_mol_ids all single");); - TEST_FAILURE(".*ERROR: Illegal reset_mol_ids command.*", - lmp->input->one("reset_mol_ids all single xxx");); + command("reset_mol_ids all single xxx");); } TEST(ResetMolIds, CMDFail) @@ -693,20 +692,23 @@ TEST(ResetMolIds, CMDFail) TEST_FAILURE(".*ERROR: Reset_mol_ids command before simulation box is.*", lmp->input->one("reset_mol_ids all");); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("atom_modify id no"); - lmp->input->one("region box block 0 1 0 1 0 1"); - lmp->input->one("create_box 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - TEST_FAILURE(".*ERROR: Cannot use reset_mol_ids unless.*", - lmp->input->one("reset_mol_ids all");); + auto command = [&](const std::string &line) { + lmp->input->one(line.c_str()); + }; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("region box block 0 1 0 1 0 1"); - lmp->input->one("create_box 1 box"); + command("atom_modify id no"); + command("region box block 0 1 0 1 0 1"); + command("create_box 1 box"); if (!verbose) ::testing::internal::GetCapturedStdout(); - TEST_FAILURE(".*ERROR: Can only use reset_mol_ids.*", lmp->input->one("reset_mol_ids all");); + TEST_FAILURE(".*ERROR: Cannot use reset_mol_ids unless.*", command("reset_mol_ids all");); + + if (!verbose) ::testing::internal::CaptureStdout(); + command("clear"); + command("region box block 0 1 0 1 0 1"); + command("create_box 1 box"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + TEST_FAILURE(".*ERROR: Can only use reset_mol_ids.*", command("reset_mol_ids all");); if (!verbose) ::testing::internal::CaptureStdout(); delete lmp; diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index 5fdc1e912b..4261dbd61d 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -82,11 +82,13 @@ protected: delete lmp; if (!verbose) ::testing::internal::GetCapturedStdout(); } + + void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(SimpleCommandsTest, UnknownCommand) { - TEST_FAILURE(".*ERROR: Unknown command.*", lmp->input->one("XXX one two");); + TEST_FAILURE(".*ERROR: Unknown command.*", command("XXX one two");); } TEST_F(SimpleCommandsTest, Echo) @@ -95,31 +97,31 @@ TEST_F(SimpleCommandsTest, Echo) ASSERT_EQ(lmp->input->echo_log, 0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("echo none"); + command("echo none"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->input->echo_screen, 0); ASSERT_EQ(lmp->input->echo_log, 0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("echo both"); + command("echo both"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->input->echo_screen, 1); ASSERT_EQ(lmp->input->echo_log, 1); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("echo screen"); + command("echo screen"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->input->echo_screen, 1); ASSERT_EQ(lmp->input->echo_log, 0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("echo log"); + command("echo log"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->input->echo_screen, 0); ASSERT_EQ(lmp->input->echo_log, 1); - TEST_FAILURE(".*ERROR: Illegal echo command.*", lmp->input->one("echo");); - TEST_FAILURE(".*ERROR: Illegal echo command.*", lmp->input->one("echo xxx");); + TEST_FAILURE(".*ERROR: Illegal echo command.*", command("echo");); + TEST_FAILURE(".*ERROR: Illegal echo command.*", command("echo xxx");); } TEST_F(SimpleCommandsTest, Log) @@ -127,13 +129,13 @@ TEST_F(SimpleCommandsTest, Log) ASSERT_EQ(lmp->logfile, nullptr); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("log simple_command_test.log"); - lmp->input->one("print 'test1'"); + command("log simple_command_test.log"); + command("print 'test1'"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_NE(lmp->logfile, nullptr); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("log none"); + command("log none"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->logfile, nullptr); @@ -145,12 +147,12 @@ TEST_F(SimpleCommandsTest, Log) ASSERT_THAT(text, StrEq("test1")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("log simple_command_test.log append"); - lmp->input->one("print 'test2'"); + command("log simple_command_test.log append"); + command("print 'test2'"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_NE(lmp->logfile, nullptr); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("log none"); + command("log none"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->logfile, nullptr); @@ -162,7 +164,7 @@ TEST_F(SimpleCommandsTest, Log) in.close(); remove("simple_command_test.log"); - TEST_FAILURE(".*ERROR: Illegal log command.*", lmp->input->one("log");); + TEST_FAILURE(".*ERROR: Illegal log command.*", command("log");); } TEST_F(SimpleCommandsTest, Newton) @@ -171,22 +173,22 @@ TEST_F(SimpleCommandsTest, Newton) ASSERT_EQ(lmp->force->newton_pair, 1); ASSERT_EQ(lmp->force->newton_bond, 1); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("newton off"); + command("newton off"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->force->newton_pair, 0); ASSERT_EQ(lmp->force->newton_bond, 0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("newton on off"); + command("newton on off"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->force->newton_pair, 1); ASSERT_EQ(lmp->force->newton_bond, 0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("newton off on"); + command("newton off on"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->force->newton_pair, 0); ASSERT_EQ(lmp->force->newton_bond, 1); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("newton on"); + command("newton on"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->force->newton_pair, 1); ASSERT_EQ(lmp->force->newton_bond, 1); @@ -195,21 +197,20 @@ TEST_F(SimpleCommandsTest, Newton) TEST_F(SimpleCommandsTest, Partition) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("echo none"); + command("echo none"); if (!verbose) ::testing::internal::GetCapturedStdout(); - TEST_FAILURE(".*ERROR: Illegal partition command .*", - lmp->input->one("partition xxx 1 echo none");); + TEST_FAILURE(".*ERROR: Illegal partition command .*", command("partition xxx 1 echo none");); TEST_FAILURE(".*ERROR: Numeric index 2 is out of bounds.*", - lmp->input->one("partition yes 2 echo none");); + command("partition yes 2 echo none");); ::testing::internal::CaptureStdout(); - lmp->input->one("partition yes 1 print 'test'"); + command("partition yes 1 print 'test'"); auto text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; ASSERT_THAT(text, StrEq("test\n")); ::testing::internal::CaptureStdout(); - lmp->input->one("partition no 1 print 'test'"); + command("partition no 1 print 'test'"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; ASSERT_THAT(text, StrEq("")); @@ -218,14 +219,14 @@ TEST_F(SimpleCommandsTest, Partition) TEST_F(SimpleCommandsTest, Quit) { ::testing::internal::CaptureStdout(); - lmp->input->one("echo none"); + command("echo none"); ::testing::internal::GetCapturedStdout(); - TEST_FAILURE(".*ERROR: Expected integer .*", lmp->input->one("quit xxx");); + TEST_FAILURE(".*ERROR: Expected integer .*", command("quit xxx");); // the following tests must be skipped with OpenMPI due to using threads if (have_openmpi) GTEST_SKIP(); - ASSERT_EXIT(lmp->input->one("quit"), ExitedWithCode(0), ""); - ASSERT_EXIT(lmp->input->one("quit 9"), ExitedWithCode(9), ""); + ASSERT_EXIT(command("quit"), ExitedWithCode(0), ""); + ASSERT_EXIT(command("quit 9"), ExitedWithCode(9), ""); } TEST_F(SimpleCommandsTest, ResetTimestep) @@ -233,19 +234,19 @@ TEST_F(SimpleCommandsTest, ResetTimestep) ASSERT_EQ(lmp->update->ntimestep, 0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("reset_timestep 10"); + command("reset_timestep 10"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->update->ntimestep, 10); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("reset_timestep 0"); + command("reset_timestep 0"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->update->ntimestep, 0); - TEST_FAILURE(".*ERROR: Timestep must be >= 0.*", lmp->input->one("reset_timestep -10");); - TEST_FAILURE(".*ERROR: Illegal reset_timestep .*", lmp->input->one("reset_timestep");); - TEST_FAILURE(".*ERROR: Illegal reset_timestep .*", lmp->input->one("reset_timestep 10 10");); - TEST_FAILURE(".*ERROR: Expected integer .*", lmp->input->one("reset_timestep xxx");); + TEST_FAILURE(".*ERROR: Timestep must be >= 0.*", command("reset_timestep -10");); + TEST_FAILURE(".*ERROR: Illegal reset_timestep .*", command("reset_timestep");); + TEST_FAILURE(".*ERROR: Illegal reset_timestep .*", command("reset_timestep 10 10");); + TEST_FAILURE(".*ERROR: Expected integer .*", command("reset_timestep xxx");); } TEST_F(SimpleCommandsTest, Suffix) @@ -254,39 +255,38 @@ TEST_F(SimpleCommandsTest, Suffix) ASSERT_EQ(lmp->suffix, nullptr); ASSERT_EQ(lmp->suffix2, nullptr); - TEST_FAILURE(".*ERROR: May only enable suffixes after defining one.*", - lmp->input->one("suffix on");); + TEST_FAILURE(".*ERROR: May only enable suffixes after defining one.*", command("suffix on");); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("suffix one"); + command("suffix one"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_THAT(lmp->suffix, StrEq("one")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("suffix hybrid two three"); + command("suffix hybrid two three"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_THAT(lmp->suffix, StrEq("two")); ASSERT_THAT(lmp->suffix2, StrEq("three")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("suffix four"); + command("suffix four"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_THAT(lmp->suffix, StrEq("four")); ASSERT_EQ(lmp->suffix2, nullptr); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("suffix off"); + command("suffix off"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->suffix_enable, 0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("suffix on"); + command("suffix on"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->suffix_enable, 1); - TEST_FAILURE(".*ERROR: Illegal suffix command.*", lmp->input->one("suffix");); - TEST_FAILURE(".*ERROR: Illegal suffix command.*", lmp->input->one("suffix hybrid");); - TEST_FAILURE(".*ERROR: Illegal suffix command.*", lmp->input->one("suffix hybrid one");); + TEST_FAILURE(".*ERROR: Illegal suffix command.*", command("suffix");); + TEST_FAILURE(".*ERROR: Illegal suffix command.*", command("suffix hybrid");); + TEST_FAILURE(".*ERROR: Illegal suffix command.*", command("suffix hybrid one");); } TEST_F(SimpleCommandsTest, Thermo) @@ -294,53 +294,53 @@ TEST_F(SimpleCommandsTest, Thermo) ASSERT_EQ(lmp->output->thermo_every, 0); ASSERT_EQ(lmp->output->var_thermo, nullptr); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("thermo 2"); + command("thermo 2"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->output->thermo_every, 2); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("variable step equal logfreq(10,3,10)"); - lmp->input->one("thermo v_step"); + command("variable step equal logfreq(10,3,10)"); + command("thermo v_step"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_THAT(lmp->output->var_thermo, StrEq("step")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("thermo 10"); + command("thermo 10"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->output->thermo_every, 10); ASSERT_EQ(lmp->output->var_thermo, nullptr); - TEST_FAILURE(".*ERROR: Illegal thermo command.*", lmp->input->one("thermo");); - TEST_FAILURE(".*ERROR: Illegal thermo command.*", lmp->input->one("thermo -1");); - TEST_FAILURE(".*ERROR: Expected integer.*", lmp->input->one("thermo xxx");); + TEST_FAILURE(".*ERROR: Illegal thermo command.*", command("thermo");); + TEST_FAILURE(".*ERROR: Illegal thermo command.*", command("thermo -1");); + TEST_FAILURE(".*ERROR: Expected integer.*", command("thermo xxx");); } TEST_F(SimpleCommandsTest, TimeStep) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("timestep 1"); + command("timestep 1"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->update->dt, 1.0); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("timestep 0.1"); + command("timestep 0.1"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->update->dt, 0.1); // zero timestep is legal and works (atoms don't move) if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("timestep 0.0"); + command("timestep 0.0"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->update->dt, 0.0); // negative timestep also creates a viable MD. if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("timestep -0.1"); + command("timestep -0.1"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_EQ(lmp->update->dt, -0.1); - TEST_FAILURE(".*ERROR: Illegal timestep command.*", lmp->input->one("timestep");); - TEST_FAILURE(".*ERROR: Expected floating point.*", lmp->input->one("timestep xxx");); + TEST_FAILURE(".*ERROR: Illegal timestep command.*", command("timestep");); + TEST_FAILURE(".*ERROR: Expected floating point.*", command("timestep xxx");); } TEST_F(SimpleCommandsTest, Units) @@ -353,24 +353,24 @@ TEST_F(SimpleCommandsTest, Units) ASSERT_THAT(lmp->update->unit_style, StrEq("lj")); for (std::size_t i = 0; i < num; ++i) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one(fmt::format("units {}", names[i])); + command(fmt::format("units {}", names[i])); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_THAT(lmp->update->unit_style, StrEq(names[i])); ASSERT_EQ(lmp->update->dt, dt[i]); } if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); + command("clear"); if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_THAT(lmp->update->unit_style, StrEq("lj")); - TEST_FAILURE(".*ERROR: Illegal units command.*", lmp->input->one("units unknown");); + TEST_FAILURE(".*ERROR: Illegal units command.*", command("units unknown");); } TEST_F(SimpleCommandsTest, Shell) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("shell putenv TEST_VARIABLE=simpletest"); + command("shell putenv TEST_VARIABLE=simpletest"); if (!verbose) ::testing::internal::GetCapturedStdout(); char *test_var = getenv("TEST_VARIABLE"); @@ -378,8 +378,8 @@ TEST_F(SimpleCommandsTest, Shell) ASSERT_THAT(test_var, StrEq("simpletest")); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("shell putenv TEST_VARIABLE=simpletest"); - lmp->input->one("shell putenv TEST_VARIABLE2=simpletest2 OTHER_VARIABLE=2"); + command("shell putenv TEST_VARIABLE=simpletest"); + command("shell putenv TEST_VARIABLE2=simpletest2 OTHER_VARIABLE=2"); if (!verbose) ::testing::internal::GetCapturedStdout(); char *test_var2 = getenv("TEST_VARIABLE2"); diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 5a1d249bd5..7106867894 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -298,31 +298,31 @@ TEST_F(VariableTest, IfCommand) command("if 1>0 then 'print \".*bingo!\"'"); auto text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text,MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ::testing::internal::CaptureStdout(); command("if (1>=0) then 'print \"bingo!\"'"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text,MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ::testing::internal::CaptureStdout(); command("if (-1.0e-1<0.0E+0) then 'print \"bingo!\"'"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text,MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ::testing::internal::CaptureStdout(); command("if (${one}==1.0)&&(2>=1) then 'print \"bingo!\"'"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text,MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ::testing::internal::CaptureStdout(); command("if !((${one}!=1.0)||(2|^1)) then 'print \"missed\"' else 'print \"bingo!\"'"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text,MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", command("if () then 'print \"bingo!\"'");); diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index 7f07052b3d..8cef78c6f8 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -307,7 +307,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); - auto f = lmp->atom->f; + auto f = lmp->atom->f; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -327,7 +327,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) writer.emit_block("run_stress", block); block.clear(); - f = lmp->atom->f; + f = lmp->atom->f; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); diff --git a/unittest/force-styles/test_bond_style.cpp b/unittest/force-styles/test_bond_style.cpp index a4956006f5..fa9f8fbc02 100644 --- a/unittest/force-styles/test_bond_style.cpp +++ b/unittest/force-styles/test_bond_style.cpp @@ -307,7 +307,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); - auto f = lmp->atom->f; + auto f = lmp->atom->f; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -327,7 +327,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) writer.emit_block("run_stress", block); block.clear(); - f = lmp->atom->f; + f = lmp->atom->f; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); diff --git a/unittest/force-styles/test_config_reader.cpp b/unittest/force-styles/test_config_reader.cpp index 4ef3692f56..d4d9d3c854 100644 --- a/unittest/force-styles/test_config_reader.cpp +++ b/unittest/force-styles/test_config_reader.cpp @@ -53,17 +53,17 @@ TestConfigReader::TestConfigReader(TestConfig &config) : YamlReader(), config(co consumers["global_scalar"] = &TestConfigReader::global_scalar; consumers["global_vector"] = &TestConfigReader::global_vector; - consumers["bond_style"] = &TestConfigReader::bond_style; - consumers["bond_coeff"] = &TestConfigReader::bond_coeff; - consumers["angle_style"] = &TestConfigReader::angle_style; - consumers["angle_coeff"] = &TestConfigReader::angle_coeff; + consumers["bond_style"] = &TestConfigReader::bond_style; + consumers["bond_coeff"] = &TestConfigReader::bond_coeff; + consumers["angle_style"] = &TestConfigReader::angle_style; + consumers["angle_coeff"] = &TestConfigReader::angle_coeff; consumers["dihedral_style"] = &TestConfigReader::dihedral_style; consumers["dihedral_coeff"] = &TestConfigReader::dihedral_coeff; consumers["improper_style"] = &TestConfigReader::improper_style; consumers["improper_coeff"] = &TestConfigReader::improper_coeff; - consumers["init_energy"] = &TestConfigReader::init_energy; - consumers["run_energy"] = &TestConfigReader::run_energy; - consumers["equilibrium"] = &TestConfigReader::equilibrium; + consumers["init_energy"] = &TestConfigReader::init_energy; + consumers["run_energy"] = &TestConfigReader::run_energy; + consumers["equilibrium"] = &TestConfigReader::equilibrium; } void TestConfigReader::prerequisites(const yaml_event_t &event) diff --git a/unittest/force-styles/test_dihedral_style.cpp b/unittest/force-styles/test_dihedral_style.cpp index 6dd6a3f205..81df454fcc 100644 --- a/unittest/force-styles/test_dihedral_style.cpp +++ b/unittest/force-styles/test_dihedral_style.cpp @@ -310,7 +310,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); - auto f = lmp->atom->f; + auto f = lmp->atom->f; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -330,7 +330,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) writer.emit_block("run_stress", block); block.clear(); - f = lmp->atom->f; + f = lmp->atom->f; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index 1b97f38faf..33d95820bd 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -301,7 +301,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); - auto f = lmp->atom->f; + auto f = lmp->atom->f; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -321,7 +321,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) writer.emit_block("run_stress", block); block.clear(); - f = lmp->atom->f; + f = lmp->atom->f; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index fd8d306538..edfad1f923 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -307,7 +307,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) // init_forces block.clear(); - auto f = lmp->atom->f; + auto f = lmp->atom->f; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -330,7 +330,7 @@ void generate_yaml_file(const char *outfile, const TestConfig &config) writer.emit_block("run_stress", block); block.clear(); - f = lmp->atom->f; + f = lmp->atom->f; for (int i = 1; i <= natoms; ++i) { const int j = lmp->atom->map(i); block += fmt::format("{:3} {:23.16e} {:23.16e} {:23.16e}\n", i, f[j][0], f[j][1], f[j][2]); @@ -829,9 +829,8 @@ TEST(PairStyle, intel) GTEST_SKIP(); } - if ((test_config.pair_style == "rebo") - || utils::strmatch(test_config.pair_style, "^dpd") - || utils::strmatch(test_config.pair_style, "^tersoff.* shift ")) { + if ((test_config.pair_style == "rebo") || utils::strmatch(test_config.pair_style, "^dpd") || + utils::strmatch(test_config.pair_style, "^tersoff.* shift ")) { std::cerr << "Skipping pair style " << lmp->force->pair_style << "\n"; if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index 37d436a7a2..b787076495 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -102,9 +102,6 @@ class AtomStyleTest : public ::testing::Test { protected: LAMMPS *lmp; - // convenience... - void command(const std::string cmd) { lmp->input->one(cmd); } - void SetUp() override { const char *args[] = {"SimpleCommandsTest", "-log", "none", "-echo", "screen", "-nocite"}; @@ -131,6 +128,8 @@ protected: remove("input_atom_styles.data"); remove("test_atom_styles.restart"); } + + void command(const std::string cmd) { lmp->input->one(cmd); } }; // default class Atom state diff --git a/unittest/formats/test_file_operations.cpp b/unittest/formats/test_file_operations.cpp index 8c4c8bce89..cf85d810df 100644 --- a/unittest/formats/test_file_operations.cpp +++ b/unittest/formats/test_file_operations.cpp @@ -84,6 +84,8 @@ protected: if (!verbose) ::testing::internal::GetCapturedStdout(); remove("safe_file_read_test.txt"); } + + void command(const std::string &cmd) { lmp->input->one(cmd); } }; #define MAX_BUF_SIZE 128 @@ -155,13 +157,13 @@ TEST_F(FileOperationsTest, logmesg) { char buf[8]; ::testing::internal::CaptureStdout(); - lmp->input->one("echo none"); + command("echo none"); ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); utils::logmesg(lmp, "one\n"); - lmp->input->one("log test_logmesg.log"); + command("log test_logmesg.log"); utils::logmesg(lmp, "two\n"); - lmp->input->one("log none"); + command("log none"); std::string out = ::testing::internal::GetCapturedStdout(); memset(buf, 0, 8); FILE *fp = fopen("test_logmesg.log", "r"); diff --git a/unittest/formats/test_image_flags.cpp b/unittest/formats/test_image_flags.cpp index 6d4ae08111..6b3a333328 100644 --- a/unittest/formats/test_image_flags.cpp +++ b/unittest/formats/test_image_flags.cpp @@ -28,7 +28,6 @@ using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { using ::testing::Eq; - class ImageFlagsTest : public ::testing::Test { protected: LAMMPS *lmp; @@ -43,18 +42,18 @@ protected: if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_NE(lmp, nullptr); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units real"); - lmp->input->one("dimension 3"); - lmp->input->one("region box block -2 2 -2 2 -2 2"); - lmp->input->one("create_box 1 box"); - lmp->input->one("create_atoms 1 single 0.0 0.0 0.0 units box"); - lmp->input->one("create_atoms 1 single 1.9 -1.9 1.9999 units box"); - lmp->input->one("pair_style zero 2.0"); - lmp->input->one("pair_coeff * *"); - lmp->input->one("mass * 1.0"); - lmp->input->one("set atom 1 image -1 2 3"); - lmp->input->one("set atom 2 image -2 1 -1"); - lmp->input->one("write_data test_image_flags.data"); + command("units real"); + command("dimension 3"); + command("region box block -2 2 -2 2 -2 2"); + command("create_box 1 box"); + command("create_atoms 1 single 0.0 0.0 0.0 units box"); + command("create_atoms 1 single 1.9 -1.9 1.9999 units box"); + command("pair_style zero 2.0"); + command("pair_coeff * *"); + command("mass * 1.0"); + command("set atom 1 image -1 2 3"); + command("set atom 2 image -2 1 -1"); + command("write_data test_image_flags.data"); if (!verbose) ::testing::internal::GetCapturedStdout(); } @@ -65,196 +64,198 @@ protected: if (!verbose) ::testing::internal::GetCapturedStdout(); remove("test_image_flags.data"); } + + void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(ImageFlagsTest, change_box) { auto image = lmp->atom->image; - int imx = (image[0] & IMGMASK) - IMGMAX; - int imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; - int imz = (image[0] >> IMG2BITS) - IMGMAX; + int imx = (image[0] & IMGMASK) - IMGMAX; + int imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; + int imz = (image[0] >> IMG2BITS) - IMGMAX; + + ASSERT_EQ(imx, -1); + ASSERT_EQ(imy, 2); + ASSERT_EQ(imz, 3); - ASSERT_EQ(imx,-1); - ASSERT_EQ(imy,2); - ASSERT_EQ(imz,3); - imx = (image[1] & IMGMASK) - IMGMAX; imy = (image[1] >> IMGBITS & IMGMASK) - IMGMAX; imz = (image[1] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,-2); - ASSERT_EQ(imy,1); - ASSERT_EQ(imz,-1); - + ASSERT_EQ(imx, -2); + ASSERT_EQ(imy, 1); + ASSERT_EQ(imz, -1); + if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("change_box all boundary f p p"); + command("change_box all boundary f p p"); if (!verbose) ::testing::internal::GetCapturedStdout(); image = lmp->atom->image; - imx = (image[0] & IMGMASK) - IMGMAX; - imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; - imz = (image[0] >> IMG2BITS) - IMGMAX; + imx = (image[0] & IMGMASK) - IMGMAX; + imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; + imz = (image[0] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,0); - ASSERT_EQ(imy,2); - ASSERT_EQ(imz,3); + ASSERT_EQ(imx, 0); + ASSERT_EQ(imy, 2); + ASSERT_EQ(imz, 3); imx = (image[1] & IMGMASK) - IMGMAX; imy = (image[1] >> IMGBITS & IMGMASK) - IMGMAX; imz = (image[1] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,0); - ASSERT_EQ(imy,1); - ASSERT_EQ(imz,-1); + ASSERT_EQ(imx, 0); + ASSERT_EQ(imy, 1); + ASSERT_EQ(imz, -1); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("change_box all boundary f s p"); + command("change_box all boundary f s p"); if (!verbose) ::testing::internal::GetCapturedStdout(); image = lmp->atom->image; - imx = (image[0] & IMGMASK) - IMGMAX; - imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; - imz = (image[0] >> IMG2BITS) - IMGMAX; + imx = (image[0] & IMGMASK) - IMGMAX; + imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; + imz = (image[0] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,0); - ASSERT_EQ(imy,0); - ASSERT_EQ(imz,3); + ASSERT_EQ(imx, 0); + ASSERT_EQ(imy, 0); + ASSERT_EQ(imz, 3); imx = (image[1] & IMGMASK) - IMGMAX; imy = (image[1] >> IMGBITS & IMGMASK) - IMGMAX; imz = (image[1] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,0); - ASSERT_EQ(imy,0); - ASSERT_EQ(imz,-1); + ASSERT_EQ(imx, 0); + ASSERT_EQ(imy, 0); + ASSERT_EQ(imz, -1); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("change_box all boundary p p m"); + command("change_box all boundary p p m"); if (!verbose) ::testing::internal::GetCapturedStdout(); image = lmp->atom->image; - imx = (image[0] & IMGMASK) - IMGMAX; - imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; - imz = (image[0] >> IMG2BITS) - IMGMAX; + imx = (image[0] & IMGMASK) - IMGMAX; + imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; + imz = (image[0] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,0); - ASSERT_EQ(imy,0); - ASSERT_EQ(imz,0); + ASSERT_EQ(imx, 0); + ASSERT_EQ(imy, 0); + ASSERT_EQ(imz, 0); imx = (image[1] & IMGMASK) - IMGMAX; imy = (image[1] >> IMGBITS & IMGMASK) - IMGMAX; imz = (image[1] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,0); - ASSERT_EQ(imy,0); - ASSERT_EQ(imz,0); + ASSERT_EQ(imx, 0); + ASSERT_EQ(imy, 0); + ASSERT_EQ(imz, 0); } TEST_F(ImageFlagsTest, read_data) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("dimension 3"); - lmp->input->one("boundary p p p"); - lmp->input->one("pair_style zero 2.0"); - lmp->input->one("read_data test_image_flags.data"); + command("clear"); + command("units real"); + command("dimension 3"); + command("boundary p p p"); + command("pair_style zero 2.0"); + command("read_data test_image_flags.data"); if (!verbose) ::testing::internal::GetCapturedStdout(); - + auto image = lmp->atom->image; - int imx = (image[0] & IMGMASK) - IMGMAX; - int imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; - int imz = (image[0] >> IMG2BITS) - IMGMAX; + int imx = (image[0] & IMGMASK) - IMGMAX; + int imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; + int imz = (image[0] >> IMG2BITS) - IMGMAX; + + ASSERT_EQ(imx, -1); + ASSERT_EQ(imy, 2); + ASSERT_EQ(imz, 3); - ASSERT_EQ(imx,-1); - ASSERT_EQ(imy,2); - ASSERT_EQ(imz,3); - imx = (image[1] & IMGMASK) - IMGMAX; imy = (image[1] >> IMGBITS & IMGMASK) - IMGMAX; imz = (image[1] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,-2); - ASSERT_EQ(imy,1); - ASSERT_EQ(imz,-1); - + ASSERT_EQ(imx, -2); + ASSERT_EQ(imy, 1); + ASSERT_EQ(imz, -1); + if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("dimension 3"); - lmp->input->one("boundary f p p"); - lmp->input->one("pair_style zero 2.0"); - lmp->input->one("read_data test_image_flags.data"); + command("clear"); + command("units real"); + command("dimension 3"); + command("boundary f p p"); + command("pair_style zero 2.0"); + command("read_data test_image_flags.data"); if (!verbose) ::testing::internal::GetCapturedStdout(); image = lmp->atom->image; - imx = (image[0] & IMGMASK) - IMGMAX; - imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; - imz = (image[0] >> IMG2BITS) - IMGMAX; + imx = (image[0] & IMGMASK) - IMGMAX; + imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; + imz = (image[0] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,0); - ASSERT_EQ(imy,2); - ASSERT_EQ(imz,3); + ASSERT_EQ(imx, 0); + ASSERT_EQ(imy, 2); + ASSERT_EQ(imz, 3); imx = (image[1] & IMGMASK) - IMGMAX; imy = (image[1] >> IMGBITS & IMGMASK) - IMGMAX; imz = (image[1] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,0); - ASSERT_EQ(imy,1); - ASSERT_EQ(imz,-1); + ASSERT_EQ(imx, 0); + ASSERT_EQ(imy, 1); + ASSERT_EQ(imz, -1); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("dimension 3"); - lmp->input->one("boundary p s p"); - lmp->input->one("pair_style zero 2.0"); - lmp->input->one("read_data test_image_flags.data"); + command("clear"); + command("units real"); + command("dimension 3"); + command("boundary p s p"); + command("pair_style zero 2.0"); + command("read_data test_image_flags.data"); if (!verbose) ::testing::internal::GetCapturedStdout(); image = lmp->atom->image; - imx = (image[0] & IMGMASK) - IMGMAX; - imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; - imz = (image[0] >> IMG2BITS) - IMGMAX; + imx = (image[0] & IMGMASK) - IMGMAX; + imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; + imz = (image[0] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,-1); - ASSERT_EQ(imy,0); - ASSERT_EQ(imz,3); + ASSERT_EQ(imx, -1); + ASSERT_EQ(imy, 0); + ASSERT_EQ(imz, 3); imx = (image[1] & IMGMASK) - IMGMAX; imy = (image[1] >> IMGBITS & IMGMASK) - IMGMAX; imz = (image[1] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,-2); - ASSERT_EQ(imy,0); - ASSERT_EQ(imz,-1); + ASSERT_EQ(imx, -2); + ASSERT_EQ(imy, 0); + ASSERT_EQ(imz, -1); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("dimension 3"); - lmp->input->one("boundary p p m"); - lmp->input->one("pair_style zero 2.0"); - lmp->input->one("read_data test_image_flags.data"); + command("clear"); + command("units real"); + command("dimension 3"); + command("boundary p p m"); + command("pair_style zero 2.0"); + command("read_data test_image_flags.data"); if (!verbose) ::testing::internal::GetCapturedStdout(); image = lmp->atom->image; - imx = (image[0] & IMGMASK) - IMGMAX; - imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; - imz = (image[0] >> IMG2BITS) - IMGMAX; + imx = (image[0] & IMGMASK) - IMGMAX; + imy = (image[0] >> IMGBITS & IMGMASK) - IMGMAX; + imz = (image[0] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,-1); - ASSERT_EQ(imy,2); - ASSERT_EQ(imz,0); + ASSERT_EQ(imx, -1); + ASSERT_EQ(imy, 2); + ASSERT_EQ(imz, 0); imx = (image[1] & IMGMASK) - IMGMAX; imy = (image[1] >> IMGBITS & IMGMASK) - IMGMAX; imz = (image[1] >> IMG2BITS) - IMGMAX; - ASSERT_EQ(imx,-2); - ASSERT_EQ(imy,1); - ASSERT_EQ(imz,0); + ASSERT_EQ(imx, -2); + ASSERT_EQ(imy, 1); + ASSERT_EQ(imz, 0); } } // namespace LAMMPS_NS diff --git a/unittest/formats/test_molecule_file.cpp b/unittest/formats/test_molecule_file.cpp index 3bfc0dc4fa..204a1bd061 100644 --- a/unittest/formats/test_molecule_file.cpp +++ b/unittest/formats/test_molecule_file.cpp @@ -131,19 +131,20 @@ protected: lmp->input->one(fmt::format("molecule {} {} {}", name, file, args)); remove(file.c_str()); } + + void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(MoleculeFileTest, nofile) { - TEST_FAILURE(".*Cannot open molecule file nofile.mol.*", - lmp->input->one("molecule 1 nofile.mol");); + TEST_FAILURE(".*Cannot open molecule file nofile.mol.*", command("molecule 1 nofile.mol");); } TEST_F(MoleculeFileTest, badid) { TEST_FAILURE(".*Molecule template ID must have only " "alphanumeric or underscore characters.*", - lmp->input->one("molecule @mol nofile.mol");); + command("molecule @mol nofile.mol");); } TEST_F(MoleculeFileTest, badargs) @@ -223,7 +224,7 @@ TEST_F(MoleculeFileTest, twomols) TEST_F(MoleculeFileTest, twofiles) { ::testing::internal::CaptureStdout(); - lmp->input->one("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); + command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); auto output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; ASSERT_THAT(output, MatchesRegex(".*Read molecule template twomols:.*1 molecules.*3 atoms " @@ -237,10 +238,10 @@ TEST_F(MoleculeFileTest, twofiles) TEST_F(MoleculeFileTest, bonds) { ::testing::internal::CaptureStdout(); - lmp->input->one("atom_style bond"); - lmp->input->one("region box block 0 1 0 1 0 1"); - lmp->input->one("create_box 2 box bond/types 2 extra/bond/per/atom 2 " - "extra/special/per/atom 4"); + command("atom_style bond"); + command("region box block 0 1 0 1 0 1"); + command("create_box 2 box bond/types 2 extra/bond/per/atom 2 " + "extra/special/per/atom 4"); run_mol_cmd(test_name, "", "Comment\n" "4 atoms\n" @@ -264,8 +265,8 @@ TEST_F(MoleculeFileTest, bonds) "2 bonds.*type.*2.*0 angles.*")); ::testing::internal::CaptureStdout(); - lmp->input->one("mass * 2.0"); - lmp->input->one("create_atoms 0 single 0.5 0.5 0.5 mol bonds 67235"); + command("mass * 2.0"); + command("create_atoms 0 single 0.5 0.5 0.5 mol bonds 67235"); output = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << output; ASSERT_THAT(output, MatchesRegex(".*Created 4 atoms.*")); diff --git a/unittest/formats/test_pair_unit_convert.cpp b/unittest/formats/test_pair_unit_convert.cpp index 712e6ff50c..f0c2f0d031 100644 --- a/unittest/formats/test_pair_unit_convert.cpp +++ b/unittest/formats/test_pair_unit_convert.cpp @@ -59,19 +59,19 @@ protected: ASSERT_NE(lmp, nullptr); if (!verbose) ::testing::internal::CaptureStdout(); info = new Info(lmp); - lmp->input->one("units metal"); - lmp->input->one("dimension 3"); - lmp->input->one("region box block -4 4 -4 4 -4 4"); - lmp->input->one("create_box 2 box"); - lmp->input->one("create_atoms 1 single -1.1 1.2 0.0 units box"); - lmp->input->one("create_atoms 1 single -1.2 -1.1 0.0 units box"); - lmp->input->one("create_atoms 2 single 0.9 1.0 0.0 units box"); - lmp->input->one("create_atoms 2 single 1.0 -0.9 0.0 units box"); - lmp->input->one("pair_style zero 4.0"); - lmp->input->one("pair_coeff * *"); - lmp->input->one("mass * 1.0"); - lmp->input->one("write_data test_pair_unit_convert.data nocoeff"); - lmp->input->one("clear"); + command("units metal"); + command("dimension 3"); + command("region box block -4 4 -4 4 -4 4"); + command("create_box 2 box"); + command("create_atoms 1 single -1.1 1.2 0.0 units box"); + command("create_atoms 1 single -1.2 -1.1 0.0 units box"); + command("create_atoms 2 single 0.9 1.0 0.0 units box"); + command("create_atoms 2 single 1.0 -0.9 0.0 units box"); + command("pair_style zero 4.0"); + command("pair_coeff * *"); + command("mass * 1.0"); + command("write_data test_pair_unit_convert.data nocoeff"); + command("clear"); if (!verbose) ::testing::internal::GetCapturedStdout(); } @@ -83,6 +83,8 @@ protected: if (!verbose) ::testing::internal::GetCapturedStdout(); remove("test_pair_unit_convert.data"); } + + void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(PairUnitConvertTest, zero) @@ -91,11 +93,11 @@ TEST_F(PairUnitConvertTest, zero) if (!info->has_style("pair", "zero")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style zero 6.0"); - lmp->input->one("pair_coeff * *"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style zero 6.0"); + command("pair_coeff * *"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -108,12 +110,12 @@ TEST_F(PairUnitConvertTest, zero) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style zero 6.0"); - lmp->input->one("pair_coeff * *"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style zero 6.0"); + command("pair_coeff * *"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -134,15 +136,15 @@ TEST_F(PairUnitConvertTest, lj_cut) if (!info->has_style("pair", "lj/cut")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style lj/cut 6.0"); - lmp->input->one("pair_coeff * * 0.01014286346782117 2.0"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style lj/cut 6.0"); + command("pair_coeff * * 0.01014286346782117 2.0"); remove("test.table.metal"); - lmp->input->one("pair_write 1 1 1000 r 0.1 6.0 test.table.metal lj_1_1"); - lmp->input->one("pair_write 1 2 1000 r 0.1 6.0 test.table.metal lj_1_2"); - lmp->input->one("pair_write 2 2 1000 r 0.1 6.0 test.table.metal lj_2_2"); - lmp->input->one("run 0 post no"); + command("pair_write 1 1 1000 r 0.1 6.0 test.table.metal lj_1_1"); + command("pair_write 1 2 1000 r 0.1 6.0 test.table.metal lj_1_2"); + command("pair_write 2 2 1000 r 0.1 6.0 test.table.metal lj_2_2"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -155,16 +157,16 @@ TEST_F(PairUnitConvertTest, lj_cut) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style lj/cut 6.0"); - lmp->input->one("pair_coeff * * 0.2339 2.0"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style lj/cut 6.0"); + command("pair_coeff * * 0.2339 2.0"); remove("test.table.real"); - lmp->input->one("pair_write 1 1 1000 r 0.1 6.0 test.table.real lj_1_1"); - lmp->input->one("pair_write 1 2 1000 r 0.1 6.0 test.table.real lj_1_2"); - lmp->input->one("pair_write 2 2 1000 r 0.1 6.0 test.table.real lj_2_2"); - lmp->input->one("run 0 post no"); + command("pair_write 1 1 1000 r 0.1 6.0 test.table.real lj_1_1"); + command("pair_write 1 2 1000 r 0.1 6.0 test.table.real lj_1_2"); + command("pair_write 2 2 1000 r 0.1 6.0 test.table.real lj_2_2"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -185,11 +187,11 @@ TEST_F(PairUnitConvertTest, eam) if (!info->has_style("pair", "eam")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style eam"); - lmp->input->one("pair_coeff * * Cu_u3.eam"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style eam"); + command("pair_coeff * * Cu_u3.eam"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -202,12 +204,12 @@ TEST_F(PairUnitConvertTest, eam) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style eam"); - lmp->input->one("pair_coeff * * Cu_u3.eam"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style eam"); + command("pair_coeff * * Cu_u3.eam"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -228,11 +230,11 @@ TEST_F(PairUnitConvertTest, eam_alloy) if (!info->has_style("pair", "eam/alloy")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style eam/alloy"); - lmp->input->one("pair_coeff * * AlCu.eam.alloy Al Cu"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style eam/alloy"); + command("pair_coeff * * AlCu.eam.alloy Al Cu"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -245,12 +247,12 @@ TEST_F(PairUnitConvertTest, eam_alloy) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style eam/alloy"); - lmp->input->one("pair_coeff * * AlCu.eam.alloy Al Cu"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style eam/alloy"); + command("pair_coeff * * AlCu.eam.alloy Al Cu"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -271,11 +273,11 @@ TEST_F(PairUnitConvertTest, eam_fs) if (!info->has_style("pair", "eam/fs")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style eam/fs"); - lmp->input->one("pair_coeff * * FeP_mm.eam.fs Fe P"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style eam/fs"); + command("pair_coeff * * FeP_mm.eam.fs Fe P"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -288,12 +290,12 @@ TEST_F(PairUnitConvertTest, eam_fs) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style eam/fs"); - lmp->input->one("pair_coeff * * FeP_mm.eam.fs Fe P"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style eam/fs"); + command("pair_coeff * * FeP_mm.eam.fs Fe P"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -314,11 +316,11 @@ TEST_F(PairUnitConvertTest, eam_cd) if (!info->has_style("pair", "eam/cd")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style eam/cd"); - lmp->input->one("pair_coeff * * FeCr.cdeam Cr Fe"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style eam/cd"); + command("pair_coeff * * FeCr.cdeam Cr Fe"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -331,12 +333,12 @@ TEST_F(PairUnitConvertTest, eam_cd) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style eam/cd"); - lmp->input->one("pair_coeff * * FeCr.cdeam Cr Fe"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style eam/cd"); + command("pair_coeff * * FeCr.cdeam Cr Fe"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -357,11 +359,11 @@ TEST_F(PairUnitConvertTest, eim) if (!info->has_style("pair", "eim")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style eim"); - lmp->input->one("pair_coeff * * Na Cl ffield.eim Na Cl"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style eim"); + command("pair_coeff * * Na Cl ffield.eim Na Cl"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -374,12 +376,12 @@ TEST_F(PairUnitConvertTest, eim) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style eim"); - lmp->input->one("pair_coeff * * Na Cl ffield.eim Na Cl"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style eim"); + command("pair_coeff * * Na Cl ffield.eim Na Cl"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -400,11 +402,11 @@ TEST_F(PairUnitConvertTest, gw) if (!info->has_style("pair", "gw")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style gw"); - lmp->input->one("pair_coeff * * SiC.gw Si C"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style gw"); + command("pair_coeff * * SiC.gw Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -417,12 +419,12 @@ TEST_F(PairUnitConvertTest, gw) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style gw"); - lmp->input->one("pair_coeff * * SiC.gw Si C"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style gw"); + command("pair_coeff * * SiC.gw Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -443,11 +445,11 @@ TEST_F(PairUnitConvertTest, gw_zbl) if (!info->has_style("pair", "gw/zbl")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style gw/zbl"); - lmp->input->one("pair_coeff * * SiC.gw.zbl Si C"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style gw/zbl"); + command("pair_coeff * * SiC.gw.zbl Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -460,12 +462,12 @@ TEST_F(PairUnitConvertTest, gw_zbl) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style gw/zbl"); - lmp->input->one("pair_coeff * * SiC.gw.zbl Si C"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style gw/zbl"); + command("pair_coeff * * SiC.gw.zbl Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -486,11 +488,11 @@ TEST_F(PairUnitConvertTest, nb3b_harmonic) if (!info->has_style("pair", "nb3b/harmonic")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style nb3b/harmonic"); - lmp->input->one("pair_coeff * * MOH.nb3b.harmonic M O"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style nb3b/harmonic"); + command("pair_coeff * * MOH.nb3b.harmonic M O"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -503,12 +505,12 @@ TEST_F(PairUnitConvertTest, nb3b_harmonic) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style nb3b/harmonic"); - lmp->input->one("pair_coeff * * MOH.nb3b.harmonic M O"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style nb3b/harmonic"); + command("pair_coeff * * MOH.nb3b.harmonic M O"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -529,11 +531,11 @@ TEST_F(PairUnitConvertTest, sw) if (!info->has_style("pair", "sw")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style sw"); - lmp->input->one("pair_coeff * * GaN.sw Ga N"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style sw"); + command("pair_coeff * * GaN.sw Ga N"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -546,12 +548,12 @@ TEST_F(PairUnitConvertTest, sw) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style sw"); - lmp->input->one("pair_coeff * * GaN.sw Ga N"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style sw"); + command("pair_coeff * * GaN.sw Ga N"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -572,13 +574,13 @@ TEST_F(PairUnitConvertTest, table_metal2real) if (!info->has_style("pair", "table")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style table linear 1000"); - lmp->input->one("pair_coeff 1 1 test.table.metal lj_1_1"); - lmp->input->one("pair_coeff 1 2 test.table.metal lj_1_2"); - lmp->input->one("pair_coeff 2 2 test.table.metal lj_2_2"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style table linear 1000"); + command("pair_coeff 1 1 test.table.metal lj_1_1"); + command("pair_coeff 1 2 test.table.metal lj_1_2"); + command("pair_coeff 2 2 test.table.metal lj_2_2"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -591,14 +593,14 @@ TEST_F(PairUnitConvertTest, table_metal2real) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style table linear 1000"); - lmp->input->one("pair_coeff 1 1 test.table.metal lj_1_1"); - lmp->input->one("pair_coeff 1 2 test.table.metal lj_1_2"); - lmp->input->one("pair_coeff 2 2 test.table.metal lj_2_2"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style table linear 1000"); + command("pair_coeff 1 1 test.table.metal lj_1_1"); + command("pair_coeff 1 2 test.table.metal lj_1_2"); + command("pair_coeff 2 2 test.table.metal lj_2_2"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -619,13 +621,13 @@ TEST_F(PairUnitConvertTest, table_real2metal) if (!info->has_style("pair", "table")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style table linear 1000"); - lmp->input->one("pair_coeff 1 1 test.table.real lj_1_1"); - lmp->input->one("pair_coeff 1 2 test.table.real lj_1_2"); - lmp->input->one("pair_coeff 2 2 test.table.real lj_2_2"); - lmp->input->one("run 0 post no"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style table linear 1000"); + command("pair_coeff 1 1 test.table.real lj_1_1"); + command("pair_coeff 1 2 test.table.real lj_1_2"); + command("pair_coeff 2 2 test.table.real lj_2_2"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -638,14 +640,14 @@ TEST_F(PairUnitConvertTest, table_real2metal) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style table linear 1000"); - lmp->input->one("pair_coeff 1 1 test.table.real lj_1_1"); - lmp->input->one("pair_coeff 1 2 test.table.real lj_1_2"); - lmp->input->one("pair_coeff 2 2 test.table.real lj_2_2"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style table linear 1000"); + command("pair_coeff 1 1 test.table.real lj_1_1"); + command("pair_coeff 1 2 test.table.real lj_1_2"); + command("pair_coeff 2 2 test.table.real lj_2_2"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -666,11 +668,11 @@ TEST_F(PairUnitConvertTest, tersoff) if (!info->has_style("pair", "tersoff")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style tersoff"); - lmp->input->one("pair_coeff * * SiC.tersoff Si C"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style tersoff"); + command("pair_coeff * * SiC.tersoff Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -683,12 +685,12 @@ TEST_F(PairUnitConvertTest, tersoff) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style tersoff"); - lmp->input->one("pair_coeff * * SiC.tersoff Si C"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style tersoff"); + command("pair_coeff * * SiC.tersoff Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -709,11 +711,11 @@ TEST_F(PairUnitConvertTest, tersoff_mod) if (!info->has_style("pair", "tersoff/mod")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style tersoff/mod"); - lmp->input->one("pair_coeff * * Si.tersoff.mod Si Si"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style tersoff/mod"); + command("pair_coeff * * Si.tersoff.mod Si Si"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -726,12 +728,12 @@ TEST_F(PairUnitConvertTest, tersoff_mod) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style tersoff/mod"); - lmp->input->one("pair_coeff * * Si.tersoff.mod Si Si"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style tersoff/mod"); + command("pair_coeff * * Si.tersoff.mod Si Si"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -752,11 +754,11 @@ TEST_F(PairUnitConvertTest, tersoff_mod_c) if (!info->has_style("pair", "tersoff/mod/c")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style tersoff/mod/c"); - lmp->input->one("pair_coeff * * Si.tersoff.modc Si Si"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style tersoff/mod/c"); + command("pair_coeff * * Si.tersoff.modc Si Si"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -769,12 +771,12 @@ TEST_F(PairUnitConvertTest, tersoff_mod_c) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style tersoff/mod/c"); - lmp->input->one("pair_coeff * * Si.tersoff.modc Si Si"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style tersoff/mod/c"); + command("pair_coeff * * Si.tersoff.modc Si Si"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -795,11 +797,11 @@ TEST_F(PairUnitConvertTest, tersoff_table) if (!info->has_style("pair", "tersoff/table")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style tersoff/table"); - lmp->input->one("pair_coeff * * SiC.tersoff Si C"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style tersoff/table"); + command("pair_coeff * * SiC.tersoff Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -812,12 +814,12 @@ TEST_F(PairUnitConvertTest, tersoff_table) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style tersoff/table"); - lmp->input->one("pair_coeff * * SiC.tersoff Si C"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style tersoff/table"); + command("pair_coeff * * SiC.tersoff Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -838,11 +840,11 @@ TEST_F(PairUnitConvertTest, tersoff_zbl) if (!info->has_style("pair", "tersoff/zbl")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style tersoff/zbl"); - lmp->input->one("pair_coeff * * SiC.tersoff.zbl Si C"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style tersoff/zbl"); + command("pair_coeff * * SiC.tersoff.zbl Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -855,12 +857,12 @@ TEST_F(PairUnitConvertTest, tersoff_zbl) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style tersoff/zbl"); - lmp->input->one("pair_coeff * * SiC.tersoff.zbl Si C"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style tersoff/zbl"); + command("pair_coeff * * SiC.tersoff.zbl Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -881,12 +883,12 @@ TEST_F(PairUnitConvertTest, tersoff_zbl_omp) if (!info->has_style("pair", "tersoff/zbl/omp")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("package omp 4"); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style tersoff/zbl/omp"); - lmp->input->one("pair_coeff * * SiC.tersoff.zbl Si C"); - lmp->input->one("run 0 post no"); + command("package omp 4"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style tersoff/zbl/omp"); + command("pair_coeff * * SiC.tersoff.zbl Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -899,13 +901,13 @@ TEST_F(PairUnitConvertTest, tersoff_zbl_omp) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("package omp 4"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style tersoff/zbl/omp"); - lmp->input->one("pair_coeff * * SiC.tersoff.zbl Si C"); - lmp->input->one("run 0 post no"); + command("clear"); + command("package omp 4"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style tersoff/zbl/omp"); + command("pair_coeff * * SiC.tersoff.zbl Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; @@ -926,11 +928,11 @@ TEST_F(PairUnitConvertTest, vashishta) if (!info->has_style("pair", "vashishta")) GTEST_SKIP(); if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style vashishta"); - lmp->input->one("pair_coeff * * SiC.vashishta Si C"); - lmp->input->one("run 0 post no"); + command("units metal"); + command("read_data test_pair_unit_convert.data"); + command("pair_style vashishta"); + command("pair_coeff * * SiC.vashishta Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); // copy pressure, energy, and force from first step @@ -943,12 +945,12 @@ TEST_F(PairUnitConvertTest, vashishta) fold[i][j] = f[i][j]; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("clear"); - lmp->input->one("units real"); - lmp->input->one("read_data test_pair_unit_convert.data"); - lmp->input->one("pair_style vashishta"); - lmp->input->one("pair_coeff * * SiC.vashishta Si C"); - lmp->input->one("run 0 post no"); + command("clear"); + command("units real"); + command("read_data test_pair_unit_convert.data"); + command("pair_style vashishta"); + command("pair_coeff * * SiC.vashishta Si C"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); double pnew; diff --git a/unittest/formats/test_potential_file_reader.cpp b/unittest/formats/test_potential_file_reader.cpp index 4279c8d1a7..6cf2fd010c 100644 --- a/unittest/formats/test_potential_file_reader.cpp +++ b/unittest/formats/test_potential_file_reader.cpp @@ -96,13 +96,15 @@ protected: delete lmp; if (!verbose) ::testing::internal::GetCapturedStdout(); } + + void command(const std::string &cmd) { lmp->input->one(cmd); } }; // open for native units TEST_F(PotentialFileReaderTest, Sw_native) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); + command("units metal"); PotentialFileReader reader(lmp, "Si.sw", "Stillinger-Weber"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -114,7 +116,7 @@ TEST_F(PotentialFileReaderTest, Sw_native) TEST_F(PotentialFileReaderTest, Sw_conv) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units real"); + command("units real"); PotentialFileReader reader(lmp, "Si.sw", "Stillinger-Weber", utils::METAL2REAL); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -126,7 +128,7 @@ TEST_F(PotentialFileReaderTest, Sw_conv) TEST_F(PotentialFileReaderTest, Sw_noconv) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units real"); + command("units real"); if (!verbose) ::testing::internal::GetCapturedStdout(); TEST_FAILURE(".*ERROR on proc.*potential.*requires metal units but real.*", @@ -136,7 +138,7 @@ TEST_F(PotentialFileReaderTest, Sw_noconv) TEST_F(PotentialFileReaderTest, Comb) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); + command("units metal"); PotentialFileReader reader(lmp, "ffield.comb", "COMB"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -147,7 +149,7 @@ TEST_F(PotentialFileReaderTest, Comb) TEST_F(PotentialFileReaderTest, Comb3) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); + command("units metal"); PotentialFileReader reader(lmp, "ffield.comb3", "COMB3"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -158,7 +160,7 @@ TEST_F(PotentialFileReaderTest, Comb3) TEST_F(PotentialFileReaderTest, Tersoff) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); + command("units metal"); PotentialFileReader reader(lmp, "Si.tersoff", "Tersoff"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -169,7 +171,7 @@ TEST_F(PotentialFileReaderTest, Tersoff) TEST_F(PotentialFileReaderTest, TersoffMod) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); + command("units metal"); PotentialFileReader reader(lmp, "Si.tersoff.mod", "Tersoff/Mod"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -180,7 +182,7 @@ TEST_F(PotentialFileReaderTest, TersoffMod) TEST_F(PotentialFileReaderTest, TersoffModC) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); + command("units metal"); PotentialFileReader reader(lmp, "Si.tersoff.modc", "Tersoff/ModC"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -191,7 +193,7 @@ TEST_F(PotentialFileReaderTest, TersoffModC) TEST_F(PotentialFileReaderTest, TersoffTable) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); + command("units metal"); PotentialFileReader reader(lmp, "Si.tersoff", "TersoffTable"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -202,7 +204,7 @@ TEST_F(PotentialFileReaderTest, TersoffTable) TEST_F(PotentialFileReaderTest, TersoffZBL) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); + command("units metal"); PotentialFileReader reader(lmp, "SiC.tersoff.zbl", "Tersoff/ZBL"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -213,7 +215,7 @@ TEST_F(PotentialFileReaderTest, TersoffZBL) TEST_F(PotentialFileReaderTest, GW) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); + command("units metal"); PotentialFileReader reader(lmp, "SiC.gw", "GW"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -224,7 +226,7 @@ TEST_F(PotentialFileReaderTest, GW) TEST_F(PotentialFileReaderTest, GWZBL) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); + command("units metal"); PotentialFileReader reader(lmp, "SiC.gw.zbl", "GW/ZBL"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -235,7 +237,7 @@ TEST_F(PotentialFileReaderTest, GWZBL) TEST_F(PotentialFileReaderTest, Nb3bHarmonic) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units real"); + command("units real"); PotentialFileReader reader(lmp, "MOH.nb3b.harmonic", "NB3B Harmonic"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -246,7 +248,7 @@ TEST_F(PotentialFileReaderTest, Nb3bHarmonic) TEST_F(PotentialFileReaderTest, Vashishta) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); + command("units metal"); PotentialFileReader reader(lmp, "SiC.vashishta", "Vashishta"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -260,7 +262,7 @@ TEST_F(PotentialFileReaderTest, UnitConvert) int unit_convert, flag; if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); + command("units metal"); reader = new PotentialFileReader(lmp, "Si.sw", "Stillinger-Weber"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -288,7 +290,7 @@ TEST_F(PotentialFileReaderTest, UnitConvert) if (!verbose) ::testing::internal::CaptureStdout(); flag = utils::get_supported_conversions(utils::ENERGY); - lmp->input->one("units real"); + command("units real"); reader = new PotentialFileReader(lmp, "Si.sw", "Stillinger-Weber", flag); if (!verbose) ::testing::internal::GetCapturedStdout(); diff --git a/unittest/utils/test_tokenizer.cpp b/unittest/utils/test_tokenizer.cpp index de7472599c..69ec7a55d2 100644 --- a/unittest/utils/test_tokenizer.cpp +++ b/unittest/utils/test_tokenizer.cpp @@ -112,7 +112,7 @@ TEST(Tokenizer, as_vector1) TEST(Tokenizer, as_vector2) { - auto list = Tokenizer("a\\b\\c","\\").as_vector(); + auto list = Tokenizer("a\\b\\c", "\\").as_vector(); ASSERT_THAT(list[0], Eq("a")); ASSERT_THAT(list[1], Eq("b")); ASSERT_THAT(list[2], Eq("c")); @@ -121,14 +121,14 @@ TEST(Tokenizer, as_vector2) TEST(Tokenizer, as_vector3) { - auto list = Tokenizer ("a\\","\\").as_vector(); + auto list = Tokenizer("a\\", "\\").as_vector(); ASSERT_THAT(list[0], Eq("a")); ASSERT_EQ(list.size(), 1); } TEST(Tokenizer, as_vector4) { - auto list = Tokenizer ("\\a","\\").as_vector(); + auto list = Tokenizer("\\a", "\\").as_vector(); ASSERT_THAT(list[0], Eq("a")); ASSERT_EQ(list.size(), 1); } diff --git a/unittest/utils/test_utils.cpp b/unittest/utils/test_utils.cpp index 2fa17a5e5a..56a88e330a 100644 --- a/unittest/utils/test_utils.cpp +++ b/unittest/utils/test_utils.cpp @@ -533,10 +533,12 @@ TEST(Utils, strfind_dot) TEST(Utils, strfind_kim) { - ASSERT_THAT(utils::strfind("n3409jfse MO_004835508849_000 aslfjiaf", - "[MS][MO]_\\d\\d\\d+_\\d\\d\\d"), StrEq("MO_004835508849_000")); + ASSERT_THAT( + utils::strfind("n3409jfse MO_004835508849_000 aslfjiaf", "[MS][MO]_\\d\\d\\d+_\\d\\d\\d"), + StrEq("MO_004835508849_000")); ASSERT_THAT(utils::strfind("VanDuinChakraborty_2003_CHNO__SM_107643900657_000", - "[MS][MO]_\\d\\d\\d+_\\d\\d\\d"), StrEq("SM_107643900657_000")); + "[MS][MO]_\\d\\d\\d+_\\d\\d\\d"), + StrEq("SM_107643900657_000")); } TEST(Utils, bounds_case1) From 51946205ce2b4f90c9b4d1c65a7fca6b9090e5a2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 24 Mar 2021 12:18:12 -0400 Subject: [PATCH 136/257] add YAML files for MLIAP nn and quadratic snap model input --- .../tests/manybody-pair-mliap_nn.yaml | 158 ++++++++++++++++++ ...l => manybody-pair-mliap_snap_linear.yaml} | 0 .../manybody-pair-mliap_snap_quadratic.yaml | 158 ++++++++++++++++++ 3 files changed, 316 insertions(+) create mode 100644 unittest/force-styles/tests/manybody-pair-mliap_nn.yaml rename unittest/force-styles/tests/{manybody-pair-mliap_snap.yaml => manybody-pair-mliap_snap_linear.yaml} (100%) create mode 100644 unittest/force-styles/tests/manybody-pair-mliap_snap_quadratic.yaml diff --git a/unittest/force-styles/tests/manybody-pair-mliap_nn.yaml b/unittest/force-styles/tests/manybody-pair-mliap_nn.yaml new file mode 100644 index 0000000000..5270c9571f --- /dev/null +++ b/unittest/force-styles/tests/manybody-pair-mliap_nn.yaml @@ -0,0 +1,158 @@ +--- +lammps_version: 10 Mar 2021 +date_generated: Wed Mar 24 12:18:23 202 +epsilon: 5e-13 +prerequisites: ! | + pair mliap + pair zbl +pre_commands: ! | + variable newton_pair delete + variable newton_pair index on +post_commands: ! "" +input_file: in.manybody +pair_style: hybrid/overlay zbl 4.0 4.8 mliap model nn Ta06A.nn.mliap.model descriptor + sna Ta06A.mliap.descriptor +pair_coeff: ! | + 1*8 1*8 zbl 73 73 + * * mliap Ta Ta Ta Ta Ta Ta Ta Ta +extract: ! "" +natoms: 64 +init_vdwl: -473.569864629026 +init_coul: 0 +init_stress: ! |2- + 3.9989504688551500e+02 4.0778136516736993e+02 4.3596322435184823e+02 -2.5242497284339720e+01 1.2811620806363655e+02 2.8644673361821793e+00 +init_forces: ! |2 + 1 -3.7538180163781538e+00 8.8612947043788708e+00 6.7712977816732263e+00 + 2 -7.6696525239232596e+00 -3.7674335682223203e-01 -5.7958054718422760e+00 + 3 -2.9221261341045079e-01 -1.2984917885683813e+00 2.2320440844884399e+00 + 4 -4.7103509354198474e+00 9.2783458784125941e+00 4.3108702582741429e+00 + 5 -2.0331946400488916e+00 -2.9593716047756180e+00 -1.6136351145373196e+00 + 6 1.8086748683348572e+00 4.6479727629048675e+00 3.0425695895915184e-01 + 7 -3.0573043543220644e+00 -4.0575899915120264e+00 1.5283788878527900e+00 + 8 2.7148403621334427e-01 1.3063473238306007e+00 -1.1268098385676173e+00 + 9 5.2043326273129953e-01 -2.9340446386399996e+00 -7.6461969078455834e+00 + 10 -6.2786875145099508e-01 5.6606570005199308e-02 -5.3746300485699576e+00 + 11 8.1946917251451818e+00 -6.7267140406524675e+00 2.5930013855034630e+00 + 12 -1.4328402235895087e+01 -8.0774309292156197e+00 -7.6980199570965677e+00 + 13 -3.2260600618006614e+00 1.3854745225224621e+01 -1.8038061855949390e+00 + 14 -2.9498732270039856e+00 8.5589611530655674e+00 2.0530716609447816e-01 + 15 -8.6349846297038031e+00 9.1996942753987270e+00 -9.5905201240123024e+00 + 16 3.7310502876344778e+00 1.9788328492752776e+00 1.5687925430243098e+01 + 17 5.0755393464331471e+00 6.1278868384113423e+00 -1.0750955741273682e+01 + 18 1.7371660543384140e+00 3.0620693584379239e+00 7.2701166654624991e+00 + 19 -2.9132243097469201e+00 -1.1018213008189437e+00 -2.8349170179881567e+00 + 20 -1.6464048708371479e+01 2.4791517492525559e+00 3.4072780064525732e-01 + 21 3.9250706073854098e+00 -1.0562396695052145e+00 -9.1632104209006702e+00 + 22 -1.5634125465245701e+01 8.9090677007239911e+00 -1.2750204519006148e+01 + 23 2.8936071278420723e+00 5.3816164530412767e+00 7.4597216732837071e+00 + 24 3.1860163425620680e+00 4.7170150104555253e+00 6.3461114127051133e+00 + 25 8.8078411119652245e-01 -1.4554648001614754e+00 1.6812657581308246e+00 + 26 -1.8170871697803546e+00 -3.7700946621067644e-01 6.2457161242680581e-01 + 27 4.3406014531279231e+00 -2.9009678649007267e+00 5.2435008444617139e+00 + 28 -7.0542478046177770e-01 1.0981989037209707e+00 1.3116499712117630e+01 + 29 -6.6151960592236154e+00 1.6410275382967996e+00 -1.0570398181017497e+00 + 30 -3.6949627314218070e+00 2.0505225752289262e+00 -1.5676706969561256e+00 + 31 -3.1645464836586603e+00 3.4678442856969571e-01 -3.0903933004746946e+00 + 32 -7.8831496558114571e+00 4.7917666582558249e-01 8.5821461480119510e-01 + 33 1.0742815926879523e+01 -5.8142728701457189e+00 9.7282423280124952e+00 + 34 -1.3523086688998047e+00 -1.1117518205645105e-01 1.6057041203339644e+00 + 35 2.5212001799950716e+00 -2.2938190564661185e+00 5.7029334689777986e+00 + 36 1.7666626040313700e+00 -4.4698105712986091e+00 2.0563602888032650e-01 + 37 -3.8714388913204467e+00 5.6357721515897250e+00 -6.6078854304621775e+00 + 38 1.4632813171776671e+00 -3.3182377007830244e-01 -8.4412322782161375e-01 + 39 4.1718406489245972e+00 -6.3270387696640586e+00 -1.1208012916569135e+01 + 40 9.5193696695210637e+00 -7.0213638399035432e+00 -1.5692669012530696e+00 + 41 2.4000089474497699e-01 1.0045144396502914e+00 -2.3032449685213630e+00 + 42 -9.4741999244791426e+00 -6.3134658287662750e+00 -3.6928028439517893e+00 + 43 2.7218639962411728e-01 -1.3813634477251096e+01 5.5147832931992291e-01 + 44 8.0196107396135208e+00 -8.1793730426384545e+00 3.5131695854462590e+00 + 45 -1.8910274064701343e-01 3.9137627573846219e+00 -7.4450993876429399e+00 + 46 -3.5282857552811575e+00 -5.1713579630178099e+00 1.2477491203990510e+01 + 47 5.1131478665605341e+00 2.3800985688973459e+00 5.1348001359881970e+00 + 48 2.1755560727357057e+00 2.9996491762493216e+00 -9.9575511910097214e-01 + 49 -2.3978299788760209e+00 -1.2283692236805253e+01 -8.3755937565454435e+00 + 50 3.6161933080447888e+00 5.6291551969069182e+00 -6.9709721613230968e-01 + 51 -3.0166275666360352e+00 1.1037977712957442e+01 8.8691052932904171e+00 + 52 1.2943573147098917e+01 -1.1745909799528654e+01 1.6522312348562508e+01 + 53 5.8389424736085775e+00 7.5295796786576226e+00 5.5403096028203525e+00 + 54 4.6678942858445893e+00 -5.7948610984030058e+00 -4.7138910958393971e+00 + 55 4.9846400582125163e+00 -8.4400769236810902e+00 -6.5776931744173313e+00 + 56 -3.5699586538966939e-02 1.5545384984529795e+00 -5.2139902048630429e+00 + 57 2.1375440189892982e+00 -1.3001299791681296e+00 -8.9740026386466654e-01 + 58 5.2652486142639416e+00 -2.5529130533710997e+00 2.0016357749193905e-01 + 59 9.0343971306644377e+00 4.2302611807585224e+00 -1.8088550980511922e+00 + 60 -5.1586404521695464e+00 -1.5178664164309549e+01 -9.8559725391424795e+00 + 61 9.6892046530364073e-01 3.6493959386458350e+00 -8.3809793809505195e-01 + 62 -6.2693637951458694e+00 5.5593866650560679e+00 -4.0417158962655781e+00 + 63 5.8570431431678962e+00 -6.2896068000076317e+00 -3.8788666930728688e+00 + 64 7.5837965251215369e+00 7.5954689486766096e+00 1.6804021764142011e+01 +run_vdwl: -473.666568306022 +run_coul: 0 +run_stress: ! |2- + 3.9951053758431499e+02 4.0757094669497650e+02 4.3599209936956868e+02 -2.5012844114476398e+01 1.2751742945242590e+02 3.9821818278564844e+00 +run_forces: ! |2 + 1 -3.7832595710893155e+00 8.8212124103655292e+00 6.7792549500694745e+00 + 2 -7.6693903913873163e+00 -4.4331479267505980e-01 -5.8319844453604492e+00 + 3 -3.5652510811236748e-01 -1.2843261396638010e+00 2.3164336943032460e+00 + 4 -4.6688281400123417e+00 9.2569804046918627e+00 4.2532553525093961e+00 + 5 -2.0698377683688305e+00 -3.0068940885360655e+00 -1.5557558367041349e+00 + 6 1.9121936983089021e+00 4.6485144224151016e+00 3.8302570899366983e-01 + 7 -3.0000564919294019e+00 -3.9598169423628935e+00 1.4730795882443171e+00 + 8 2.2616298546615310e-01 1.3160780554993146e+00 -1.1365737437456360e+00 + 9 4.5475496885290934e-01 -3.0115904820513633e+00 -7.6802788934953448e+00 + 10 -6.5754023848348220e-01 4.3910855294922169e-02 -5.2814927356947416e+00 + 11 8.0870811363765238e+00 -6.6478157150338770e+00 2.5239196033647513e+00 + 12 -1.4266979871278297e+01 -7.9890391049193692e+00 -7.6506348180232058e+00 + 13 -3.0605842642063994e+00 1.3809674690005217e+01 -1.6731082107132822e+00 + 14 -3.0058694850615257e+00 8.5169039650285132e+00 1.8498544937038552e-01 + 15 -8.6057398167379340e+00 9.1431278151038597e+00 -9.5164336499508586e+00 + 16 3.7105123804670184e+00 1.9684880085511294e+00 1.5628485674431591e+01 + 17 5.0446625217738115e+00 6.1086935560886335e+00 -1.0684670022014132e+01 + 18 1.6342572076662352e+00 3.0978003138559700e+00 7.3023410755539730e+00 + 19 -2.9853538081785418e+00 -1.1736228416330263e+00 -2.8772549755196275e+00 + 20 -1.6354717680325663e+01 2.4069036913441169e+00 2.5852528541413577e-01 + 21 3.9596059647558470e+00 -1.1309140461374385e+00 -9.2411865520092746e+00 + 22 -1.5578599385494211e+01 8.8837889458923414e+00 -1.2717012806950681e+01 + 23 2.9286474436436607e+00 5.4115499463398438e+00 7.4875237575502283e+00 + 24 3.2309052666659346e+00 4.6724691716691664e+00 6.3076914533727404e+00 + 25 8.7447853599857761e-01 -1.4447800235404800e+00 1.6369348219913344e+00 + 26 -1.8229284577405889e+00 -3.3721763232208768e-01 6.1531223202321172e-01 + 27 4.3482945496099807e+00 -2.9274873379719288e+00 5.2404893120488989e+00 + 28 -7.6160360457911214e-01 1.1530752576673735e+00 1.3094542130299224e+01 + 29 -6.6257114998810200e+00 1.6523572981586176e+00 -1.0670925651816274e+00 + 30 -3.6586042068050459e+00 2.0111737944853250e+00 -1.5501355511382873e+00 + 31 -3.1601602861552482e+00 3.3256891161094693e-01 -3.0724685917071382e+00 + 32 -7.8275016718590731e+00 4.4236506496773642e-01 8.3868054333668041e-01 + 33 1.0688722918141039e+01 -5.7920158261872583e+00 9.6923706747923646e+00 + 34 -1.3525464452783258e+00 -1.0575652830645854e-01 1.6380965403350563e+00 + 35 2.5193832475087721e+00 -2.2598987796878789e+00 5.6810280412635601e+00 + 36 1.7111787089042565e+00 -4.4473718671663391e+00 9.6398513850121076e-02 + 37 -3.8563809307986823e+00 5.6131073606614059e+00 -6.6177968130852260e+00 + 38 1.5064516388374909e+00 -3.1694753678232956e-01 -8.3526359314898979e-01 + 39 4.1314418694153812e+00 -6.2751004763663678e+00 -1.1210904504268449e+01 + 40 9.5830290785144836e+00 -7.0395435048262769e+00 -1.6267459470122683e+00 + 41 3.1375436243120802e-01 1.0622164383329200e+00 -2.2467935230672076e+00 + 42 -9.4881290346220375e+00 -6.3542967900678029e+00 -3.7436081761319060e+00 + 43 2.2855728522521823e-01 -1.3797673758210431e+01 5.1169123226999269e-01 + 44 8.0135824689800454e+00 -8.1618220152116709e+00 3.4767795780208774e+00 + 45 -2.2793629160624870e-01 3.8533578964252726e+00 -7.3720918772105994e+00 + 46 -3.5217473183911405e+00 -5.1375353430494126e+00 1.2535347493777751e+01 + 47 5.1244898311428937e+00 2.3801653011346930e+00 5.1114297013297003e+00 + 48 2.1906793040748171e+00 3.0345200169741182e+00 -1.0179863236095192e+00 + 49 -2.4788694934316329e+00 -1.2411071815396923e+01 -8.4971983039341392e+00 + 50 3.6569038614206466e+00 5.6055766933888798e+00 -7.2525721879624516e-01 + 51 -3.1071936932427051e+00 1.1143003955179145e+01 8.9003301745210983e+00 + 52 1.2953816665492676e+01 -1.1681525536724189e+01 1.6495289315845085e+01 + 53 5.8923317047264643e+00 7.6559750818830006e+00 5.7413363341910788e+00 + 54 4.6456819257039355e+00 -5.7613868673147293e+00 -4.6785882460677595e+00 + 55 4.9036275837635479e+00 -8.4131355466563491e+00 -6.4652425471547437e+00 + 56 -2.5919766291264371e-02 1.4942725648609447e+00 -5.1846171304946838e+00 + 57 2.1354464802186661e+00 -1.3197172317543322e+00 -8.9084444403811647e-01 + 58 5.2496503717062382e+00 -2.5023030575014631e+00 1.2534239362101771e-01 + 59 9.1088663289515797e+00 4.2501608997098561e+00 -1.8293706034164023e+00 + 60 -5.2377119984886820e+00 -1.5252944642880552e+01 -9.9884309435445626e+00 + 61 9.8418569822230928e-01 3.6718229831397404e+00 -7.9620939417097958e-01 + 62 -6.2529671270584286e+00 5.5348777429740972e+00 -3.9890515783571203e+00 + 63 5.8510809377900035e+00 -6.3420520892802621e+00 -3.9437203585924383e+00 + 64 7.6647749161376320e+00 7.7322248465188412e+00 1.6865884297614787e+01 +... diff --git a/unittest/force-styles/tests/manybody-pair-mliap_snap.yaml b/unittest/force-styles/tests/manybody-pair-mliap_snap_linear.yaml similarity index 100% rename from unittest/force-styles/tests/manybody-pair-mliap_snap.yaml rename to unittest/force-styles/tests/manybody-pair-mliap_snap_linear.yaml diff --git a/unittest/force-styles/tests/manybody-pair-mliap_snap_quadratic.yaml b/unittest/force-styles/tests/manybody-pair-mliap_snap_quadratic.yaml new file mode 100644 index 0000000000..475fc1caac --- /dev/null +++ b/unittest/force-styles/tests/manybody-pair-mliap_snap_quadratic.yaml @@ -0,0 +1,158 @@ +--- +lammps_version: 10 Mar 2021 +date_generated: Wed Mar 24 12:24:38 202 +epsilon: 5e-13 +prerequisites: ! | + pair mliap + pair zbl +pre_commands: ! | + variable newton_pair delete + variable newton_pair index on +post_commands: ! "" +input_file: in.manybody +pair_style: hybrid/overlay zbl 4.0 4.8 mliap model quadratic W.quadratic.mliap.model + descriptor sna W.quadratic.mliap.descriptor +pair_coeff: ! | + 1*8 1*8 zbl 74 74 + * * mliap W W W W W W W W +extract: ! "" +natoms: 64 +init_vdwl: 310.670038860846 +init_coul: 0 +init_stress: ! |2- + 5.6259528842196187e+02 5.7316629871796738e+02 5.8790591480137323e+02 -1.8189500835315549e+01 1.3614672500307736e+02 5.6212035897053383e+00 +init_forces: ! |2 + 1 -1.7332406552612252e+00 9.6965139437668633e+00 5.8109280039223741e+00 + 2 -8.4506855506966403e+00 1.7517630868906400e+00 -5.8585143024763751e+00 + 3 1.3067558540335114e+00 2.4533443839399922e+00 -5.3832194918864029e-01 + 4 -5.4997504048583030e+00 8.6507394288895618e+00 3.5210921442144869e+00 + 5 -5.4578004799253836e+00 -3.8166835957403560e+00 -1.9324965001410375e+00 + 6 1.8068295611859355e+00 7.7167110612740411e+00 2.2464754671860354e+00 + 7 -1.4615233556948404e+00 -4.5523205969121312e+00 5.2307165009286525e+00 + 8 1.3470528830761590e+00 1.1150099302890997e+00 -2.4124956929134638e+00 + 9 1.8536678547304528e+00 -5.9192817641183115e+00 -8.9231779770120117e+00 + 10 -1.6830129533144051e+00 -2.0004948002622096e+00 -6.7940188134883588e+00 + 11 9.3899899055663916e+00 -9.6096061996623181e+00 5.4294046031393410e+00 + 12 -1.8440182258152287e+01 -9.1578611598783599e+00 -6.9019373206621033e+00 + 13 -1.4789077352315048e+00 1.6126223605834220e+01 -2.3399418562200816e+00 + 14 -5.1192810384232743e+00 7.8887975887856649e+00 2.7987351355628833e+00 + 15 -1.1432288954023196e+01 1.2052925891647078e+01 -7.6561230955500186e+00 + 16 4.9875199325917112e+00 -7.9756500980837031e-01 1.5348327626794408e+01 + 17 3.0326448198662455e+00 1.0247763080256838e+01 -1.3162357502394531e+01 + 18 1.1912120343158321e+00 3.8795028741303881e+00 9.7535980505837134e+00 + 19 -4.1904376957856400e+00 -3.2045372808825174e+00 -1.1178952155997879e+00 + 20 -2.0524722840954009e+01 1.3584987641399842e+00 1.2643890965526294e+00 + 21 7.8962692301193274e+00 3.0756220916596053e+00 -1.0060035052224105e+01 + 22 -1.6638865872488534e+01 7.3242501928548176e+00 -1.1470088145525292e+01 + 23 3.1098873977160020e+00 8.9978923066815906e+00 7.3796685128197010e+00 + 24 3.7623303590129575e+00 3.9470381598445985e+00 8.3456006313463575e+00 + 25 2.7135762879995773e+00 1.2688233449033359e-01 2.7652325878214103e+00 + 26 -2.5567333671028858e+00 -1.5012729784955012e+00 3.8180756571583805e+00 + 27 5.4933629833598179e+00 -3.5852699914334007e-01 5.6772577899252621e+00 + 28 2.1583223591405485e+00 2.5602854563986126e+00 1.2987493211097293e+01 + 29 -9.3928065614100227e+00 8.1231719788253520e-01 -3.4139694444606663e+00 + 30 -6.5111025810175223e+00 3.9239227943865140e+00 -1.9909323666256402e+00 + 31 -4.5532920832558466e+00 2.9334735012590949e+00 -2.2603005294374805e+00 + 32 -1.1131319171235056e+01 4.0773060096293179e-01 2.3495354245782185e-01 + 33 1.1946312975015427e+01 -4.8997346173109610e+00 8.5135451343035555e+00 + 34 2.2567306848110924e-01 -9.7924723339198039e-01 1.7583322195512454e+00 + 35 2.8580692192724184e+00 -9.9224668537616911e-01 8.1615215594264985e+00 + 36 -9.5804648131257442e-02 -6.2355391184959963e+00 -1.1533359083409473e+00 + 37 -5.1866584177272408e+00 5.2276382338316552e+00 -9.4551207183301855e+00 + 38 -1.1543907922565189e+00 -1.2217116705851163e+00 7.8535042419588308e-01 + 39 7.5764294215464227e+00 -4.6563914581780939e+00 -1.4559998851452969e+01 + 40 1.1962426631242364e+01 -6.5095442931054395e+00 -3.2593809840204688e+00 + 41 4.2161422225881529e-01 -1.4729246940628351e+00 -4.8653082075157528e+00 + 42 -1.2872945210845128e+01 -6.7834573750437004e+00 -6.3019087398505946e-01 + 43 2.5785048972790117e+00 -1.6923099420445759e+01 -1.3360019377139212e+00 + 44 1.2291023950270986e+01 -1.2191603864766963e+01 2.7304006094143318e+00 + 45 -1.2398099447130371e+00 5.0658390044921555e+00 -9.2322482748129762e+00 + 46 -1.4311260929166141e+00 -5.6910264552445193e+00 1.3277999978308035e+01 + 47 6.2057343183031417e+00 3.7310981833648289e+00 4.8205098133270914e+00 + 48 3.3963650236743295e+00 2.0831245825926228e+00 -1.2673031459768591e+00 + 49 -1.8543360773247199e+00 -1.3380317233196116e+01 -8.4112300152561250e+00 + 50 -1.9920275269520710e-01 7.0107508582593869e+00 -2.6708325452002271e+00 + 51 -9.3660629689657249e-01 1.1809167034995344e+01 9.8986119959157612e+00 + 52 1.2220659999225337e+01 -1.2024509026677922e+01 1.4962970527017067e+01 + 53 7.4348387428600198e+00 7.7548706874243649e+00 4.1933368746931752e+00 + 54 7.0105713161150085e+00 -7.7007180274608169e+00 -6.5961935960226112e+00 + 55 3.2473798770902653e+00 -9.0385173613511878e+00 -8.5508326243716120e+00 + 56 4.2348804882267466e-01 4.3169490550492495e-01 -5.3478203134943731e+00 + 57 3.5009508489349979e+00 -3.3027079935021968e+00 -2.1184761311459956e+00 + 58 9.2468424036384231e+00 -4.5181490794556876e+00 2.4559890235342761e+00 + 59 9.9448793924013952e+00 4.5973129034833260e+00 -2.2322113512955504e+00 + 60 -3.6986806985028280e+00 -1.7543528229443428e+01 -1.0133821358926038e+01 + 61 -2.2233420196353229e+00 6.0781304306653574e+00 -1.8495331839082056e+00 + 62 -1.2719363808848012e+01 8.6073749589883608e+00 -4.9797073704539283e+00 + 63 7.9457470990016770e+00 -9.7673000016796276e+00 -4.3317841246475552e-01 + 64 9.3812874011747454e+00 7.3062141638106093e+00 2.1744814847410481e+01 +run_vdwl: 310.495392494539 +run_coul: 0 +run_stress: ! |2- + 5.6245390685235475e+02 5.7310155923142815e+02 5.8811705982147669e+02 -1.8382792415481248e+01 1.3530908723557451e+02 6.7996805811527254e+00 +run_forces: ! |2 + 1 -1.7474911328125362e+00 9.6453508706584969e+00 5.8264070485591564e+00 + 2 -8.4157283593600489e+00 1.6574874271599898e+00 -5.8310589262897814e+00 + 3 1.2088949261773574e+00 2.4669650164003505e+00 -4.1375090165872641e-01 + 4 -5.4649039359012761e+00 8.6435152499830856e+00 3.4462094837625115e+00 + 5 -5.4958328716797862e+00 -3.8484174335646353e+00 -1.8816778997456991e+00 + 6 1.9551787223560284e+00 7.7494231202147503e+00 2.2973472684776728e+00 + 7 -1.4123397167898091e+00 -4.4576559389423105e+00 5.1606908467828738e+00 + 8 1.3003903361118314e+00 1.1090418970773539e+00 -2.4122402377787160e+00 + 9 1.7752795626830657e+00 -5.9789440759859360e+00 -8.9434548975396595e+00 + 10 -1.7012447055310522e+00 -1.9935230569531357e+00 -6.6673307006625988e+00 + 11 9.2689566064779427e+00 -9.5287746372607316e+00 5.4104731087638704e+00 + 12 -1.8405278855921495e+01 -9.0991584859228194e+00 -6.8488708319775853e+00 + 13 -1.2996763830273808e+00 1.6069530823653931e+01 -2.2707313142490793e+00 + 14 -5.1882033738262070e+00 7.8832636277485548e+00 2.7916487158318102e+00 + 15 -1.1433449800945827e+01 1.2015094164432849e+01 -7.5825275115016781e+00 + 16 4.9454676036434462e+00 -7.8102971145205025e-01 1.5266194219606220e+01 + 17 3.0052148409052588e+00 1.0222703724442866e+01 -1.3093555057589381e+01 + 18 1.0836570454713836e+00 3.9100837051064552e+00 9.7948718675854156e+00 + 19 -4.2707464401127355e+00 -3.2934173316232527e+00 -1.1211010156027728e+00 + 20 -2.0392897715847305e+01 1.3054265260795233e+00 1.1968830911637141e+00 + 21 7.9027972563135283e+00 2.9933448022464120e+00 -1.0141811195436880e+01 + 22 -1.6575655480795024e+01 7.3026015885081472e+00 -1.1453084247555879e+01 + 23 3.1438035132341287e+00 9.0208182590437627e+00 7.4001520562013852e+00 + 24 3.8345333002034385e+00 3.8688922268567087e+00 8.2635479168723016e+00 + 25 2.6893003750410522e+00 1.3495734265712933e-01 2.6770556576379549e+00 + 26 -2.5895248886874898e+00 -1.4293305889359713e+00 3.8291245405081260e+00 + 27 5.5060054332311656e+00 -4.1092061919393136e-01 5.6759895801356688e+00 + 28 2.1307408306936098e+00 2.6175526554889608e+00 1.2958660769748445e+01 + 29 -9.3633952447569087e+00 8.2665579439215930e-01 -3.4012747321257448e+00 + 30 -6.4533544693943297e+00 3.8387646522939547e+00 -2.0200114390690862e+00 + 31 -4.5312579127038672e+00 2.9434281499085380e+00 -2.2589125870011584e+00 + 32 -1.1081437585586908e+01 3.5221507626974347e-01 1.7034641632139044e-01 + 33 1.1876109082707279e+01 -4.8655564590595244e+00 8.4901635945810785e+00 + 34 1.9834861495951994e-01 -9.7867922827610787e-01 1.7689988369185765e+00 + 35 2.8755972285806117e+00 -9.4201232104253185e-01 8.1427329437299605e+00 + 36 -1.7696676342095063e-01 -6.2050030582426956e+00 -1.2610314329006926e+00 + 37 -5.1523185432926066e+00 5.1647495629610471e+00 -9.4596116018450456e+00 + 38 -1.0982182558331921e+00 -1.1973914898033993e+00 8.2357032136004271e-01 + 39 7.5153819798537249e+00 -4.6353686206926801e+00 -1.4561478300809743e+01 + 40 1.2018485301986439e+01 -6.4889114819969862e+00 -3.3179507002516861e+00 + 41 5.3906537639254815e-01 -1.3597164515464635e+00 -4.7572664553057376e+00 + 42 -1.2853367469523606e+01 -6.8243263403454719e+00 -7.0954222980753212e-01 + 43 2.5285681786651231e+00 -1.6882295131334587e+01 -1.3986624925913076e+00 + 44 1.2309710907856807e+01 -1.2175400941985238e+01 2.6677164515852514e+00 + 45 -1.3287685848983446e+00 4.9721749381786715e+00 -9.1534484515246355e+00 + 46 -1.4302864380872948e+00 -5.6407929749476793e+00 1.3337675572559966e+01 + 47 6.2320161927247124e+00 3.7264499027617033e+00 4.8100453121557578e+00 + 48 3.4140183611989756e+00 2.1640838168269934e+00 -1.2936781336070275e+00 + 49 -1.9593115645555264e+00 -1.3493991739193522e+01 -8.5023532432195843e+00 + 50 -1.6811489988289596e-01 6.9681072464297396e+00 -2.7188888125967106e+00 + 51 -1.0469270161190001e+00 1.1884430462587432e+01 9.9090099481589125e+00 + 52 1.2258922313552624e+01 -1.1933013587721307e+01 1.4931067313457525e+01 + 53 7.4707442724281288e+00 7.8432472024360917e+00 4.3940747538426654e+00 + 54 6.9725677862692397e+00 -7.6678940689959383e+00 -6.5509217426800008e+00 + 55 3.1754349262716173e+00 -9.0126325358351416e+00 -8.4265432974728931e+00 + 56 4.0310136221619780e-01 3.3628916654912500e-01 -5.3158911291318605e+00 + 57 3.5009222797756716e+00 -3.3989600099867601e+00 -2.1369392158489036e+00 + 58 9.2532114410873234e+00 -4.4437952950838877e+00 2.3641140155667579e+00 + 59 1.0015845748025313e+01 4.6123938091542342e+00 -2.2569748666852796e+00 + 60 -3.7800808893756161e+00 -1.7584651166860183e+01 -1.0234679510276377e+01 + 61 -2.1980530287652753e+00 6.1071583911470810e+00 -1.7912415049492632e+00 + 62 -1.2705161798029133e+01 8.5765301471185520e+00 -4.9056271749898661e+00 + 63 7.9321561763633355e+00 -9.8033451737328594e+00 -4.9729640856821433e-01 + 64 9.4795662420049851e+00 7.4221786097433808e+00 2.1786648548971794e+01 +... From 9d3e37b1028b16ba14c3fed101e10036440333fd Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 24 Mar 2021 12:43:47 -0400 Subject: [PATCH 137/257] Add more python variable tests --- unittest/python/func.py | 10 ++-- unittest/python/test_python_package.cpp | 65 ++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/unittest/python/func.py b/unittest/python/func.py index 27704660a6..cc2269c435 100644 --- a/unittest/python/func.py +++ b/unittest/python/func.py @@ -4,6 +4,11 @@ from __future__ import print_function def square(val): return val*val +def bool_to_val(txt): + if txt.upper() in ["TRUE", "YES"]: + return 1.0 + return 0.0 + def printnum(): print("2.25") @@ -11,8 +16,7 @@ def printtxt(): print("sometext") def getidxvar(lmpptr): - from lammps import lammps, LMP_VAR_EQUAL + from lammps import lammps lmp = lammps(ptr=lmpptr) - - val = lmp.extract_variable("idx",None,LMP_VAR_EQUAL) + val = lmp.extract_variable("idx") print(val) diff --git a/unittest/python/test_python_package.cpp b/unittest/python/test_python_package.cpp index 137278a9d2..a7cf52c74e 100644 --- a/unittest/python/test_python_package.cpp +++ b/unittest/python/test_python_package.cpp @@ -14,6 +14,7 @@ #include "atom.h" #include "info.h" #include "input.h" +#include "variable.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -58,6 +59,13 @@ protected: return output; } + double get_variable_value(const std::string & name) { + char * str = utils::strdup(fmt::format("v_{}", name)); + double value = lmp->input->variable->compute_equal(str); + delete [] str; + return value; + } + void SetUp() override { const char *args[] = {"PythonPackageTest", "-log", "none", "-echo", "screen", "-nocite"}; @@ -100,13 +108,67 @@ TEST_F(PythonPackageTest, InvokeFunctionFromFile) HIDE_OUTPUT([&] { command("python printnum file ${input_dir}/func.py"); }); - + auto output = CAPTURE_OUTPUT([&]() { command("python printnum invoke"); }); ASSERT_THAT(output, HasSubstr("2.25\n")); } +TEST_F(PythonPackageTest, InvokeFunctionPassInt) +{ + // execute python function, passing integer as argument + HIDE_OUTPUT([&] { + command("variable sq python square"); + command("python square input 1 2 format ii return v_sq file ${input_dir}/func.py"); + }); + + ASSERT_EQ(get_variable_value("sq"), 4.0); +} + +TEST_F(PythonPackageTest, InvokeFunctionPassFloat) +{ + // execute python function, passing float as argument + HIDE_OUTPUT([&] { + command("variable sq python square"); + command("python square input 1 2.5 format ff return v_sq file ${input_dir}/func.py"); + }); + + ASSERT_EQ(get_variable_value("sq"), 6.25); +} + +TEST_F(PythonPackageTest, InvokeFunctionPassString) +{ + // execute python function, passing string as argument + HIDE_OUTPUT([&] { + command("variable val python bool_to_val"); + command("python bool_to_val input 1 \"true\" format sf return v_val file ${input_dir}/func.py"); + }); + + ASSERT_EQ(get_variable_value("val"), 1.0); +} + +TEST_F(PythonPackageTest, InvokeFunctionPassStringVariable) +{ + // execute python function, passing string variable as argument + HIDE_OUTPUT([&] { + command("variable val python bool_to_val"); + command("python bool_to_val input 1 v_str format sf return v_val file ${input_dir}/func.py"); + }); + + HIDE_OUTPUT([&] { + command("variable str string \"true\""); + }); + + ASSERT_EQ(get_variable_value("val"), 1.0); + + HIDE_OUTPUT([&] { + command("variable str string \"false\""); + }); + + ASSERT_EQ(get_variable_value("val"), 0.0); +} + TEST_F(PythonPackageTest, InvokeOtherFunctionFromFile) { // execute another python function from same file @@ -137,6 +199,7 @@ TEST_F(PythonPackageTest, InvokeFunctionThatUsesLAMMPSModule) TEST_F(PythonPackageTest, python_variable) { + // define variable that evaluates a python function HIDE_OUTPUT([&] { command("variable sq python square"); command("variable val index 1.5"); From cc54f553e0d09ecaa0a15881f1598c33765d2d9c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 24 Mar 2021 14:35:48 -0400 Subject: [PATCH 138/257] complete tests for if command booleans --- unittest/commands/test_variables.cpp | 56 ++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 7106867894..37856184eb 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -295,19 +295,25 @@ TEST_F(VariableTest, IfCommand) if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - command("if 1>0 then 'print \".*bingo!\"'"); + command("if 1>0 then 'print \"bingo!\"'"); auto text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ::testing::internal::CaptureStdout(); - command("if (1>=0) then 'print \"bingo!\"'"); + command("if 1>2 then 'print \"bingo!\"' else 'print \"nope?\"'"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, MatchesRegex(".*nope\?.*")); ::testing::internal::CaptureStdout(); - command("if (-1.0e-1<0.0E+0) then 'print \"bingo!\"'"); + command("if (1<=0) then 'print \"bingo!\"' else 'print \"nope?\"'"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*nope\?.*")); + + ::testing::internal::CaptureStdout(); + command("if (-1.0e-1<0.0E+0)|^(1<0) then 'print \"bingo!\"'"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); @@ -324,8 +330,50 @@ TEST_F(VariableTest, IfCommand) if (verbose) std::cout << text; ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + ::testing::internal::CaptureStdout(); + command("if (1>=2)&&(0&&1) then 'print \"missed\"' else 'print \"bingo!\"'"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + + ::testing::internal::CaptureStdout(); + command("if !1 then 'print \"missed\"' else 'print \"bingo!\"'"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + + ::testing::internal::CaptureStdout(); + command("if !(a==b) then 'print \"bingo!\"'"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + + ::testing::internal::CaptureStdout(); + command("if x==x|^1==0 then 'print \"bingo!\"'"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + + ::testing::internal::CaptureStdout(); + command("if x!=x|^a!=b then 'print \"bingo!\"'"); + text = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << text; + ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", command("if () then 'print \"bingo!\"'");); + TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", + command("if \"1 1\" then 'print \"bingo!\"'");); + TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", + command("if 1a then 'print \"bingo!\"'");); + TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", + command("if 1=<2 then 'print \"bingo!\"'");); + TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", + command("if 1!=a then 'print \"bingo!\"'");); + TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", + command("if 1&<2 then 'print \"bingo!\"'");); + TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", + command("if 1|<2 then 'print \"bingo!\"'");); TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", command("if (1)( then 'print \"bingo!\"'");); TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", From 407212153ff8a6d24d28dc12d86f209690a406c7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 24 Mar 2021 15:14:58 -0400 Subject: [PATCH 139/257] create more variables of different styles --- unittest/commands/test_variables.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 37856184eb..c558e02376 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -168,17 +168,22 @@ TEST_F(VariableTest, CreateDelete) command("variable nine file test_variable.file"); command("variable ten internal 1.0"); command("variable ten internal 10.0"); + command("variable ten1 universe 1 2 3 4"); + command("variable ten2 uloop 4"); + command("variable ten3 uloop 4 pad"); command("variable dummy index 0"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 13); + ASSERT_EQ(variable->nvar, 16); if (!verbose) ::testing::internal::CaptureStdout(); command("variable dummy delete"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 12); + ASSERT_EQ(variable->nvar, 15); TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable");); TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy index");); TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy delete xxx");); + TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy loop -1");); + TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy loop 10 1");); TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", command("variable two string xxx");); TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", @@ -191,6 +196,12 @@ TEST_F(VariableTest, CreateDelete) command("variable eleven atomfile test_variable.atomfile");); TEST_FAILURE(".*ERROR on proc 0: Cannot open file variable file test_variable.xxx.*", command("variable nine1 file test_variable.xxx");); + TEST_FAILURE(".*ERROR: World variable count doesn't match # of partitions.*", + command("variable ten10 world xxx xxx");); + TEST_FAILURE(".*ERROR: All universe/uloop variables must have same # of values.*", + command("variable ten4 uloop 2");); + TEST_FAILURE(".*ERROR: Incorrect conversion in format string.*", + command("variable ten11 format two \"%08f\"");); } TEST_F(VariableTest, AtomicSystem) @@ -204,8 +215,16 @@ TEST_F(VariableTest, AtomicSystem) command("variable id atom type"); command("variable id atom id"); command("variable ten atomfile test_variable.atomfile"); + command("compute press all pressure NULL pair"); + command("fix press all ave/time 1 1 1 c_press mode vector"); + command("variable press vector f_press"); + command("variable stress vector v_press+vol"); + command("variable pmax equal max(f_press)"); + command("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 3); + ASSERT_EQ(variable->nvar, 6); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_pmax"), 0.0); TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", command("variable one atom x");); From 1c9c46d2c1811531a18b05b10ec0f33f8104ecee Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 24 Mar 2021 15:42:38 -0400 Subject: [PATCH 140/257] Add tests to cover python command --- src/PYTHON/python_impl.cpp | 1 + unittest/python/func.py | 8 ++ unittest/python/run.py | 2 + unittest/python/test_python_package.cpp | 100 +++++++++++++++++++++++- 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 unittest/python/run.py diff --git a/src/PYTHON/python_impl.cpp b/src/PYTHON/python_impl.cpp index 1f45ca6635..4c43ca3744 100644 --- a/src/PYTHON/python_impl.cpp +++ b/src/PYTHON/python_impl.cpp @@ -506,6 +506,7 @@ int PythonImpl::create_entry(char *name) "cannot be used unless output is a string"); pfuncs[ifunc].length_longstr = length_longstr; pfuncs[ifunc].longstr = new char[length_longstr+1]; + pfuncs[ifunc].longstr[length_longstr] = '\0'; } if (strstr(ostr,"v_") != ostr) error->all(FLERR,"Invalid python command"); diff --git a/unittest/python/func.py b/unittest/python/func.py index cc2269c435..cf8db41670 100644 --- a/unittest/python/func.py +++ b/unittest/python/func.py @@ -9,6 +9,11 @@ def bool_to_val(txt): return 1.0 return 0.0 +def val_to_bool(val): + if val != 0: + return "True" + return "False" + def printnum(): print("2.25") @@ -20,3 +25,6 @@ def getidxvar(lmpptr): lmp = lammps(ptr=lmpptr) val = lmp.extract_variable("idx") print(val) + +def longstr(): + return "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent metus." diff --git a/unittest/python/run.py b/unittest/python/run.py new file mode 100644 index 0000000000..7cdb205f50 --- /dev/null +++ b/unittest/python/run.py @@ -0,0 +1,2 @@ +from __future__ import print_function +print("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent metus.") diff --git a/unittest/python/test_python_package.cpp b/unittest/python/test_python_package.cpp index a7cf52c74e..f7a184b6b3 100644 --- a/unittest/python/test_python_package.cpp +++ b/unittest/python/test_python_package.cpp @@ -15,6 +15,7 @@ #include "info.h" #include "input.h" #include "variable.h" +#include "library.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -31,11 +32,14 @@ std::string INPUT_FOLDER = STRINGIFY(TEST_INPUT_FOLDER); // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; +const char * LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent metus."; + using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { using ::testing::MatchesRegex; using ::testing::StrEq; +using ::testing::Eq; using ::testing::HasSubstr; class PythonPackageTest : public ::testing::Test { @@ -45,6 +49,8 @@ protected: void command(const std::string &line) { lmp->input->one(line.c_str()); } + void command_string(const std::string &lines) { lammps_commands_string(lmp, lines.c_str()); } + void HIDE_OUTPUT(std::function f) { if (!verbose) ::testing::internal::CaptureStdout(); f(); @@ -66,6 +72,10 @@ protected: return value; } + std::string get_variable_string(const std::string & name) { + return lmp->input->variable->retrieve(name.c_str()); + } + void SetUp() override { const char *args[] = {"PythonPackageTest", "-log", "none", "-echo", "screen", "-nocite"}; @@ -121,6 +131,7 @@ TEST_F(PythonPackageTest, InvokeFunctionPassInt) HIDE_OUTPUT([&] { command("variable sq python square"); command("python square input 1 2 format ii return v_sq file ${input_dir}/func.py"); + command("python square invoke"); }); ASSERT_EQ(get_variable_value("sq"), 4.0); @@ -169,6 +180,38 @@ TEST_F(PythonPackageTest, InvokeFunctionPassStringVariable) ASSERT_EQ(get_variable_value("val"), 0.0); } +TEST_F(PythonPackageTest, InvokeStringFunction) +{ + // execute python function, passing string variable as argument + HIDE_OUTPUT([&] { + command("variable str python val_to_bool"); + command("python val_to_bool input 1 v_val format is return v_str file ${input_dir}/func.py"); + }); + + HIDE_OUTPUT([&] { + command("variable val equal 0"); + }); + + ASSERT_THAT(get_variable_string("str"), StrEq("False")); + + HIDE_OUTPUT([&] { + command("variable val equal 1"); + }); + + ASSERT_THAT(get_variable_string("str"), StrEq("True")); +} + +TEST_F(PythonPackageTest, InvokeLongStringFunction) +{ + // execute python function, passing string variable as argument + HIDE_OUTPUT([&] { + command("variable str python longstr"); + command("python longstr format s length 72 return v_str file ${input_dir}/func.py"); + }); + + ASSERT_THAT(get_variable_string("str"), StrEq(LOREM_IPSUM)); +} + TEST_F(PythonPackageTest, InvokeOtherFunctionFromFile) { // execute another python function from same file @@ -211,6 +254,61 @@ TEST_F(PythonPackageTest, python_variable) ASSERT_THAT(output, MatchesRegex("print.*2.25.*")); } +TEST_F(PythonPackageTest, InlineFunction) +{ + // define variable that evaluates a python function + HIDE_OUTPUT([&] { + command("variable fact python factorial"); + command("python factorial input 1 v_n return v_fact format ii here \"\"\"\n" + "def factorial(n):\n" + " if n == 0 or n == 1: return 1\n" + " return n*factorial(n-1)\n" + "\"\"\""); + }); + + HIDE_OUTPUT([&] { + command("variable n equal 1"); + }); + + ASSERT_EQ(get_variable_value("fact"), 1.0); + + HIDE_OUTPUT([&] { + command("variable n equal 2"); + }); + + ASSERT_EQ(get_variable_value("fact"), 2.0); + + HIDE_OUTPUT([&] { + command("variable n equal 3"); + }); + + ASSERT_EQ(get_variable_value("fact"), 6.0); +} + +TEST_F(PythonPackageTest, RunSource) +{ + // execute python script from file + auto output = CAPTURE_OUTPUT([&] { + command("python xyz source ${input_dir}/run.py"); + }); + + ASSERT_THAT(output, HasSubstr(LOREM_IPSUM)); +} + +TEST_F(PythonPackageTest, RunSourceInline) +{ + // execute inline python script + auto output = CAPTURE_OUTPUT([&] { + command("python xyz source \"\"\"\n" + "from __future__ import print_function\n" + "print(2+2)\n" + "\"\"\"" + ); + }); + + ASSERT_THAT(output, HasSubstr("4")); +} + } // namespace LAMMPS_NS int main(int argc, char **argv) @@ -220,7 +318,7 @@ int main(int argc, char **argv) // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { - std::vector env = split_words(var); + auto env = split_words(var); for (auto arg : env) { if (arg == "-v") { verbose = true; From b15502ddc861526a72f4041896fbabc5e0b64337 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 24 Mar 2021 15:53:00 -0400 Subject: [PATCH 141/257] Add utils::split_lines --- src/utils.cpp | 8 ++++++++ src/utils.h | 6 ++++++ unittest/utils/test_utils.cpp | 17 +++++++++++++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/utils.cpp b/src/utils.cpp index b5576b9f27..e733d7eaae 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -851,6 +851,14 @@ std::vector utils::split_words(const std::string &text) return list; } +/* ---------------------------------------------------------------------- + Convert multi-line string into lines +------------------------------------------------------------------------- */ +std::vector utils::split_lines(const std::string &text) +{ + return Tokenizer(text, "\n").as_vector(); +} + /* ---------------------------------------------------------------------- Return whether string is a valid integer number ------------------------------------------------------------------------- */ diff --git a/src/utils.h b/src/utils.h index eab81f1343..ec4dd6ae85 100644 --- a/src/utils.h +++ b/src/utils.h @@ -321,6 +321,12 @@ namespace LAMMPS_NS { std::vector split_words(const std::string &text); + /** Take multi-line text and split into lines + * + * \param text string that should be split + * \return STL vector with the lines */ + std::vector split_lines(const std::string &text); + /** Check if string can be converted to valid integer * * \param str string that should be checked diff --git a/unittest/utils/test_utils.cpp b/unittest/utils/test_utils.cpp index 2fa17a5e5a..2a87f1c347 100644 --- a/unittest/utils/test_utils.cpp +++ b/unittest/utils/test_utils.cpp @@ -113,7 +113,7 @@ TEST(Utils, count_words_with_extra_spaces) TEST(Utils, split_words_simple) { - std::vector list = utils::split_words("one two three"); + auto list = utils::split_words("one two three"); ASSERT_EQ(list.size(), 3); ASSERT_THAT(list[0], StrEq("one")); ASSERT_THAT(list[1], StrEq("two")); @@ -122,7 +122,7 @@ TEST(Utils, split_words_simple) TEST(Utils, split_words_quoted) { - std::vector list = utils::split_words("one 'two' \"three\""); + auto list = utils::split_words("one 'two' \"three\""); ASSERT_EQ(list.size(), 3); ASSERT_THAT(list[0], StrEq("one")); ASSERT_THAT(list[1], StrEq("two")); @@ -131,7 +131,7 @@ TEST(Utils, split_words_quoted) TEST(Utils, split_words_escaped) { - std::vector list = utils::split_words("1\\' '\"two\"' 3\\\""); + auto list = utils::split_words("1\\' '\"two\"' 3\\\""); ASSERT_EQ(list.size(), 3); ASSERT_THAT(list[0], StrEq("1\\'")); ASSERT_THAT(list[1], StrEq("\"two\"")); @@ -140,13 +140,22 @@ TEST(Utils, split_words_escaped) TEST(Utils, split_words_quote_in_quoted) { - std::vector list = utils::split_words("one 't\\'wo' \"th\\\"ree\""); + auto list = utils::split_words("one 't\\'wo' \"th\\\"ree\""); ASSERT_EQ(list.size(), 3); ASSERT_THAT(list[0], StrEq("one")); ASSERT_THAT(list[1], StrEq("t\\'wo")); ASSERT_THAT(list[2], StrEq("th\\\"ree")); } +TEST(Utils, split_lines) +{ + auto list = utils::split_lines(" line 1\nline 2 \n line 3 \n"); + ASSERT_EQ(list.size(), 3); + ASSERT_THAT(list[0], StrEq(" line 1")); + ASSERT_THAT(list[1], StrEq("line 2 ")); + ASSERT_THAT(list[2], StrEq(" line 3 ")); +} + TEST(Utils, valid_integer1) { ASSERT_TRUE(utils::is_integer("10")); From 45191e9f7c3c21a8f445c3c9699037838bb382cf Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 24 Mar 2021 16:33:39 -0400 Subject: [PATCH 142/257] Refactor and add fix python/invoke tests --- unittest/python/test_python_package.cpp | 115 +++++++++++++----------- unittest/testing/core.h | 46 ++++++++-- unittest/testing/systems/melt.h | 28 +++--- 3 files changed, 117 insertions(+), 72 deletions(-) diff --git a/unittest/python/test_python_package.cpp b/unittest/python/test_python_package.cpp index f7a184b6b3..5a36112781 100644 --- a/unittest/python/test_python_package.cpp +++ b/unittest/python/test_python_package.cpp @@ -24,14 +24,14 @@ #include #include +#include "../testing/core.h" +#include "../testing/systems/melt.h" + // location of '*.py' files required by tests #define STRINGIFY(val) XSTR(val) #define XSTR(val) #val std::string INPUT_FOLDER = STRINGIFY(TEST_INPUT_FOLDER); -// whether to print verbose output (i.e. not capturing LAMMPS screen output). -bool verbose = false; - const char * LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent metus."; using LAMMPS_NS::utils::split_words; @@ -42,51 +42,12 @@ using ::testing::StrEq; using ::testing::Eq; using ::testing::HasSubstr; -class PythonPackageTest : public ::testing::Test { +class PythonPackageTest : public LAMMPSTest { protected: - LAMMPS *lmp; - Info *info; - - void command(const std::string &line) { lmp->input->one(line.c_str()); } - - void command_string(const std::string &lines) { lammps_commands_string(lmp, lines.c_str()); } - - void HIDE_OUTPUT(std::function f) { - if (!verbose) ::testing::internal::CaptureStdout(); - f(); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string CAPTURE_OUTPUT(std::function f) { - ::testing::internal::CaptureStdout(); - f(); - auto output = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << output; - return output; - } - - double get_variable_value(const std::string & name) { - char * str = utils::strdup(fmt::format("v_{}", name)); - double value = lmp->input->variable->compute_equal(str); - delete [] str; - return value; - } - - std::string get_variable_string(const std::string & name) { - return lmp->input->variable->retrieve(name.c_str()); - } - - void SetUp() override + void InitSystem() override { - const char *args[] = {"PythonPackageTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - HIDE_OUTPUT([&] { - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - }); - ASSERT_NE(lmp, nullptr); - info = new Info(lmp); if (!info->has_package("PYTHON")) GTEST_SKIP(); + HIDE_OUTPUT([&] { command("units real"); command("dimension 3"); @@ -100,15 +61,15 @@ protected: command("variable input_dir index " + INPUT_FOLDER); }); } +}; - void TearDown() override +class FixPythonInvokeTest : public MeltTest { +protected: + void InitSystem() override { - HIDE_OUTPUT([&] { - delete info; - delete lmp; - info = nullptr; - lmp = nullptr; - }); + if (!info->has_package("PYTHON")) GTEST_SKIP(); + + MeltTest::InitSystem(); } }; @@ -309,6 +270,56 @@ TEST_F(PythonPackageTest, RunSourceInline) ASSERT_THAT(output, HasSubstr("4")); } +TEST_F(FixPythonInvokeTest, end_of_step) +{ + HIDE_OUTPUT([&] { + command("python end_of_step_callback here \"\"\"\n" + "from __future__ import print_function\n" + "def end_of_step_callback(ptr):\n" + " print(\"PYTHON_END_OF_STEP\")\n" + "\"\"\""); + command("fix eos all python/invoke 10 end_of_step end_of_step_callback"); + }); + + auto output = CAPTURE_OUTPUT([&] { + command("run 50"); + }); + + auto lines = utils::split_lines(output); + int count = 0; + + for(auto & line : lines) { + if (line == "PYTHON_END_OF_STEP") ++count; + } + + ASSERT_EQ(count, 5); +} + +TEST_F(FixPythonInvokeTest, post_force) +{ + HIDE_OUTPUT([&] { + command("python post_force_callback here \"\"\"\n" + "from __future__ import print_function\n" + "def post_force_callback(ptr, vflag):\n" + " print(\"PYTHON_POST_FORCE\")\n" + "\"\"\""); + command("fix pf all python/invoke 10 post_force post_force_callback"); + }); + + auto output = CAPTURE_OUTPUT([&] { + command("run 50"); + }); + + auto lines = utils::split_lines(output); + int count = 0; + + for(auto & line : lines) { + if (line == "PYTHON_POST_FORCE") ++count; + } + + ASSERT_EQ(count, 5); +} + } // namespace LAMMPS_NS int main(int argc, char **argv) diff --git a/unittest/testing/core.h b/unittest/testing/core.h index 5852f7fd06..4dc15a5327 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -16,9 +16,12 @@ #include "info.h" #include "input.h" #include "lammps.h" +#include "variable.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include + using namespace LAMMPS_NS; using ::testing::MatchesRegex; @@ -45,29 +48,58 @@ class LAMMPSTest : public ::testing::Test { public: void command(const std::string &line) { lmp->input->one(line.c_str()); } + void HIDE_OUTPUT(std::function f) { + if (!verbose) ::testing::internal::CaptureStdout(); + f(); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + std::string CAPTURE_OUTPUT(std::function f) { + ::testing::internal::CaptureStdout(); + f(); + auto output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + return output; + } + + double get_variable_value(const std::string & name) { + char * str = utils::strdup(fmt::format("v_{}", name)); + double value = lmp->input->variable->compute_equal(str); + delete [] str; + return value; + } + + std::string get_variable_string(const std::string & name) { + return lmp->input->variable->retrieve(name.c_str()); + } + protected: const char *testbinary = "LAMMPSTest"; LAMMPS *lmp; + Info *info; void SetUp() override { const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + HIDE_OUTPUT([&] { + lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + info = new Info(lmp); + }); InitSystem(); - if (!verbose) ::testing::internal::GetCapturedStdout(); } virtual void InitSystem() {} void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - lmp = nullptr; - if (!verbose) ::testing::internal::GetCapturedStdout(); + HIDE_OUTPUT([&] { + delete info; + delete lmp; + info = nullptr; + lmp = nullptr; + }); } }; diff --git a/unittest/testing/systems/melt.h b/unittest/testing/systems/melt.h index 4189a6b771..5ac92f562b 100644 --- a/unittest/testing/systems/melt.h +++ b/unittest/testing/systems/melt.h @@ -19,23 +19,25 @@ class MeltTest : public LAMMPSTest { protected: virtual void InitSystem() override { - command("units lj"); - command("atom_style atomic"); - command("atom_modify map yes"); + HIDE_OUTPUT([&] { + command("units lj"); + command("atom_style atomic"); + command("atom_modify map yes"); - command("lattice fcc 0.8442"); - command("region box block 0 2 0 2 0 2"); - command("create_box 1 box"); - command("create_atoms 1 box"); - command("mass 1 1.0"); + command("lattice fcc 0.8442"); + command("region box block 0 2 0 2 0 2"); + command("create_box 1 box"); + command("create_atoms 1 box"); + command("mass 1 1.0"); - command("velocity all create 3.0 87287"); + command("velocity all create 3.0 87287"); - command("pair_style lj/cut 2.5"); - command("pair_coeff 1 1 1.0 1.0 2.5"); + command("pair_style lj/cut 2.5"); + command("pair_coeff 1 1 1.0 1.0 2.5"); - command("neighbor 0.3 bin"); - command("neigh_modify every 20 delay 0 check no"); + command("neighbor 0.3 bin"); + command("neigh_modify every 20 delay 0 check no"); + }); } }; From 157698543fa85ed6d849f5f1418d658b5e3f42d3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 24 Mar 2021 16:47:08 -0400 Subject: [PATCH 143/257] add tests for "next" command --- unittest/commands/test_variables.cpp | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index c558e02376..476874ec74 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -401,6 +401,47 @@ TEST_F(VariableTest, IfCommand) command("if (v_one==1.0)&&(2>=1) then 'print \"bingo!\"'");); } +TEST_F(VariableTest, NextCommand) +{ + file_vars(); + + if (!verbose) ::testing::internal::CaptureStdout(); + command("variable one index 1 2"); + command("variable two equal 2"); + command("variable three file test_variable.file"); + command("variable four loop 2 4"); + command("variable five index 1 2"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_one"), 1); + ASSERT_THAT(variable->retrieve("three"), StrEq("one")); + if (!verbose) ::testing::internal::CaptureStdout(); + command("next one"); + command("next three"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_one"), 2); + ASSERT_THAT(variable->retrieve("three"), StrEq("two")); + ASSERT_GE(variable->find("one"), 0); + if (!verbose) ::testing::internal::CaptureStdout(); + command("next one"); + command("next three"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + // index style variable is deleted if no more next element + ASSERT_EQ(variable->find("one"), -1); + ASSERT_GE(variable->find("three"), 0); + if (!verbose) ::testing::internal::CaptureStdout(); + command("next three"); + command("next three"); + command("next three"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + // file style variable is deleted if no more next element + ASSERT_EQ(variable->find("three"), -1); + + TEST_FAILURE(".*ERROR: Illegal next command.*", command("next");); + TEST_FAILURE(".*ERROR: Invalid variable 'xxx' in next command.*", command("next xxx");); + TEST_FAILURE(".*ERROR: Invalid variable style with next command.*", command("next two");); + TEST_FAILURE(".*ERROR: All variables in next command must have same style.*", + command("next five four");); +} } // namespace LAMMPS_NS int main(int argc, char **argv) From aab51fe70e5db178bdac8e5599751e9b2f9e1dba Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 24 Mar 2021 16:47:56 -0400 Subject: [PATCH 144/257] more coverage of utility functions in Variable class --- unittest/commands/test_variables.cpp | 61 +++++++++++++++++++++------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 476874ec74..30bbccf4d9 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -71,7 +71,8 @@ protected: void SetUp() override { - const char *args[] = {"VariableTest", "-log", "none", "-echo", "screen", "-nocite"}; + const char *args[] = {"VariableTest", "-log", "none", "-echo", "screen", + "-nocite", "-v", "num", "1"}; char **argv = (char **)args; int argc = sizeof(args) / sizeof(char *); if (!verbose) ::testing::internal::CaptureStdout(); @@ -150,7 +151,7 @@ protected: TEST_F(VariableTest, CreateDelete) { file_vars(); - ASSERT_EQ(variable->nvar, 0); + ASSERT_EQ(variable->nvar, 1); if (!verbose) ::testing::internal::CaptureStdout(); command("variable one index 1 2 3 4"); command("variable two equal 1"); @@ -160,7 +161,7 @@ TEST_F(VariableTest, CreateDelete) command("variable four1 loop 4"); command("variable four2 loop 2 4"); command("variable five1 loop 100 pad"); - command("variable five2 loop 100 200 pad"); + command("variable five2 loop 10 200 pad"); command("variable six world one"); command("variable seven format two \"%5.2f\""); command("variable eight getenv PWD"); @@ -173,17 +174,32 @@ TEST_F(VariableTest, CreateDelete) command("variable ten3 uloop 4 pad"); command("variable dummy index 0"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 16); + ASSERT_EQ(variable->nvar, 17); if (!verbose) ::testing::internal::CaptureStdout(); command("variable dummy delete"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 15); + ASSERT_EQ(variable->nvar, 16); + ASSERT_THAT(variable->retrieve("three"), StrEq("three")); + variable->set_string("three", "four"); + ASSERT_THAT(variable->retrieve("three"), StrEq("four")); + ASSERT_THAT(variable->retrieve("four2"), StrEq("2")); + ASSERT_THAT(variable->retrieve("five1"), StrEq("001")); + ASSERT_THAT(variable->retrieve("seven"), StrEq(" 2.00")); + ASSERT_THAT(variable->retrieve("ten"), StrEq("1")); + + ASSERT_EQ(variable->equalstyle(variable->find("one")), 0); + ASSERT_EQ(variable->equalstyle(variable->find("two")), 1); + ASSERT_EQ(variable->equalstyle(variable->find("ten")), 1); + + ASSERT_EQ(variable->internalstyle(variable->find("two")), 0); + ASSERT_EQ(variable->internalstyle(variable->find("ten")), 1); TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable");); TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy index");); TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy delete xxx");); TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy loop -1");); TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy loop 10 1");); + TEST_FAILURE(".*ERROR: Illegal variable command.*", command("variable dummy xxxx");); TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", command("variable two string xxx");); TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", @@ -202,6 +218,8 @@ TEST_F(VariableTest, CreateDelete) command("variable ten4 uloop 2");); TEST_FAILURE(".*ERROR: Incorrect conversion in format string.*", command("variable ten11 format two \"%08f\"");); + TEST_FAILURE(".*ERROR: Variable name 'ten@12' must have only alphanumeric characters or.*", + command("variable ten@12 index one two three");); } TEST_F(VariableTest, AtomicSystem) @@ -218,16 +236,28 @@ TEST_F(VariableTest, AtomicSystem) command("compute press all pressure NULL pair"); command("fix press all ave/time 1 1 1 c_press mode vector"); command("variable press vector f_press"); - command("variable stress vector v_press+vol"); - command("variable pmax equal max(f_press)"); + command("variable press vector f_press+vol"); + command("variable pmax equal max(v_press)"); + command("variable psum equal sum(v_press)"); command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 6); - ASSERT_DOUBLE_EQ(variable->compute_equal("v_pmax"), 0.0); + ASSERT_EQ(variable->nvar, 7); + + ASSERT_EQ(variable->atomstyle(variable->find("one")), 0); + ASSERT_EQ(variable->atomstyle(variable->find("id")), 1); + ASSERT_EQ(variable->atomstyle(variable->find("ten")), 1); + + ASSERT_EQ(variable->vectorstyle(variable->find("one")), 0); + ASSERT_EQ(variable->vectorstyle(variable->find("press")), 1); + + ASSERT_DOUBLE_EQ(variable->compute_equal("v_pmax"), 64.0); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_psum"), 6 * 64.0); TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", command("variable one atom x");); + TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", + command("variable one vector f_press");); TEST_FAILURE(".*ERROR on proc 0: Cannot open file variable file test_variable.xxx.*", command("variable ten1 atomfile test_variable.xxx");); } @@ -235,7 +265,7 @@ TEST_F(VariableTest, AtomicSystem) TEST_F(VariableTest, Expressions) { atomic_system(); - ASSERT_EQ(variable->nvar, 0); + ASSERT_EQ(variable->nvar, 1); if (!verbose) ::testing::internal::CaptureStdout(); command("variable one index 1"); command("variable two equal 2"); @@ -255,9 +285,10 @@ TEST_F(VariableTest, Expressions) command("variable ten6 equal (1<=v_one)&&(v_ten>=0.2)"); command("variable ten7 equal !(1set("dummy index 1 2"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 18); + ASSERT_EQ(variable->nvar, 21); int ivar = variable->find("one"); ASSERT_FALSE(variable->equalstyle(ivar)); @@ -282,6 +313,8 @@ TEST_F(VariableTest, Expressions) TEST_FAILURE(".*ERROR: Variable six: Invalid thermo keyword 'XXX' in variable formula.*", command("print \"${six}\"");); + TEST_FAILURE(".*ERROR: Variable ten9: has a circular dependency.*", + command("print \"${ten9}\"");); } TEST_F(VariableTest, Functions) @@ -289,14 +322,14 @@ TEST_F(VariableTest, Functions) atomic_system(); file_vars(); - ASSERT_EQ(variable->nvar, 0); + ASSERT_EQ(variable->nvar, 1); if (!verbose) ::testing::internal::CaptureStdout(); command("variable one index 1"); command("variable two equal random(1,2,643532)"); command("variable three equal atan2(v_one,1)"); command("variable four equal atan2()"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 4); + ASSERT_EQ(variable->nvar, 5); int ivar = variable->find("two"); ASSERT_GT(variable->compute_equal(ivar), 0.99); From 81e8676c7e8fe1566817decacc2f65cf4e5989fd Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 24 Mar 2021 17:10:15 -0400 Subject: [PATCH 145/257] Prepare python/move unittest --- unittest/force-styles/tests/py_nve.py | 75 +++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 unittest/force-styles/tests/py_nve.py diff --git a/unittest/force-styles/tests/py_nve.py b/unittest/force-styles/tests/py_nve.py new file mode 100644 index 0000000000..4740c85597 --- /dev/null +++ b/unittest/force-styles/tests/py_nve.py @@ -0,0 +1,75 @@ +from __future__ import print_function +from lammps import lammps, LAMMPS_INT, LAMMPS_DOUBLE + +class LAMMPSFix(object): + def __init__(self, ptr, group_name="all"): + self.lmp = lammps(ptr=ptr) + self.group_name = group_name + +class LAMMPSFixMove(LAMMPSFix): + def __init__(self, ptr, group_name="all"): + super(LAMMPSFixMove, self).__init__(ptr, group_name) + + def init(self): + pass + + def initial_integrate(self, vflag): + pass + + def final_integrate(self): + pass + + def initial_integrate_respa(self, vflag, ilevel, iloop): + pass + + def final_integrate_respa(self, ilevel, iloop): + pass + + def reset_dt(self): + pass + + +class NVE(LAMMPSFixMove): + """ Python implementation of fix/nve """ + def __init__(self, ptr, group_name="all"): + super(NVE, self).__init__(ptr) + assert(self.group_name == "all") + + def init(self): + dt = self.lmp.extract_global("dt") + ftm2v = self.lmp.extract_global("ftm2v") + self.ntypes = self.lmp.extract_global("ntypes") + self.dtv = dt + self.dtf = 0.5 * dt * ftm2v + + def initial_integrate(self, vflag): + nlocal = self.lmp.extract_global("nlocal") + mass = self.lmp.extract_atom("mass") + atype = self.lmp.extract_atom("type") + x = self.lmp.extract_atom("x") + v = self.lmp.extract_atom("v") + f = self.lmp.extract_atom("f") + + for i in range(nlocal): + dtfm = self.dtf / mass[int(atype[i])] + v[i][0] += dtfm * f[i][0] + v[i][1] += dtfm * f[i][1] + v[i][2] += dtfm * f[i][2] + x[i][0] += self.dtv * v[i][0] + x[i][1] += self.dtv * v[i][1] + x[i][2] += self.dtv * v[i][2] + + def final_integrate(self): + nlocal = self.lmp.extract_global("nlocal") + mass = self.lmp.extract_atom("mass") + atype = self.lmp.extract_atom("type") + v = self.lmp.extract_atom("v") + f = self.lmp.extract_atom("f") + + for i in range(nlocal): + dtfm = self.dtf / mass[int(atype[i])] + v[i][0] += dtfm * f[i][0] + v[i][1] += dtfm * f[i][1] + v[i][2] += dtfm * f[i][2] + + From b0bc0b9a2f0e39bf936a7b89b10eae3f218bf674 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 24 Mar 2021 17:54:10 -0400 Subject: [PATCH 146/257] Use time.strptime instead of datetime.strptime Embedding the Python interpreter multiple times in the same process can cause this issue due to import caching. https://bugs.python.org/issue27400 This seems to be avoidable by using the time module instead. --- python/lammps/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/lammps/__init__.py b/python/lammps/__init__.py index 48839273c5..e6ffd779a9 100644 --- a/python/lammps/__init__.py +++ b/python/lammps/__init__.py @@ -15,7 +15,7 @@ from .pylammps import * # convert module string version to numeric version def get_version_number(): - from datetime import datetime + import time from sys import version_info vstring = None if version_info.major == 3 and version_info.minor >= 8: @@ -32,7 +32,7 @@ def get_version_number(): if not vstring: return 0 - d = datetime.strptime(vstring, "%d%b%Y") - return d.year*10000 + d.month*100 + d.day + t = time.strptime(vstring, "%d%b%Y") + return t.tm_year*10000 + t.tm_mon*100 + t.tm_mday __version__ = get_version_number() From 55b0e33200dceda41397966f2c8999160c95e52d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 24 Mar 2021 18:01:48 -0400 Subject: [PATCH 147/257] fix typo --- doc/src/variable.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/variable.rst b/doc/src/variable.rst index ea6b7ef8ec..6a6cdf9a6d 100644 --- a/doc/src/variable.rst +++ b/doc/src/variable.rst @@ -429,7 +429,7 @@ argument. For *equal*\ -style variables the formula computes a scalar quantity, which becomes the value of the variable whenever it is evaluated. For *vector*\ -style variables the formula must compute a vector of quantities, which becomes the value of the variable whenever -it is evaluated. The calculated vector can be on length one, but it +it is evaluated. The calculated vector can be of length one, but it cannot be a simple scalar value like that produced by an equal-style compute. I.e. the formula for a vector-style variable must have at least one quantity in it that refers to a global vector produced by a From d04d326413760462d6e670d417610a6bb214514e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 24 Mar 2021 18:02:30 -0400 Subject: [PATCH 148/257] more tests for expressions and vector style variables --- unittest/commands/test_variables.cpp | 68 ++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 30bbccf4d9..f214dadd36 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -165,7 +165,7 @@ TEST_F(VariableTest, CreateDelete) command("variable six world one"); command("variable seven format two \"%5.2f\""); command("variable eight getenv PWD"); - command("variable eight getenv HOME"); + command("variable eight getenv XXXXX"); command("variable nine file test_variable.file"); command("variable ten internal 1.0"); command("variable ten internal 10.0"); @@ -186,6 +186,9 @@ TEST_F(VariableTest, CreateDelete) ASSERT_THAT(variable->retrieve("five1"), StrEq("001")); ASSERT_THAT(variable->retrieve("seven"), StrEq(" 2.00")); ASSERT_THAT(variable->retrieve("ten"), StrEq("1")); + ASSERT_THAT(variable->retrieve("eight"), StrEq("")); + variable->internal_set(variable->find("ten"), 2.5); + ASSERT_THAT(variable->retrieve("ten"), StrEq("2.5")); ASSERT_EQ(variable->equalstyle(variable->find("one")), 0); ASSERT_EQ(variable->equalstyle(variable->find("two")), 1); @@ -220,6 +223,10 @@ TEST_F(VariableTest, CreateDelete) command("variable ten11 format two \"%08f\"");); TEST_FAILURE(".*ERROR: Variable name 'ten@12' must have only alphanumeric characters or.*", command("variable ten@12 index one two three");); + TEST_FAILURE(".*ERROR: Variable evaluation before simulation box is defined.*", + variable->compute_equal("c_thermo_press");); + TEST_FAILURE(".*ERROR: Invalid variable reference v_unknown in variable formula.*", + variable->compute_equal("v_unknown");); } TEST_F(VariableTest, AtomicSystem) @@ -233,16 +240,29 @@ TEST_F(VariableTest, AtomicSystem) command("variable id atom type"); command("variable id atom id"); command("variable ten atomfile test_variable.atomfile"); - command("compute press all pressure NULL pair"); - command("fix press all ave/time 1 1 1 c_press mode vector"); - command("variable press vector f_press"); - command("variable press vector f_press+vol"); - command("variable pmax equal max(v_press)"); - command("variable psum equal sum(v_press)"); - command("run 0 post no"); + command("compute press all pressure NULL pair"); + command("compute rg all gyration"); + command("compute vacf all vacf"); + command("fix press all ave/time 1 1 1 c_press mode vector"); + command("fix rg all ave/time 1 1 1 c_rg mode vector"); + command("fix vacf all ave/time 1 1 1 c_vacf mode vector"); + + command("variable press vector f_press"); + command("variable rg vector f_rg"); + command("variable vacf vector f_vacf"); + command("variable press vector f_press+0.0"); + command("variable self vector v_self+f_press"); + command("variable circle vector f_press+v_circle"); + command("variable sum vector v_press+v_rg"); + command("variable sum2 vector v_vacf+v_rg"); + command("variable pmax equal max(v_press)"); + command("variable psum equal sum(v_press)"); + command("variable rgmax equal max(v_rg)"); + command("variable rgsum equal sum(v_rg)"); + command("variable loop equal v_loop+1"); + command("run 0 post no"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 7); ASSERT_EQ(variable->atomstyle(variable->find("one")), 0); ASSERT_EQ(variable->atomstyle(variable->find("id")), 1); @@ -251,8 +271,11 @@ TEST_F(VariableTest, AtomicSystem) ASSERT_EQ(variable->vectorstyle(variable->find("one")), 0); ASSERT_EQ(variable->vectorstyle(variable->find("press")), 1); - ASSERT_DOUBLE_EQ(variable->compute_equal("v_pmax"), 64.0); - ASSERT_DOUBLE_EQ(variable->compute_equal("v_psum"), 6 * 64.0); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_pmax"), 0.0); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_psum"), 0.0); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_rgmax"), 1.25); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_rgsum"), 3.75); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_sum[1]"), 1.25); TEST_FAILURE(".*ERROR: Cannot redefine variable as a different style.*", command("variable one atom x");); @@ -260,12 +283,17 @@ TEST_F(VariableTest, AtomicSystem) command("variable one vector f_press");); TEST_FAILURE(".*ERROR on proc 0: Cannot open file variable file test_variable.xxx.*", command("variable ten1 atomfile test_variable.xxx");); + TEST_FAILURE(".*ERROR: Variable loop: has a circular dependency.*", + variable->compute_equal("v_loop");); + TEST_FAILURE(".*Variable self: Vector-style variable in equal-style variable formula.*", + variable->compute_equal("v_self");); + TEST_FAILURE(".*ERROR: Variable sum2: Inconsistent lengths in vector-style variable.*", + variable->compute_equal("max(v_sum2)");); } TEST_F(VariableTest, Expressions) { atomic_system(); - ASSERT_EQ(variable->nvar, 1); if (!verbose) ::testing::internal::CaptureStdout(); command("variable one index 1"); command("variable two equal 2"); @@ -286,9 +314,13 @@ TEST_F(VariableTest, Expressions) command("variable ten7 equal !(12)+(1>=2)+(1&&0)+(0||0)+(1|^1)+10^0"); + command("variable err1 equal v_one/v_ten7"); + command("variable err2 equal v_one%v_ten7"); + command("variable err3 equal v_ten7^-v_one"); variable->set("dummy index 1 2"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 21); int ivar = variable->find("one"); ASSERT_FALSE(variable->equalstyle(ivar)); @@ -310,11 +342,19 @@ TEST_F(VariableTest, Expressions) ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten6"), 1); ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten7"), 0); ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten8"), 1); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten10"), 100); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten11"), 1); TEST_FAILURE(".*ERROR: Variable six: Invalid thermo keyword 'XXX' in variable formula.*", command("print \"${six}\"");); TEST_FAILURE(".*ERROR: Variable ten9: has a circular dependency.*", command("print \"${ten9}\"");); + TEST_FAILURE(".*ERROR on proc 0: Variable err1: Divide by 0 in variable formula.*", + command("print \"${err1}\"");); + TEST_FAILURE(".*ERROR on proc 0: Variable err2: Modulo 0 in variable formula.*", + command("print \"${err2}\"");); + TEST_FAILURE(".*ERROR on proc 0: Variable err3: Invalid power expression in variable formula.*", + command("print \"${err3}\"");); } TEST_F(VariableTest, Functions) @@ -322,14 +362,12 @@ TEST_F(VariableTest, Functions) atomic_system(); file_vars(); - ASSERT_EQ(variable->nvar, 1); if (!verbose) ::testing::internal::CaptureStdout(); command("variable one index 1"); command("variable two equal random(1,2,643532)"); command("variable three equal atan2(v_one,1)"); command("variable four equal atan2()"); if (!verbose) ::testing::internal::GetCapturedStdout(); - ASSERT_EQ(variable->nvar, 5); int ivar = variable->find("two"); ASSERT_GT(variable->compute_equal(ivar), 0.99); From 4fa5ce2dbccd5d6bdcffcce5cce9c2a3bc636585 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 24 Mar 2021 18:11:31 -0400 Subject: [PATCH 149/257] Remove unnecessary import --- unittest/force-styles/tests/py_nve.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/py_nve.py b/unittest/force-styles/tests/py_nve.py index 4740c85597..1f05be04a8 100644 --- a/unittest/force-styles/tests/py_nve.py +++ b/unittest/force-styles/tests/py_nve.py @@ -1,5 +1,5 @@ from __future__ import print_function -from lammps import lammps, LAMMPS_INT, LAMMPS_DOUBLE +from lammps import lammps class LAMMPSFix(object): def __init__(self, ptr, group_name="all"): From 3c41c12dbc0818b2e93165d436aed45430285188 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Wed, 24 Mar 2021 18:58:46 -0400 Subject: [PATCH 150/257] Add testcase for python/move --- unittest/force-styles/CMakeLists.txt | 2 +- unittest/force-styles/test_fix_timestep.cpp | 5 +- .../tests/fix-timestep-python_move_nve.yaml | 73 +++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 unittest/force-styles/tests/fix-timestep-python_move_nve.yaml diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index 02300b5ea2..60e83e7e16 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -124,7 +124,7 @@ file(GLOB FIX_TIMESTEP_TESTS LIST_DIRECTORIES false ${TEST_INPUT_FOLDER}/fix-tim foreach(TEST ${FIX_TIMESTEP_TESTS}) string(REGEX REPLACE "^.*fix-timestep-(.*)\.yaml" "FixTimestep:\\1" TNAME ${TEST}) add_test(NAME ${TNAME} COMMAND test_fix_timestep ${TEST} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:$ENV{PYTHONPATH}") + set_tests_properties(${TNAME} PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${TEST_INPUT_FOLDER}:${LAMMPS_PYTHON_DIR}:$ENV{PYTHONPATH}") endforeach() # dihedral style tester diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index e4b0fa6e02..aa07f36fb9 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -518,9 +518,12 @@ TEST(FixTimestep, plain) // rigid fixes need work to test properly with r-RESPA. // fix nve/limit cannot work with r-RESPA + // fix python/move implementation is missing library interface access to Repsa::step ifix = lmp->modify->find_fix("test"); if (!utils::strmatch(lmp->modify->fix[ifix]->style, "^rigid") && - !utils::strmatch(lmp->modify->fix[ifix]->style, "^nve/limit")) { + !utils::strmatch(lmp->modify->fix[ifix]->style, "^nve/limit") && + !utils::strmatch(lmp->modify->fix[ifix]->style, "^python/move") + ) { if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); diff --git a/unittest/force-styles/tests/fix-timestep-python_move_nve.yaml b/unittest/force-styles/tests/fix-timestep-python_move_nve.yaml new file mode 100644 index 0000000000..9c78dbe416 --- /dev/null +++ b/unittest/force-styles/tests/fix-timestep-python_move_nve.yaml @@ -0,0 +1,73 @@ +--- +lammps_version: 10 Mar 2021 +date_generated: Wed Mar 24 18:57:26 202 +epsilon: 9e-12 +prerequisites: ! | + atom full + fix python/move +pre_commands: ! "" +post_commands: ! | + fix test all python/move py_nve.NVE +input_file: in.fourmol +natoms: 29 +run_pos: ! |2 + 1 -2.7045559775384037e-01 2.4912159905679729e+00 -1.6695851791541885e-01 + 2 3.1004029573899528e-01 2.9612354631094391e+00 -8.5466363037021464e-01 + 3 -7.0398551400789477e-01 1.2305509955830618e+00 -6.2777526944456274e-01 + 4 -1.5818159336499285e+00 1.4837407818929933e+00 -1.2538710836062004e+00 + 5 -9.0719763672789266e-01 9.2652103885675297e-01 3.9954210488374786e-01 + 6 2.4831720524855985e-01 2.8313021497871271e-01 -1.2314233331711453e+00 + 7 3.4143527641386412e-01 -2.2646551041391422e-02 -2.5292291414903052e+00 + 8 1.1743552229100009e+00 -4.8863228565853950e-01 -6.3783432910825522e-01 + 9 1.3800524229500313e+00 -2.5274721030406683e-01 2.8353985887095157e-01 + 10 2.0510765220543883e+00 -1.4604063740302866e+00 -9.8323745081712954e-01 + 11 1.7878031944442556e+00 -1.9921863272948861e+00 -1.8890602447625777e+00 + 12 3.0063007039340053e+00 -4.9013350496963298e-01 -1.6231898107386229e+00 + 13 4.0515402959192999e+00 -8.9202011606653986e-01 -1.6400005529924957e+00 + 14 2.6066963345543819e+00 -4.1789253965514150e-01 -2.6634003608794394e+00 + 15 2.9695287185712913e+00 5.5422613165234036e-01 -1.2342022021790127e+00 + 16 2.6747029695228521e+00 -2.4124119054564295e+00 -2.3435746150616148e-02 + 17 2.2153577785283796e+00 -2.0897985186907717e+00 1.1963150794479436e+00 + 18 2.1369701704115704e+00 3.0158507413630606e+00 -3.5179348337215015e+00 + 19 1.5355837136087378e+00 2.6255292355375675e+00 -4.2353987779879052e+00 + 20 2.7727573005678776e+00 3.6923910449610169e+00 -3.9330842459133493e+00 + 21 4.9040128073204299e+00 -4.0752348172957946e+00 -3.6210314709891711e+00 + 22 4.3582355554440841e+00 -4.2126119427287048e+00 -4.4612844196314052e+00 + 23 5.7439382849307599e+00 -3.5821957939275029e+00 -3.8766361295935821e+00 + 24 2.0689243582422630e+00 3.1513346907271012e+00 3.1550389754828800e+00 + 25 1.3045351331492134e+00 3.2665125705842848e+00 2.5111855257433504e+00 + 26 2.5809237402711274e+00 4.0117602605482832e+00 3.2212060529089896e+00 + 27 -1.9611343130357228e+00 -4.3563411931359752e+00 2.1098293115523705e+00 + 28 -2.7473562684513411e+00 -4.0200819932379330e+00 1.5830052163433954e+00 + 29 -1.3126000191359855e+00 -3.5962518039482929e+00 2.2746342468737835e+00 +run_vel: ! |2 + 1 8.1705744183262364e-03 1.6516406176274288e-02 4.7902264318912978e-03 + 2 5.4501493445687759e-03 5.1791699408496334e-03 -1.4372931530376651e-03 + 3 -8.2298292722385643e-03 -1.2926551614621381e-02 -4.0984181178163881e-03 + 4 -3.7699042590093588e-03 -6.5722892098813799e-03 -1.1184640360133230e-03 + 5 -1.1021961004346586e-02 -9.8906780939335987e-03 -2.8410737829284395e-03 + 6 -3.9676663166400034e-02 4.6817061464710256e-02 3.7148491979476124e-02 + 7 9.1033953013898580e-04 -1.0128524411938794e-02 -5.1568251805019748e-02 + 8 7.9064712058855707e-03 -3.3507254552631767e-03 3.4557098492564629e-02 + 9 1.5644176117320923e-03 3.7365546102722164e-03 1.5047408822037646e-02 + 10 2.9201446820573174e-02 -2.9249578745486147e-02 -1.5018077424322538e-02 + 11 -4.7835961513517560e-03 -3.7481385134185206e-03 -2.3464104142290089e-03 + 12 2.2696451841920521e-03 -3.4774154398129479e-04 -3.0640770327796806e-03 + 13 2.7531740451953168e-03 5.8171061612840667e-03 -7.9467454022160518e-04 + 14 3.5246182371994252e-03 -5.7939995585585468e-03 -3.9478431172751344e-03 + 15 -1.8547943640122894e-03 -5.8554729942777743e-03 6.2938485140538649e-03 + 16 1.8681499973445245e-02 -1.3262466204585335e-02 -4.5638651457003243e-02 + 17 -1.2896269981100382e-02 9.7527665265956451e-03 3.7296535360836762e-02 + 18 -8.0065794848261610e-04 -8.6270473212554395e-04 -1.4483040697508738e-03 + 19 1.2452390836182623e-03 -2.5061097118772701e-03 7.2998631009712975e-03 + 20 3.5930060229597042e-03 3.6938860309252966e-03 3.2322732687893028e-03 + 21 -1.4689220370766550e-03 -2.7352129761527741e-04 7.0581624215243391e-04 + 22 -7.0694199254630339e-03 -4.2577148924878554e-03 2.8079117614251796e-04 + 23 6.0446963117374913e-03 -1.4000131614795382e-03 2.5819754847014255e-03 + 24 3.1926367902287940e-04 -9.9445664749276438e-04 1.4999996959365452e-04 + 25 1.3789754514814662e-04 -4.4335894884532569e-03 -8.1808136725080281e-04 + 26 2.0485904035217549e-03 2.7813358633835984e-03 4.3245727149206692e-03 + 27 4.5604120293369857e-04 -1.0305523026921137e-03 2.1188058381358511e-04 + 28 -6.2544520861855116e-03 1.4127711176146942e-03 -1.8429821884794269e-03 + 29 6.4110631534401762e-04 3.1273432719593867e-03 3.7253671105656715e-03 +... From a772c3b7d2ae9c981ce4712f6df1ab739d342640 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 24 Mar 2021 21:27:32 -0400 Subject: [PATCH 151/257] test a few more functions and constants --- unittest/commands/test_variables.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index f214dadd36..45183a2e54 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -316,6 +316,7 @@ TEST_F(VariableTest, Expressions) command("variable ten9 equal v_one-v_ten9"); command("variable ten10 internal 100.0"); command("variable ten11 equal (1!=1)+(2<1)+(2<=1)+(1>2)+(1>=2)+(1&&0)+(0||0)+(1|^1)+10^0"); + command("variable ten12 equal yes+no+on+off+true+false"); command("variable err1 equal v_one/v_ten7"); command("variable err2 equal v_one%v_ten7"); command("variable err3 equal v_ten7^-v_one"); @@ -344,6 +345,7 @@ TEST_F(VariableTest, Expressions) ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten8"), 1); ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten10"), 100); ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten11"), 1); + ASSERT_DOUBLE_EQ(variable->compute_equal("v_ten12"), 3); TEST_FAILURE(".*ERROR: Variable six: Invalid thermo keyword 'XXX' in variable formula.*", command("print \"${six}\"");); @@ -367,13 +369,27 @@ TEST_F(VariableTest, Functions) command("variable two equal random(1,2,643532)"); command("variable three equal atan2(v_one,1)"); command("variable four equal atan2()"); + command("variable five equal sqrt(v_one+v_one)"); + command("variable six equal exp(ln(0.1))"); + command("variable seven equal abs(log(1.0/100.0))"); + command("variable eight equal 0.5*PI"); + command("variable nine equal round(sin(v_eight)+cos(v_eight))"); + command("variable ten equal floor(1.85)+ceil(1.85)"); + command("variable ten1 equal tan(v_eight/2.0)"); + command("variable ten2 equal asin(-1.0)+acos(0.0)"); if (!verbose) ::testing::internal::GetCapturedStdout(); - int ivar = variable->find("two"); - ASSERT_GT(variable->compute_equal(ivar), 0.99); - ASSERT_LT(variable->compute_equal(ivar), 2.01); - ivar = variable->find("three"); - ASSERT_DOUBLE_EQ(variable->compute_equal(ivar), 0.25 * MY_PI); + ASSERT_GT(variable->compute_equal(variable->find("two")), 0.99); + ASSERT_LT(variable->compute_equal(variable->find("two")), 2.01); + ASSERT_DOUBLE_EQ(variable->compute_equal(variable->find("three")), 0.25 * MY_PI); + ASSERT_DOUBLE_EQ(variable->compute_equal(variable->find("five")), sqrt(2.0)); + ASSERT_DOUBLE_EQ(variable->compute_equal(variable->find("six")), 0.1); + ASSERT_DOUBLE_EQ(variable->compute_equal(variable->find("seven")), 2); + ASSERT_DOUBLE_EQ(variable->compute_equal(variable->find("nine")), 1); + ASSERT_DOUBLE_EQ(variable->compute_equal(variable->find("ten")), 3); + ASSERT_FLOAT_EQ(variable->compute_equal(variable->find("ten1")), 1); + ASSERT_DOUBLE_EQ(variable->compute_equal(variable->find("ten2")), 0); + TEST_FAILURE(".*ERROR: Variable four: Invalid syntax in variable formula.*", command("print \"${four}\"");); } From 6d6e2a7920bd9d98f50711f684b51ba527a0e842 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 24 Mar 2021 21:51:55 -0400 Subject: [PATCH 152/257] add simple check whether the compiled executable can actually run --- unittest/CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index c7f46a7f7b..f5d990d3ed 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -1,5 +1,14 @@ include(GTest) +# check if we can run the compiled executable and whether it prints +# the LAMMPS version header in the output for an empty input +file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/in.empty) +add_test(NAME RunLammps + COMMAND $ -log none -echo none -in in.empty + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +set_tests_properties(RunLammps PROPERTIES + PASS_REGULAR_EXPRESSION "^LAMMPS \\([0-9]+ [A-Za-z]+ 2[0-9][0-9][0-9]\\)") + if(BUILD_MPI) function(add_mpi_test) set(MPI_TEST_NUM_PROCS 1) From 28ac1fddc78376698c738e286cb2a0def55255ec Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 14:20:44 -0400 Subject: [PATCH 153/257] add tests for fix adapt with pairwise and coulomb interactions --- .../tests/fix-timestep-adapt_coul.yaml | 78 +++++++++++++++++++ .../tests/fix-timestep-adapt_pair.yaml | 77 ++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 unittest/force-styles/tests/fix-timestep-adapt_coul.yaml create mode 100644 unittest/force-styles/tests/fix-timestep-adapt_pair.yaml diff --git a/unittest/force-styles/tests/fix-timestep-adapt_coul.yaml b/unittest/force-styles/tests/fix-timestep-adapt_coul.yaml new file mode 100644 index 0000000000..4bf25f3b33 --- /dev/null +++ b/unittest/force-styles/tests/fix-timestep-adapt_coul.yaml @@ -0,0 +1,78 @@ +--- +lammps_version: 10 Mar 2021 +date_generated: Thu Mar 25 14:07:45 202 +epsilon: 1e-14 +prerequisites: ! | + atom full + fix adapt +pre_commands: ! | + variable scale equal ramp(0.5,1.0) +post_commands: ! | + fix move all nve + pair_style coul/long 8.0 + pair_coeff * * + kspace_style pppm 1.0e-5 + fix test solute adapt 1 pair coul/long scale * * v_scale kspace v_scale scale no +input_file: in.fourmol +natoms: 29 +run_pos: ! |2 + 1 -2.7585387890471996e-01 2.4721267521182790e+00 -1.7590741140808724e-01 + 2 3.0525219871189541e-01 2.9567528136379986e+00 -8.4936576402532038e-01 + 3 -6.9505003051265457e-01 1.2527081545845018e+00 -6.1997181046584049e-01 + 4 -1.5812017862079175e+00 1.4837803436802379e+00 -1.2534501022240629e+00 + 5 -9.0698616844921520e-01 9.2696438488362154e-01 3.9881670647678125e-01 + 6 2.9475212358066677e-01 2.3090672513870800e-01 -1.2850129871041163e+00 + 7 3.3910265413162427e-01 -9.8304106880631008e-03 -2.4646152989509647e+00 + 8 1.1651505006204030e+00 -4.8743821011767707e-01 -6.7114884751728299e-01 + 9 1.3774263981599719e+00 -2.5621838794437357e-01 2.7183404529472238e-01 + 10 2.0205575722774203e+00 -1.4247755749375353e+00 -9.7170370274694495e-01 + 11 1.7878178367325690e+00 -1.9913978116155537e+00 -1.8882122011553970e+00 + 12 3.0049755926663213e+00 -4.9113386667261005e-01 -1.6222548793223990e+00 + 13 4.0509873346708982e+00 -8.9189599256758900e-01 -1.6399664169684836e+00 + 14 2.6067290768076905e+00 -4.1787776166657575e-01 -2.6628987151232200e+00 + 15 2.9696220092443193e+00 5.5371700758037623e-01 -1.2345762790291681e+00 + 16 2.6502758794398509e+00 -2.3947260224551123e+00 3.7979604817656068e-02 + 17 2.2329379457566403e+00 -2.1019011639091216e+00 1.1489747581405534e+00 + 18 2.1370039459092824e+00 3.0160650231380983e+00 -3.5182461434707273e+00 + 19 1.5358245580755947e+00 2.6253262982024990e+00 -4.2345405067543185e+00 + 20 2.7723206208610200e+00 3.6917660744997280e+00 -3.9324445897897893e+00 + 21 4.9046698830002544e+00 -4.0744208992376789e+00 -3.6231785861154941e+00 + 22 4.3619404928241057e+00 -4.2118418466324723e+00 -4.4549778550789503e+00 + 23 5.7375471428283742e+00 -3.5861419285984151e+00 -3.8743083628403299e+00 + 24 2.0685472614153846e+00 3.1534292413678289e+00 3.1539268144873454e+00 + 25 1.3099248377134609e+00 3.2652552015323466e+00 2.5158443987470833e+00 + 26 2.5769610944059931e+00 4.0046351067750248e+00 3.2209102828198946e+00 + 27 -1.9616446495134594e+00 -4.3541288139763008e+00 2.1089564303871438e+00 + 28 -2.7409194780982360e+00 -4.0232390590132754e+00 1.5874446954442702e+00 + 29 -1.3169303967683006e+00 -3.6019395338314788e+00 2.2736834157327834e+00 +run_vel: ! |2 + 1 3.2647934948866072e-03 -1.0659515509476220e-03 -3.5596416446573862e-03 + 2 6.5461183155830240e-04 5.3408204488965814e-04 3.7281153774905299e-03 + 3 5.5824606761867453e-04 6.8767077705354802e-03 2.6081254050903369e-03 + 4 -3.0104306057251481e-03 -6.3737880755571717e-03 -5.7689309472175711e-04 + 5 -1.0695603162793169e-02 -9.3124438941875488e-03 -3.5561825582117166e-03 + 6 9.7217275192988716e-04 2.4037242875343898e-03 -1.4804194461220557e-03 + 7 -9.8813125701116859e-04 7.1676860005907047e-05 -4.9726864557309155e-04 + 8 5.7695861497255153e-04 -2.8105851335220203e-03 5.2330664783477206e-03 + 9 -1.4995649604676725e-03 3.1649947790849786e-06 2.0412648677152027e-03 + 10 1.5839012837707146e-03 3.0321007338515189e-03 -4.0872484640111792e-03 + 11 -4.7758918532801661e-03 -2.6593274143911529e-03 -1.1550198582046794e-03 + 12 9.0128567357444442e-04 -1.2761751259519178e-03 -2.0871137241467094e-03 + 13 2.1567295863873783e-03 5.8607859346030983e-03 -7.1626599947017036e-04 + 14 3.5355218381749455e-03 -5.7850299516532602e-03 -3.4518030258956843e-03 + 15 -1.7110094580322296e-03 -6.3503642729395085e-03 5.8528583997245172e-03 + 16 -1.3548756014535996e-03 1.4721717701533786e-03 3.4684968840172224e-03 + 17 1.2456371869895035e-03 7.2712506650925211e-05 -1.0263875344785681e-03 + 18 -7.6671852987712384e-04 -6.2725590016584319e-04 -1.7887461816215443e-03 + 19 1.5144560879023705e-03 -2.7339688331763923e-03 8.2529894052008699e-03 + 20 3.1192665056846264e-03 3.0118796973856330e-03 3.9267694079263664e-03 + 21 -8.3441863827979606e-04 5.2127470504020413e-04 -1.3858761585700890e-03 + 22 -3.4781949993989694e-03 -3.5196597997799125e-03 6.4236038889072932e-03 + 23 -1.5073299456798523e-04 -5.2285186251896619e-03 4.8604614163606421e-03 + 24 -6.9684359242923175e-05 1.0646658518855285e-03 -9.5542384314521332e-04 + 25 5.4585615099357566e-03 -5.7013984855115978e-03 3.7920245454784174e-03 + 26 -1.8076492725572590e-03 -4.1945707008573113e-03 4.0407648570027713e-03 + 27 -3.5547747026063570e-05 1.1321728960280906e-03 -6.3187029759558986e-04 + 28 -4.2637774879869998e-05 -1.6726973615869391e-03 2.4434056859341056e-03 + 29 -3.5302833519675510e-03 -2.4353648747156768e-03 2.8116576375086392e-03 +... diff --git a/unittest/force-styles/tests/fix-timestep-adapt_pair.yaml b/unittest/force-styles/tests/fix-timestep-adapt_pair.yaml new file mode 100644 index 0000000000..167f531b8e --- /dev/null +++ b/unittest/force-styles/tests/fix-timestep-adapt_pair.yaml @@ -0,0 +1,77 @@ +--- +lammps_version: 10 Mar 2021 +date_generated: Thu Mar 25 14:01:17 202 +epsilon: 1e-14 +prerequisites: ! | + atom full + fix adapt +pre_commands: ! | + variable epsilon equal ramp(0.01,0.03) +post_commands: ! | + fix move all nve + pair_style lj/cut 8.0 + pair_coeff * * 0.02 2.5 + fix test solute adapt 1 pair lj/cut epsilon * * v_epsilon scale no +input_file: in.fourmol +natoms: 29 +run_pos: ! |2 + 1 -3.2551307172152166e-01 2.4346451341937119e+00 -1.1396829659429568e-01 + 2 4.8617926885321056e-01 3.1070882859405997e+00 -1.0606347736697450e+00 + 3 -6.4277692336189840e-01 1.2540574692558419e+00 -6.5067148095539729e-01 + 4 -1.7124546848614086e+00 1.5199062846474698e+00 -1.3466731463120185e+00 + 5 -9.4318702684092770e-01 8.7036167560098177e-01 5.8107949039715845e-01 + 6 2.8417536732521353e-01 2.4411028847076369e-01 -1.2672995916002334e+00 + 7 3.3978105928826102e-01 -1.3702127966002052e-02 -2.4842417404954271e+00 + 8 1.1448702036571965e+00 -5.1199787721085332e-01 -7.6207631323785585e-01 + 9 1.4560807143664061e+00 -1.7028374483027719e-01 6.2141359752210135e-01 + 10 2.0382797810616289e+00 -1.4042635759560305e+00 -9.2654260470655225e-01 + 11 1.7519024690839582e+00 -2.0813293238835207e+00 -2.0333284515052927e+00 + 12 2.9787289051059695e+00 -5.2434906497210465e-01 -1.5904467995849627e+00 + 13 4.1953422217253049e+00 -9.4830119722648354e-01 -1.6427468797605889e+00 + 14 2.5500081793995157e+00 -4.0614435033397922e-01 -2.8121984203395161e+00 + 15 2.9657048145111777e+00 7.0300473914796602e-01 -1.1808819862439999e+00 + 16 2.6579963051616033e+00 -2.4005456919625914e+00 2.0005383723547647e-02 + 17 2.2277056239576578e+00 -2.0984522178633980e+00 1.1635464820238732e+00 + 18 2.1302246968151799e+00 2.9885050666882940e+00 -3.4237069257450177e+00 + 19 1.3456038469693135e+00 2.5038497935542385e+00 -4.4658170467307343e+00 + 20 2.9896625556783665e+00 3.9232215029072903e+00 -4.0788037150506025e+00 + 21 4.8757906644427553e+00 -4.1085999726993636e+00 -3.5248264027627227e+00 + 22 4.1728425444281765e+00 -4.2576916791274551e+00 -4.7519930504553214e+00 + 23 6.0419888290998678e+00 -3.4039201576442903e+00 -3.9699675670526715e+00 + 24 2.0885027685082749e+00 3.0623262332232590e+00 3.2053854817911325e+00 + 25 1.0405778226848383e+00 3.3092074961772369e+00 2.2889143046855063e+00 + 26 2.7667223704388135e+00 4.3243759349108064e+00 3.2424899041692892e+00 + 27 -1.9442324574216177e+00 -4.4528190486931383e+00 2.1453601072505339e+00 + 28 -3.0374110711029547e+00 -3.8950976773182124e+00 1.3869509742028494e+00 + 29 -1.0900141540951092e+00 -3.3361017662313661e+00 2.3288506481859019e+00 +run_vel: ! |2 + 1 -2.6363966609802322e-02 -2.1121682067821074e-02 3.6083903537541533e-02 + 2 1.1439082425218627e-01 9.6059686259844332e-02 -1.2808582493334400e-01 + 3 4.1111553959541365e-02 4.8218907676123458e-03 -2.0053345127339979e-02 + 4 -1.1200342113854607e-01 2.3479218026487367e-02 -7.8322526982440521e-02 + 5 -3.8701176979056742e-02 -5.4238808461352553e-02 1.3872068929223944e-01 + 6 -1.2123879257604515e-02 1.8312769875475924e-02 1.5946869603522588e-02 + 7 -2.8033909635229349e-04 -4.1270986674540478e-03 -2.1849258860351647e-02 + 8 -1.0170253112050078e-02 -1.7528863700725254e-02 -4.2491773012772370e-02 + 9 4.5241065101710616e-02 5.1469831376004180e-02 2.0995899436627763e-01 + 10 1.8368003566726739e-02 1.4179451083200369e-02 2.9470727636806446e-02 + 11 -3.2659358322720752e-02 -7.3493919093785873e-02 -1.1457396195350034e-01 + 12 -2.1332063889491135e-02 -2.8577988202947827e-02 2.3932097053094816e-02 + 13 1.2690181040869375e-01 -4.2622009579717637e-02 -3.2122980905022864e-03 + 14 -4.3986665577866770e-02 4.1189150738941797e-03 -1.2884939606320925e-01 + 15 -5.1087806082402770e-03 1.2103885273247751e-01 5.1598463273012998e-02 + 16 7.2721700595591750e-03 -5.1107380318211630e-03 -1.6206172124102816e-02 + 17 -4.5383051620802401e-03 3.8550131312268723e-03 1.5203146179855118e-02 + 18 -3.4035600174367278e-03 -1.6724199163900926e-02 5.8534078947667954e-02 + 19 -1.2309357029421318e-01 -8.2342186011711699e-02 -1.4270564232030267e-01 + 20 1.3831939524791759e-01 1.4683346823701657e-01 -8.6190510762895065e-02 + 21 -1.8190109221215101e-02 -2.0433705925500686e-02 5.9790597332019774e-02 + 22 -1.2248854674722252e-01 -3.2562959165287515e-02 -1.7942350258565937e-01 + 23 1.8820938314857302e-01 1.0738920901878871e-01 -5.3571267428950652e-02 + 24 1.3241508666550663e-02 -5.5202622564252735e-02 3.1590984003367552e-02 + 25 -1.6538995535147813e-01 2.1577200806135906e-02 -1.3992038866639564e-01 + 26 1.1598773628387443e-01 1.9315924859017630e-01 1.7906411933036825e-02 + 27 9.5161140946472839e-03 -6.0207807869183290e-02 2.1271816291477584e-02 + 28 -1.8165131190419664e-01 7.5944941014218031e-02 -1.2012012232111549e-01 + 29 1.3987378313944554e-01 1.6482908858701009e-01 3.7930623655713772e-02 +... From 27e31c4b151ae6c950d66fe630e45111fa4f4f90 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 14:49:49 -0400 Subject: [PATCH 154/257] simplify --- src/ASPHERE/compute_temp_asphere.cpp | 4 +--- src/BODY/compute_temp_body.cpp | 4 +--- src/GPU/fix_npt_gpu.cpp | 32 ++++++---------------------- src/GPU/fix_nvt_gpu.cpp | 19 ++++------------- src/USER-OMP/fix_npt_omp.cpp | 27 ++++------------------- src/USER-OMP/fix_nvt_omp.cpp | 14 ++---------- 6 files changed, 18 insertions(+), 82 deletions(-) diff --git a/src/ASPHERE/compute_temp_asphere.cpp b/src/ASPHERE/compute_temp_asphere.cpp index 2fe2e9699c..9afae4d2d9 100644 --- a/src/ASPHERE/compute_temp_asphere.cpp +++ b/src/ASPHERE/compute_temp_asphere.cpp @@ -58,9 +58,7 @@ ComputeTempAsphere::ComputeTempAsphere(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal compute temp/asphere command"); tempbias = 1; - int n = strlen(arg[iarg+1]) + 1; - id_bias = new char[n]; - strcpy(id_bias,arg[iarg+1]); + id_bias = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"dof") == 0) { if (iarg+2 > narg) diff --git a/src/BODY/compute_temp_body.cpp b/src/BODY/compute_temp_body.cpp index 730a857aec..fb16723b23 100644 --- a/src/BODY/compute_temp_body.cpp +++ b/src/BODY/compute_temp_body.cpp @@ -56,9 +56,7 @@ ComputeTempBody::ComputeTempBody(LAMMPS *lmp, int narg, char **arg) : if (iarg+2 > narg) error->all(FLERR,"Illegal compute temp/body command"); tempbias = 1; - int n = strlen(arg[iarg+1]) + 1; - id_bias = new char[n]; - strcpy(id_bias,arg[iarg+1]); + id_bias = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"dof") == 0) { if (iarg+2 > narg) diff --git a/src/GPU/fix_npt_gpu.cpp b/src/GPU/fix_npt_gpu.cpp index 2ba0be29e0..073d5dc6c1 100644 --- a/src/GPU/fix_npt_gpu.cpp +++ b/src/GPU/fix_npt_gpu.cpp @@ -25,44 +25,24 @@ FixNPTGPU::FixNPTGPU(LAMMPS *lmp, int narg, char **arg) : FixNHGPU(lmp, narg, arg) { if (!tstat_flag) - error->all(FLERR,"Temperature control must be used with fix npt/omp"); + error->all(FLERR,"Temperature control must be used with fix npt/gpu"); if (!pstat_flag) - error->all(FLERR,"Pressure control must be used with fix npt/omp"); + error->all(FLERR,"Pressure control must be used with fix npt/gpu"); // create a new compute temp style // id = fix-ID + temp // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(id_temp+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(std::string(id_press)+" all pressure "+id_temp); pcomputeflag = 1; } diff --git a/src/GPU/fix_nvt_gpu.cpp b/src/GPU/fix_nvt_gpu.cpp index 7d7826b6bf..6858c26497 100644 --- a/src/GPU/fix_nvt_gpu.cpp +++ b/src/GPU/fix_nvt_gpu.cpp @@ -26,25 +26,14 @@ FixNVTGPU::FixNVTGPU(LAMMPS *lmp, int narg, char **arg) : FixNHGPU(lmp, narg, arg) { if (!tstat_flag) - error->all(FLERR,"Temperature control must be used with fix nvt"); + error->all(FLERR,"Temperature control must be used with fix nvt/gpu"); if (pstat_flag) - error->all(FLERR,"Pressure control can not be used with fix nvt"); + error->all(FLERR,"Pressure control can not be used with fix nvt/gpu"); // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; } - diff --git a/src/USER-OMP/fix_npt_omp.cpp b/src/USER-OMP/fix_npt_omp.cpp index f3f08c15c2..54328803f4 100644 --- a/src/USER-OMP/fix_npt_omp.cpp +++ b/src/USER-OMP/fix_npt_omp.cpp @@ -34,35 +34,16 @@ FixNPTOMP::FixNPTOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(std::string(id_press)+" all pressure "+id_temp); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_nvt_omp.cpp b/src/USER-OMP/fix_nvt_omp.cpp index bfa2dcbe49..127876b4e8 100644 --- a/src/USER-OMP/fix_nvt_omp.cpp +++ b/src/USER-OMP/fix_nvt_omp.cpp @@ -33,17 +33,7 @@ FixNVTOMP::FixNVTOMP(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; } From 4efe60ec43e6fba31b9eebfb383ff5dac762097b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 17:14:57 -0400 Subject: [PATCH 155/257] compatibility with older CMake versions --- unittest/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index f5d990d3ed..4e27f4be45 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -2,7 +2,7 @@ include(GTest) # check if we can run the compiled executable and whether it prints # the LAMMPS version header in the output for an empty input -file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/in.empty) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/in.empty "") add_test(NAME RunLammps COMMAND $ -log none -echo none -in in.empty WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) From 2b34d88b71ce3b3757b1cfbf991e422b8d92e0bb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 17:19:03 -0400 Subject: [PATCH 156/257] fix bug --- src/GPU/fix_npt_gpu.cpp | 2 +- src/USER-OMP/fix_npt_omp.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/GPU/fix_npt_gpu.cpp b/src/GPU/fix_npt_gpu.cpp index 073d5dc6c1..3847f31a65 100644 --- a/src/GPU/fix_npt_gpu.cpp +++ b/src/GPU/fix_npt_gpu.cpp @@ -35,7 +35,7 @@ FixNPTGPU::FixNPTGPU(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(id_temp+" all temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style diff --git a/src/USER-OMP/fix_npt_omp.cpp b/src/USER-OMP/fix_npt_omp.cpp index 54328803f4..4037dd928e 100644 --- a/src/USER-OMP/fix_npt_omp.cpp +++ b/src/USER-OMP/fix_npt_omp.cpp @@ -34,7 +34,6 @@ FixNPTOMP::FixNPTOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - id_temp = utils::strdup(std::string(id)+"_temp"); modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; From 2baafda5171a8bf3291162ba4ef225b395695728 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 17:19:11 -0400 Subject: [PATCH 157/257] simplify --- src/USER-OMP/fix_nph_omp.cpp | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/USER-OMP/fix_nph_omp.cpp b/src/USER-OMP/fix_nph_omp.cpp index ba7f6e6c26..8c2f9ed3a3 100644 --- a/src/USER-OMP/fix_nph_omp.cpp +++ b/src/USER-OMP/fix_nph_omp.cpp @@ -34,35 +34,15 @@ FixNPHOMP::FixNPHOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(std::string(id_press)+" all pressure "+id_temp); pcomputeflag = 1; } From 53f32cea7e2b42c3ea3bf915ef3dfc3db4be6796 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 19:42:41 -0400 Subject: [PATCH 158/257] simplify using utils::strdup() --- src/GRANULAR/fix_pour.cpp | 8 ++----- src/GRANULAR/fix_wall_gran.cpp | 4 +--- src/KOKKOS/atom_kokkos.cpp | 8 ++----- src/KOKKOS/atom_vec_hybrid_kokkos.cpp | 9 +++----- src/KOKKOS/fix_nph_kokkos.cpp | 33 ++++++--------------------- src/KOKKOS/fix_npt_kokkos.cpp | 33 ++++++--------------------- src/KOKKOS/fix_nvt_kokkos.cpp | 18 ++++----------- 7 files changed, 26 insertions(+), 87 deletions(-) diff --git a/src/GRANULAR/fix_pour.cpp b/src/GRANULAR/fix_pour.cpp index 3b93722426..08dae55d17 100644 --- a/src/GRANULAR/fix_pour.cpp +++ b/src/GRANULAR/fix_pour.cpp @@ -948,18 +948,14 @@ void FixPour::options(int narg, char **arg) } else if (strcmp(arg[iarg],"rigid") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix pour command"); - int n = strlen(arg[iarg+1]) + 1; delete [] idrigid; - idrigid = new char[n]; - strcpy(idrigid,arg[iarg+1]); + idrigid = utils::strdup(arg[iarg+1]); rigidflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"shake") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix pour command"); - int n = strlen(arg[iarg+1]) + 1; delete [] idshake; - idshake = new char[n]; - strcpy(idshake,arg[iarg+1]); + idshake = utils::strdup(arg[iarg+1]); shakeflag = 1; iarg += 2; diff --git a/src/GRANULAR/fix_wall_gran.cpp b/src/GRANULAR/fix_wall_gran.cpp index 73d2a2f8ba..d18b72aa65 100644 --- a/src/GRANULAR/fix_wall_gran.cpp +++ b/src/GRANULAR/fix_wall_gran.cpp @@ -338,9 +338,7 @@ FixWallGran::FixWallGran(LAMMPS *lmp, int narg, char **arg) : } else if (strcmp(arg[iarg],"region") == 0) { if (narg < iarg+2) error->all(FLERR,"Illegal fix wall/gran command"); wallstyle = REGION; - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); iarg += 2; } diff --git a/src/KOKKOS/atom_kokkos.cpp b/src/KOKKOS/atom_kokkos.cpp index c41a42c99a..19cfe02c96 100644 --- a/src/KOKKOS/atom_kokkos.cpp +++ b/src/KOKKOS/atom_kokkos.cpp @@ -257,9 +257,7 @@ int AtomKokkos::add_custom(const char *name, int flag) nivector++; iname = (char **) memory->srealloc(iname,nivector*sizeof(char *), "atom:iname"); - int n = strlen(name) + 1; - iname[index] = new char[n]; - strcpy(iname[index],name); + iname[index] = utils::strdup(name); ivector = (int **) memory->srealloc(ivector,nivector*sizeof(int *), "atom:ivector"); memory->create(ivector[index],nmax,"atom:ivector"); @@ -268,9 +266,7 @@ int AtomKokkos::add_custom(const char *name, int flag) ndvector++; dname = (char **) memory->srealloc(dname,ndvector*sizeof(char *), "atom:dname"); - int n = strlen(name) + 1; - dname[index] = new char[n]; - strcpy(dname[index],name); + dname[index] = utils::strdup(name); this->sync(Device,DVECTOR_MASK); memoryKK->grow_kokkos(k_dvector,dvector,ndvector,nmax, "atom:dvector"); diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp index f1390f754b..907d1d555f 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp @@ -72,8 +72,7 @@ void AtomVecHybridKokkos::process_args(int narg, char **arg) if (strcmp(arg[iarg],keywords[i]) == 0) error->all(FLERR,"Atom style hybrid cannot use same atom style twice"); styles[nstyles] = atom->new_avec(arg[iarg],1,dummy); - keywords[nstyles] = new char[strlen(arg[iarg])+1]; - strcpy(keywords[nstyles],arg[iarg]); + keywords[nstyles] = utils::strdup(arg[iarg]); jarg = iarg + 1; while (jarg < narg && !known_style(arg[jarg])) jarg++; styles[nstyles]->process_args(jarg-iarg-1,&arg[iarg+1]); @@ -1175,10 +1174,8 @@ void AtomVecHybridKokkos::build_styles() int n; nallstyles = 0; #define ATOM_CLASS -#define AtomStyle(key,Class) \ - n = strlen(#key) + 1; \ - allstyles[nallstyles] = new char[n]; \ - strcpy(allstyles[nallstyles],#key); \ +#define AtomStyle(key,Class) \ + allstyles[nallstyles] = utils::strdup(#key); \ nallstyles++; #include "style_atom.h" // IWYU pragma: keep #undef AtomStyle diff --git a/src/KOKKOS/fix_nph_kokkos.cpp b/src/KOKKOS/fix_nph_kokkos.cpp index 71639083d9..f679940eaf 100644 --- a/src/KOKKOS/fix_nph_kokkos.cpp +++ b/src/KOKKOS/fix_nph_kokkos.cpp @@ -29,45 +29,26 @@ FixNPHKokkos::FixNPHKokkos(LAMMPS *lmp, int narg, char **arg) : { this->kokkosable = 1; if (this->tstat_flag) - this->error->all(FLERR,"Temperature control can not be used with fix nph"); + this->error->all(FLERR,"Temperature control can not be used with fix nph/kk"); if (!this->pstat_flag) - this->error->all(FLERR,"Pressure control must be used with fix nph"); + this->error->all(FLERR,"Pressure control must be used with fix nph/kk"); // create a new compute temp style // id = fix-ID + temp // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(this->id) + 6; - this->id_temp = new char[n]; - strcpy(this->id_temp,this->id); - strcat(this->id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = this->id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/kk"; - - this->modify->add_compute(3,newarg); - delete [] newarg; + this->id_temp = utils::strdup(std::string(this->id)+"_temp"); + this->modify->add_compute(std::string(this->id_temp)+" all temp/kk"); this->tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(this->id) + 7; - this->id_press = new char[n]; - strcpy(this->id_press,this->id); - strcat(this->id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = this->id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = this->id_temp; - this->modify->add_compute(4,newarg); - delete [] newarg; + this->id_press = utils::strdup(std::string(this->id)+"_press"); + this->modify->add_compute(std::string(this->id_press) + +" all pressure "+this->id_temp); this->pcomputeflag = 1; } diff --git a/src/KOKKOS/fix_npt_kokkos.cpp b/src/KOKKOS/fix_npt_kokkos.cpp index 55c1d9d33f..baa47e026f 100644 --- a/src/KOKKOS/fix_npt_kokkos.cpp +++ b/src/KOKKOS/fix_npt_kokkos.cpp @@ -29,45 +29,26 @@ FixNPTKokkos::FixNPTKokkos(LAMMPS *lmp, int narg, char **arg) : { this->kokkosable = 1; if (!this->tstat_flag) - this->error->all(FLERR,"Temperature control must be used with fix npt"); + this->error->all(FLERR,"Temperature control must be used with fix npt/kk"); if (!this->pstat_flag) - this->error->all(FLERR,"Pressure control must be used with fix npt"); + this->error->all(FLERR,"Pressure control must be used with fix npt/kk"); // create a new compute temp style // id = fix-ID + temp // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(this->id) + 6; - this->id_temp = new char[n]; - strcpy(this->id_temp,this->id); - strcat(this->id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = this->id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/kk"; - - this->modify->add_compute(3,newarg); - delete [] newarg; + this->id_temp = utils::strdup(std::string(this->id)+"_temp"); + this->modify->add_compute(std::string(this->id_temp)+" all temp/kk"); this->tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(this->id) + 7; - this->id_press = new char[n]; - strcpy(this->id_press,this->id); - strcat(this->id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = this->id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = this->id_temp; - this->modify->add_compute(4,newarg); - delete [] newarg; + this->id_press = utils::strdup(std::string(this->id)+"_press"); + this->modify->add_compute(std::string(this->id_press) + +" all pressure "+this->id_temp); this->pcomputeflag = 1; } diff --git a/src/KOKKOS/fix_nvt_kokkos.cpp b/src/KOKKOS/fix_nvt_kokkos.cpp index 25984726b7..f589600dde 100644 --- a/src/KOKKOS/fix_nvt_kokkos.cpp +++ b/src/KOKKOS/fix_nvt_kokkos.cpp @@ -30,25 +30,15 @@ FixNVTKokkos::FixNVTKokkos(LAMMPS *lmp, int narg, char **arg) : { this->kokkosable = 1; if (!this->tstat_flag) - this->error->all(FLERR,"Temperature control must be used with fix nvt"); + this->error->all(FLERR,"Temperature control must be used with fix nvt/kk"); if (this->pstat_flag) - this->error->all(FLERR,"Pressure control can not be used with fix nvt"); + this->error->all(FLERR,"Pressure control can not be used with fix nvt/kk"); // create a new compute temp style // id = fix-ID + temp - int n = strlen(this->id) + 6; - this->id_temp = new char[n]; - strcpy(this->id_temp,this->id); - strcat(this->id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = this->id_temp; - newarg[1] = this->group->names[this->igroup]; - newarg[2] = (char *) "temp/kk"; - - this->modify->add_compute(3,newarg); - delete [] newarg; + this->id_temp = utils::strdup(std::string(this->id)+"_temp"); + this->modify->add_compute(std::string(this->id_temp)+" all temp/kk"); this->tcomputeflag = 1; } From e0fdd2ad892531632ce18b6cd929f73367c33b91 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 10:09:08 -0400 Subject: [PATCH 159/257] correct lammps.extract_global() method for returned arrays which are returned as list --- python/lammps/core.py | 21 +++++++++++++++++---- unittest/python/python-commands.py | 9 +++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index be026d5e10..279b0a64dc 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -746,12 +746,21 @@ class lammps(object): :type name: string :param dtype: data type of the returned data (see :ref:`py_datatype_constants`) :type dtype: int, optional - :return: value of the property or None - :rtype: int, float, or NoneType + :return: value of the property or list of values or None + :rtype: int, float, list, or NoneType """ + if dtype == LAMMPS_AUTODETECT: dtype = self.extract_global_datatype(name) + # set length of vector for items that are not a scalar + vec_dict = { 'boxlo':3, 'boxhi':3, 'sublo':3, 'subhi':3, + 'sublo_lambda':3, 'subhi_lambda':3, 'periodicity':3 } + if name in vec_dict: + veclen = vec_dict[name] + else: + veclen = 1 + if name: name = name.encode() else: return None @@ -770,10 +779,14 @@ class lammps(object): ptr = self.lib.lammps_extract_global(self.lmp, name) if ptr: - return target_type(ptr[0]) + if veclen > 1: + result = [] + for i in range(0,veclen): + result.append(target_type(ptr[i])) + return result + else: return target_type(ptr[0]) return None - # ------------------------------------------------------------------------- # extract per-atom info datatype diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index c82e2fdb26..c1e4cecef5 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -268,6 +268,15 @@ create_atoms 1 single & self.assertEqual(self.lmp.extract_global("boxyhi"), 2.0) self.assertEqual(self.lmp.extract_global("boxzlo"), -3.0) self.assertEqual(self.lmp.extract_global("boxzhi"), 3.0) + self.assertEqual(self.lmp.extract_global("boxlo"), [-1.0, -2.0, -3.0]) + self.assertEqual(self.lmp.extract_global("boxhi"), [1.0, 2.0, 3.0]) + self.assertEqual(self.lmp.extract_global("sublo"), [-1.0, -2.0, -3.0]) + self.assertEqual(self.lmp.extract_global("subhi"), [1.0, 2.0, 3.0]) + self.assertEqual(self.lmp.extract_global("periodicity"), [1,1,1]) + # only valid for triclinic box + self.lmp.command("change_box all triclinic") + self.assertEqual(self.lmp.extract_global("sublo_lambda"), [0.0, 0.0, 0.0]) + self.assertEqual(self.lmp.extract_global("subhi_lambda"), [1.0, 1.0, 1.0]) ############################## if __name__ == "__main__": From b8f02d759abdbbd88407818bef22bcc48abe7e43 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 11:22:22 -0400 Subject: [PATCH 160/257] add support for extracting respa levels and timestep values --- python/lammps/core.py | 2 ++ src/library.cpp | 19 ++++++++++++++++++- unittest/python/python-commands.py | 10 ++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index 279b0a64dc..b3cdceb1a6 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -758,6 +758,8 @@ class lammps(object): 'sublo_lambda':3, 'subhi_lambda':3, 'periodicity':3 } if name in vec_dict: veclen = vec_dict[name] + elif name == 'respa_dt': + veclen = self.extract_global('respa_levels',LAMMPS_INT) else: veclen = 1 diff --git a/src/library.cpp b/src/library.cpp index 8de36a299f..6f08cffcc2 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -31,12 +31,14 @@ #include "group.h" #include "info.h" #include "input.h" +#include "integrate.h" #include "memory.h" #include "modify.h" #include "molecule.h" #include "neigh_list.h" #include "neighbor.h" #include "region.h" +#include "respa.h" #include "output.h" #include "thermo.h" #include "timer.h" @@ -984,12 +986,14 @@ to then decide how to cast the (void*) pointer and access the data. * \return integer constant encoding the data type of the property * or -1 if not found. */ -int lammps_extract_global_datatype(void *handle, const char *name) +int lammps_extract_global_datatype(void * /*handle*/, const char *name) { if (strcmp(name,"dt") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"ntimestep") == 0) return LAMMPS_BIGINT; if (strcmp(name,"atime") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"atimestep") == 0) return LAMMPS_BIGINT; + if (strcmp(name,"respa_levels") == 0) return LAMMPS_INT; + if (strcmp(name,"respa_dt") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"boxlo") == 0) return LAMMPS_DOUBLE; if (strcmp(name,"boxhi") == 0) return LAMMPS_DOUBLE; @@ -1116,6 +1120,14 @@ report the "native" data type. The following tables are provided: - bigint - 1 - the number of the timestep when "atime" was last updated. + * - respa_levels + - int + - 1 + - number of r-RESPA levels. See :doc:`run_style`. + * - respa_dt + - double + - number of r-RESPA levels + - length of the time steps with r-RESPA. See :doc:`run_style`. .. _extract_box_settings: @@ -1366,6 +1378,11 @@ void *lammps_extract_global(void *handle, const char *name) if (strcmp(name,"atime") == 0) return (void *) &lmp->update->atime; if (strcmp(name,"atimestep") == 0) return (void *) &lmp->update->atimestep; + if (utils::strmatch(lmp->update->integrate_style,"^respa")) { + Respa *respa = (Respa *)lmp->update->integrate; + if (strcmp(name,"respa_levels") == 0) return (void *) &respa->nlevels; + if (strcmp(name,"respa_dt") == 0) return (void *) respa->step; + } if (strcmp(name,"boxlo") == 0) return (void *) lmp->domain->boxlo; if (strcmp(name,"boxhi") == 0) return (void *) lmp->domain->boxhi; if (strcmp(name,"sublo") == 0) return (void *) lmp->domain->sublo; diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index c1e4cecef5..3bcb785b74 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -274,6 +274,16 @@ create_atoms 1 single & self.assertEqual(self.lmp.extract_global("subhi"), [1.0, 2.0, 3.0]) self.assertEqual(self.lmp.extract_global("periodicity"), [1,1,1]) # only valid for triclinic box + self.assertEqual(self.lmp.extract_global("respa_levels"), None) + self.assertEqual(self.lmp.extract_global("respa_dt"), None) + + # set and initialize r-RESPA + self.lmp.command("run_style respa 3 5 2 pair 2 kspace 3") + self.lmp.command("mass * 1.0") + self.lmp.command("run 1 post no") + self.assertEqual(self.lmp.extract_global("ntimestep"), 1) + self.assertEqual(self.lmp.extract_global("respa_levels"), 3) + self.assertEqual(self.lmp.extract_global("respa_dt"), [0.0005, 0.0025, 0.005]) self.lmp.command("change_box all triclinic") self.assertEqual(self.lmp.extract_global("sublo_lambda"), [0.0, 0.0, 0.0]) self.assertEqual(self.lmp.extract_global("subhi_lambda"), [1.0, 1.0, 1.0]) From a193d9d429ccf8129db46731bf3716b5b58b2c8c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 11:23:28 -0400 Subject: [PATCH 161/257] fix several issues when using extract_global() from python exposed by tests --- python/lammps/core.py | 3 ++- src/library.cpp | 9 +++++++-- unittest/python/python-commands.py | 13 +++++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index b3cdceb1a6..e112c4f3f8 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -777,10 +777,11 @@ class lammps(object): target_type = float elif dtype == LAMMPS_STRING: self.lib.lammps_extract_global.restype = c_char_p - target_type = lambda x: str(x, 'ascii') ptr = self.lib.lammps_extract_global(self.lmp, name) if ptr: + if dtype == LAMMPS_STRING: + return ptr.decode('utf-8') if veclen > 1: result = [] for i in range(0,veclen): diff --git a/src/library.cpp b/src/library.cpp index 6f08cffcc2..a950d31e4e 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -1387,8 +1387,13 @@ void *lammps_extract_global(void *handle, const char *name) if (strcmp(name,"boxhi") == 0) return (void *) lmp->domain->boxhi; if (strcmp(name,"sublo") == 0) return (void *) lmp->domain->sublo; if (strcmp(name,"subhi") == 0) return (void *) lmp->domain->subhi; - if (strcmp(name,"sublo_lambda") == 0) return (void *) lmp->domain->sublo_lamda; - if (strcmp(name,"subhi_lambda") == 0) return (void *) lmp->domain->subhi_lamda; + // these are only valid for a triclinic cell + if (lmp->domain->triclinic) { + if (strcmp(name,"sublo_lambda") == 0) + return (void *) lmp->domain->sublo_lamda; + if (strcmp(name,"subhi_lambda") == 0) + return (void *) lmp->domain->subhi_lamda; + } if (strcmp(name,"boxxlo") == 0) return (void *) &lmp->domain->boxlo[0]; if (strcmp(name,"boxxhi") == 0) return (void *) &lmp->domain->boxhi[0]; if (strcmp(name,"boxylo") == 0) return (void *) &lmp->domain->boxlo[1]; diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index 3bcb785b74..3661feb8a0 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -259,9 +259,13 @@ create_atoms 1 single & result = self.lmp.get_thermo(key) self.assertEqual(value, result, key) - def test_extract_global_double(self): + def test_extract_global(self): self.lmp.command("region box block -1 1 -2 2 -3 3") self.lmp.command("create_box 1 box") + self.assertEqual(self.lmp.extract_global("units"), "lj") + self.assertEqual(self.lmp.extract_global("ntimestep"), 0) + self.assertEqual(self.lmp.extract_global("dt"), 0.005) + self.assertEqual(self.lmp.extract_global("boxxlo"), -1.0) self.assertEqual(self.lmp.extract_global("boxxhi"), 1.0) self.assertEqual(self.lmp.extract_global("boxylo"), -2.0) @@ -273,7 +277,9 @@ create_atoms 1 single & self.assertEqual(self.lmp.extract_global("sublo"), [-1.0, -2.0, -3.0]) self.assertEqual(self.lmp.extract_global("subhi"), [1.0, 2.0, 3.0]) self.assertEqual(self.lmp.extract_global("periodicity"), [1,1,1]) - # only valid for triclinic box + self.assertEqual(self.lmp.extract_global("triclinic"), 0) + self.assertEqual(self.lmp.extract_global("sublo_lambda"), None) + self.assertEqual(self.lmp.extract_global("subhi_lambda"), None) self.assertEqual(self.lmp.extract_global("respa_levels"), None) self.assertEqual(self.lmp.extract_global("respa_dt"), None) @@ -284,7 +290,10 @@ create_atoms 1 single & self.assertEqual(self.lmp.extract_global("ntimestep"), 1) self.assertEqual(self.lmp.extract_global("respa_levels"), 3) self.assertEqual(self.lmp.extract_global("respa_dt"), [0.0005, 0.0025, 0.005]) + + # checks only for triclinic boxes self.lmp.command("change_box all triclinic") + self.assertEqual(self.lmp.extract_global("triclinic"), 1) self.assertEqual(self.lmp.extract_global("sublo_lambda"), [0.0, 0.0, 0.0]) self.assertEqual(self.lmp.extract_global("subhi_lambda"), [1.0, 1.0, 1.0]) From cb25e4aa3957b44af87823c2ec9e2f67a28c2845 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 25 Mar 2021 20:08:32 -0400 Subject: [PATCH 162/257] Add nve respa testcase for python/move --- unittest/force-styles/test_fix_timestep.cpp | 3 +-- unittest/force-styles/tests/py_nve.py | 29 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index aa07f36fb9..f72295716e 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -521,8 +521,7 @@ TEST(FixTimestep, plain) // fix python/move implementation is missing library interface access to Repsa::step ifix = lmp->modify->find_fix("test"); if (!utils::strmatch(lmp->modify->fix[ifix]->style, "^rigid") && - !utils::strmatch(lmp->modify->fix[ifix]->style, "^nve/limit") && - !utils::strmatch(lmp->modify->fix[ifix]->style, "^python/move") + !utils::strmatch(lmp->modify->fix[ifix]->style, "^nve/limit") ) { if (!verbose) ::testing::internal::CaptureStdout(); diff --git a/unittest/force-styles/tests/py_nve.py b/unittest/force-styles/tests/py_nve.py index 1f05be04a8..57592ea074 100644 --- a/unittest/force-styles/tests/py_nve.py +++ b/unittest/force-styles/tests/py_nve.py @@ -34,6 +34,7 @@ class NVE(LAMMPSFixMove): def __init__(self, ptr, group_name="all"): super(NVE, self).__init__(ptr) assert(self.group_name == "all") + self._step_respa = None def init(self): dt = self.lmp.extract_global("dt") @@ -42,6 +43,12 @@ class NVE(LAMMPSFixMove): self.dtv = dt self.dtf = 0.5 * dt * ftm2v + @property + def step_respa(self): + if not self._step_respa: + self._step_respa = self.lmp.extract_global("respa_dt") + return self._step_respa + def initial_integrate(self, vflag): nlocal = self.lmp.extract_global("nlocal") mass = self.lmp.extract_atom("mass") @@ -72,4 +79,26 @@ class NVE(LAMMPSFixMove): v[i][1] += dtfm * f[i][1] v[i][2] += dtfm * f[i][2] + def initial_integrate_respa(self, vflag, ilevel, iloop): + ftm2v = self.lmp.extract_global("ftm2v") + self.dtv = self.step_respa[ilevel] + self.dtf = 0.5 * self.step_respa[ilevel] * ftm2v + # innermost level - NVE update of v and x + # all other levels - NVE update of v + + if ilevel == 0: + self.initial_integrate(vflag) + else: + self.final_integrate() + + def final_integrate_respa(self, ilevel, iloop): + ftm2v = self.lmp.extract_global("ftm2v") + self.dtf = 0.5 * self.step_respa[ilevel] * ftm2v + self.final_integrate() + + def reset_dt(self): + dt = self.lmp.extract_global("dt") + ftm2v = self.lmp.extract_global("ftm2v") + self.dtv = dt; + self.dtf = 0.5 * dt * ftm2v; From 029db1413e5248e344df1b1a161b4f90e62932eb Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 25 Mar 2021 21:01:32 -0400 Subject: [PATCH 163/257] Add missing verbose after merge --- unittest/python/test_python_package.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/unittest/python/test_python_package.cpp b/unittest/python/test_python_package.cpp index 5a36112781..c240d23875 100644 --- a/unittest/python/test_python_package.cpp +++ b/unittest/python/test_python_package.cpp @@ -33,6 +33,7 @@ std::string INPUT_FOLDER = STRINGIFY(TEST_INPUT_FOLDER); const char * LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent metus."; +bool verbose = false; using LAMMPS_NS::utils::split_words; From 756d935d0651768d042dc7c2dcdd91e0d1e68e5b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 21:13:24 -0400 Subject: [PATCH 164/257] use std:: namespace for STL containers --- src/USER-AWPMD/pair_awpmd_cut.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/USER-AWPMD/pair_awpmd_cut.cpp b/src/USER-AWPMD/pair_awpmd_cut.cpp index 3d4e1f12a7..54f851171b 100644 --- a/src/USER-AWPMD/pair_awpmd_cut.cpp +++ b/src/USER-AWPMD/pair_awpmd_cut.cpp @@ -150,7 +150,7 @@ void PairAWPMDCut::compute(int eflag, int vflag) # if 1 // mapping of the LAMMPS numbers to the AWPMC numbers - vector gmap(ntot,-1); + std::vector gmap(ntot,-1); for (int ii = 0; ii < inum; ii++) { int i = ilist[ii]; @@ -226,7 +226,7 @@ void PairAWPMDCut::compute(int eflag, int vflag) // prepare the solver object wpmd->reset(); - map > etmap; + std::map > etmap; // add particles to the AWPMD solver object for (int i = 0; i < ntot; i++) { //int i = ilist[ii]; @@ -246,8 +246,8 @@ void PairAWPMDCut::compute(int eflag, int vflag) fi= new Vector_3[wpmd->ni]; // adding electrons - for (map >::iterator it=etmap.begin(); it!= etmap.end(); ++it) { - vector &el=it->second; + for (std::map >::iterator it=etmap.begin(); it!= etmap.end(); ++it) { + std::vector &el=it->second; if (!el.size()) // should not happen continue; int s=spin[el[0]] >0 ? 0 : 1; From 664335420aebe34d95fa72382f5b5285d64f621e Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 26 Mar 2021 11:50:58 -0400 Subject: [PATCH 165/257] Start refactoring tests --- .../formats/test_potential_file_reader.cpp | 120 ++++++------------ unittest/testing/core.h | 75 ++++++++++- 2 files changed, 107 insertions(+), 88 deletions(-) diff --git a/unittest/formats/test_potential_file_reader.cpp b/unittest/formats/test_potential_file_reader.cpp index 6cf2fd010c..1e3d96d6d7 100644 --- a/unittest/formats/test_potential_file_reader.cpp +++ b/unittest/formats/test_potential_file_reader.cpp @@ -28,37 +28,17 @@ #include "potential_file_reader.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include #include #include -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - using namespace LAMMPS_NS; using ::testing::MatchesRegex; using utils::split_words; -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } - // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; @@ -75,38 +55,16 @@ const int LAMMPS_NS::PairNb3bHarmonic::NPARAMS_PER_LINE; const int LAMMPS_NS::PairVashishta::NPARAMS_PER_LINE; const int LAMMPS_NS::PairTersoffTable::NPARAMS_PER_LINE; -class PotentialFileReaderTest : public ::testing::Test { -protected: - LAMMPS *lmp; - - void SetUp() override - { - const char *args[] = { - "PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void TearDown() override - { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void command(const std::string &cmd) { lmp->input->one(cmd); } +class PotentialFileReaderTest : public LAMMPSTest { }; // open for native units TEST_F(PotentialFileReaderTest, Sw_native) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); PotentialFileReader reader(lmp, "Si.sw", "Stillinger-Weber"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto line = reader.next_line(PairSW::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairSW::NPARAMS_PER_LINE); @@ -115,10 +73,10 @@ TEST_F(PotentialFileReaderTest, Sw_native) // open with supported conversion enabled TEST_F(PotentialFileReaderTest, Sw_conv) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units real"); PotentialFileReader reader(lmp, "Si.sw", "Stillinger-Weber", utils::METAL2REAL); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto line = reader.next_line(PairSW::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairSW::NPARAMS_PER_LINE); @@ -127,9 +85,9 @@ TEST_F(PotentialFileReaderTest, Sw_conv) // open without conversion enabled TEST_F(PotentialFileReaderTest, Sw_noconv) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units real"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR on proc.*potential.*requires metal units but real.*", PotentialFileReader reader(lmp, "Si.sw", "Stillinger-Weber", utils::REAL2METAL);); @@ -137,10 +95,10 @@ TEST_F(PotentialFileReaderTest, Sw_noconv) TEST_F(PotentialFileReaderTest, Comb) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); PotentialFileReader reader(lmp, "ffield.comb", "COMB"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto line = reader.next_line(PairComb::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairComb::NPARAMS_PER_LINE); @@ -148,10 +106,10 @@ TEST_F(PotentialFileReaderTest, Comb) TEST_F(PotentialFileReaderTest, Comb3) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); PotentialFileReader reader(lmp, "ffield.comb3", "COMB3"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto line = reader.next_line(PairComb3::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairComb3::NPARAMS_PER_LINE); @@ -159,10 +117,10 @@ TEST_F(PotentialFileReaderTest, Comb3) TEST_F(PotentialFileReaderTest, Tersoff) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); PotentialFileReader reader(lmp, "Si.tersoff", "Tersoff"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto line = reader.next_line(PairTersoff::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairTersoff::NPARAMS_PER_LINE); @@ -170,10 +128,10 @@ TEST_F(PotentialFileReaderTest, Tersoff) TEST_F(PotentialFileReaderTest, TersoffMod) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); PotentialFileReader reader(lmp, "Si.tersoff.mod", "Tersoff/Mod"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto line = reader.next_line(PairTersoffMOD::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairTersoffMOD::NPARAMS_PER_LINE); @@ -181,10 +139,10 @@ TEST_F(PotentialFileReaderTest, TersoffMod) TEST_F(PotentialFileReaderTest, TersoffModC) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); PotentialFileReader reader(lmp, "Si.tersoff.modc", "Tersoff/ModC"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto line = reader.next_line(PairTersoffMODC::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairTersoffMODC::NPARAMS_PER_LINE); @@ -192,10 +150,10 @@ TEST_F(PotentialFileReaderTest, TersoffModC) TEST_F(PotentialFileReaderTest, TersoffTable) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); PotentialFileReader reader(lmp, "Si.tersoff", "TersoffTable"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto line = reader.next_line(PairTersoffTable::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairTersoffTable::NPARAMS_PER_LINE); @@ -203,10 +161,10 @@ TEST_F(PotentialFileReaderTest, TersoffTable) TEST_F(PotentialFileReaderTest, TersoffZBL) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); PotentialFileReader reader(lmp, "SiC.tersoff.zbl", "Tersoff/ZBL"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto line = reader.next_line(PairTersoffZBL::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairTersoffZBL::NPARAMS_PER_LINE); @@ -214,10 +172,10 @@ TEST_F(PotentialFileReaderTest, TersoffZBL) TEST_F(PotentialFileReaderTest, GW) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); PotentialFileReader reader(lmp, "SiC.gw", "GW"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto line = reader.next_line(PairGW::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairGW::NPARAMS_PER_LINE); @@ -225,10 +183,10 @@ TEST_F(PotentialFileReaderTest, GW) TEST_F(PotentialFileReaderTest, GWZBL) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); PotentialFileReader reader(lmp, "SiC.gw.zbl", "GW/ZBL"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto line = reader.next_line(PairGWZBL::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairGWZBL::NPARAMS_PER_LINE); @@ -236,10 +194,10 @@ TEST_F(PotentialFileReaderTest, GWZBL) TEST_F(PotentialFileReaderTest, Nb3bHarmonic) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units real"); PotentialFileReader reader(lmp, "MOH.nb3b.harmonic", "NB3B Harmonic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto line = reader.next_line(PairNb3bHarmonic::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairNb3bHarmonic::NPARAMS_PER_LINE); @@ -247,10 +205,10 @@ TEST_F(PotentialFileReaderTest, Nb3bHarmonic) TEST_F(PotentialFileReaderTest, Vashishta) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); PotentialFileReader reader(lmp, "SiC.vashishta", "Vashishta"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto line = reader.next_line(PairVashishta::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairVashishta::NPARAMS_PER_LINE); @@ -261,38 +219,38 @@ TEST_F(PotentialFileReaderTest, UnitConvert) PotentialFileReader *reader; int unit_convert, flag; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); reader = new PotentialFileReader(lmp, "Si.sw", "Stillinger-Weber"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); unit_convert = reader->get_unit_convert(); ASSERT_EQ(unit_convert, 0); delete reader; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); flag = utils::get_supported_conversions(utils::UNKNOWN); reader = new PotentialFileReader(lmp, "Si.sw", "Stillinger-Weber", flag); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); unit_convert = reader->get_unit_convert(); ASSERT_EQ(unit_convert, 0); delete reader; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); flag = utils::get_supported_conversions(utils::ENERGY); reader = new PotentialFileReader(lmp, "Si.sw", "Stillinger-Weber", flag); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); unit_convert = reader->get_unit_convert(); ASSERT_EQ(unit_convert, 0); delete reader; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); flag = utils::get_supported_conversions(utils::ENERGY); command("units real"); reader = new PotentialFileReader(lmp, "Si.sw", "Stillinger-Weber", flag); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); unit_convert = reader->get_unit_convert(); ASSERT_EQ(unit_convert, utils::METAL2REAL); @@ -304,7 +262,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/testing/core.h b/unittest/testing/core.h index 6243eb219e..19013bf90a 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -16,8 +16,12 @@ #include "info.h" #include "input.h" #include "lammps.h" +#include "variable.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "exceptions.h" + +#include using namespace LAMMPS_NS; @@ -45,29 +49,86 @@ class LAMMPSTest : public ::testing::Test { public: void command(const std::string &line) { lmp->input->one(line.c_str()); } + void BEGIN_HIDE_OUTPUT() { + if (!verbose) ::testing::internal::CaptureStdout(); + } + + void END_HIDE_OUTPUT() { + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + void BEGIN_CAPTURE_OUTPUT() { + if (!verbose) ::testing::internal::CaptureStdout(); + } + + std::string END_CAPTURE_OUTPUT() { + auto output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + return output; + } + + void HIDE_OUTPUT(std::function f) { + if (!verbose) ::testing::internal::CaptureStdout(); + try { + f(); + } catch(LAMMPSException & e) { + if (!verbose) std::cout << ::testing::internal::GetCapturedStdout(); + throw e; + } + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + std::string CAPTURE_OUTPUT(std::function f) { + ::testing::internal::CaptureStdout(); + try { + f(); + } catch(LAMMPSException & e) { + if (verbose) std::cout << ::testing::internal::GetCapturedStdout(); + throw e; + } + auto output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + return output; + } + + double get_variable_value(const std::string & name) { + char * str = utils::strdup(fmt::format("v_{}", name)); + double value = lmp->input->variable->compute_equal(str); + delete [] str; + return value; + } + + std::string get_variable_string(const std::string & name) { + return lmp->input->variable->retrieve(name.c_str()); + } + protected: const char *testbinary = "LAMMPSTest"; LAMMPS *lmp; + Info *info; void SetUp() override { const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite"}; char **argv = (char **)args; int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + HIDE_OUTPUT([&] { + lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + info = new Info(lmp); + }); InitSystem(); - if (!verbose) ::testing::internal::GetCapturedStdout(); } virtual void InitSystem() {} void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - lmp = nullptr; - if (!verbose) ::testing::internal::GetCapturedStdout(); + HIDE_OUTPUT([&] { + delete info; + delete lmp; + info = nullptr; + lmp = nullptr; + }); } }; From 1752bd02765a25caec346d1a034f7226f131679e Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 26 Mar 2021 12:23:58 -0400 Subject: [PATCH 166/257] Refactoring of some test files --- unittest/commands/test_groups.cpp | 121 +++++-------- unittest/commands/test_simple_commands.cpp | 201 ++++++++------------- unittest/testing/core.h | 1 + 3 files changed, 122 insertions(+), 201 deletions(-) diff --git a/unittest/commands/test_groups.cpp b/unittest/commands/test_groups.cpp index 3ae1722f4d..181f000a7c 100644 --- a/unittest/commands/test_groups.cpp +++ b/unittest/commands/test_groups.cpp @@ -22,6 +22,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -29,12 +30,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { @@ -42,54 +37,22 @@ using ::testing::ExitedWithCode; using ::testing::MatchesRegex; using ::testing::StrEq; -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - if (verbose) std::cout << mesg; \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - if (verbose) std::cout << mesg; \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } - -class GroupTest : public ::testing::Test { +class GroupTest : public LAMMPSTest { protected: - LAMMPS *lmp; Group *group; Domain *domain; void SetUp() override { - const char *args[] = {"GroupTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "GroupTest"; + LAMMPSTest::SetUp(); group = lmp->group; domain = lmp->domain; } - void TearDown() override - { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); - std::cout.flush(); - } - - void command(const std::string &cmd) { lmp->input->one(cmd); } - void atomic_system() { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units real"); command("lattice sc 1.0 origin 0.125 0.125 0.125"); command("region box block -2 2 -2 2 -2 2"); @@ -101,23 +64,25 @@ protected: command("region top block INF INF -2.0 -1.0 INF INF"); command("set region left type 2"); command("set region right type 3"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void molecular_system() { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("fix props all property/atom mol rmass q"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); + atomic_system(); - if (!verbose) ::testing::internal::CaptureStdout(); + + BEGIN_HIDE_OUTPUT(); command("variable molid atom floor(id/4)+1"); command("variable charge atom 2.0*sin(PI/32*id)"); command("set atom * mol v_molid"); command("set atom * charge v_charge"); command("set type 1 mass 0.5"); command("set type 2*4 mass 2.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } }; @@ -131,7 +96,7 @@ TEST_F(GroupTest, EmptyDelete) { atomic_system(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group new1 empty"); command("group new2 empty"); command("group new2 empty"); @@ -143,16 +108,16 @@ TEST_F(GroupTest, EmptyDelete) command("compute 1 new3 ke"); command("dump 1 new4 atom 50 dump.melt"); command("atom_modify first new5"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(group->ngroup, 7); TEST_FAILURE(".*ERROR: Illegal group command.*", command("group new3 xxx");); TEST_FAILURE(".*ERROR: Illegal group command.*", command("group new3 empty xxx");); TEST_FAILURE(".*ERROR: Group command requires atom attribute molecule.*", command("group new2 include molecule");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); group->assign("new1 delete"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(group->ngroup, 6); TEST_FAILURE(".*ERROR: Illegal group command.*", command("group new2 delete xxx");); @@ -172,13 +137,13 @@ TEST_F(GroupTest, RegionClear) { atomic_system(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group one region left"); command("group two region right"); command("group three empty"); command("group four region left"); command("group four region right"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(group->count(group->find("one")), 16); ASSERT_EQ(group->count(group->find("two")), 16); ASSERT_EQ(group->count(group->find("three")), 0); @@ -189,20 +154,20 @@ TEST_F(GroupTest, RegionClear) TEST_FAILURE(".*ERROR: Illegal group command.*", command("group three region left xxx");); TEST_FAILURE(".*ERROR: Group region ID does not exist.*", command("group four region dummy");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group one clear"); command("group two clear"); command("group three clear"); command("group four clear"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(group->count(group->find("one")), 0); ASSERT_EQ(group->count(group->find("two")), 0); ASSERT_EQ(group->count(group->find("three")), 0); ASSERT_EQ(group->count(group->find("four")), 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("delete_atoms region box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(group->count(group->find("all")), 0); } @@ -214,7 +179,7 @@ TEST_F(GroupTest, SelectRestart) for (int i = 0; i < lmp->atom->natoms; ++i) flags[i] = i & 1; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group one region left"); command("group two region right"); group->create("half", flags); @@ -224,7 +189,7 @@ TEST_F(GroupTest, SelectRestart) command("group five subtract all half four"); command("group top region top"); command("group six intersect half top"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(group->count(group->find("one")), 16); ASSERT_EQ(group->count(group->find("two")), 16); ASSERT_EQ(group->count(group->find("three")), 0); @@ -235,12 +200,12 @@ TEST_F(GroupTest, SelectRestart) ASSERT_EQ(group->count(group->find("half"), domain->find_region("top")), 8); ASSERT_DOUBLE_EQ(group->mass(group->find("half"), domain->find_region("top")), 8.0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_restart group.restart"); command("clear"); command("read_restart group.restart"); unlink("group.restart"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); group = lmp->group; ASSERT_EQ(group->count(group->find("one")), 16); ASSERT_EQ(group->count(group->find("two")), 16); @@ -250,11 +215,11 @@ TEST_F(GroupTest, SelectRestart) ASSERT_EQ(group->count(group->find("five")), 16); ASSERT_DOUBLE_EQ(group->mass(group->find("six")), 8.0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group four clear"); command("group five clear"); command("group six clear"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Group ID does not exist.*", command("group four union one two xxx");); TEST_FAILURE(".*ERROR: Group ID does not exist.*", @@ -267,14 +232,14 @@ TEST_F(GroupTest, Molecular) { molecular_system(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group one region left"); command("group two region right"); command("group half id 1:1000:2"); command("group top region top"); command("group three intersect half top"); command("group three include molecule"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(group->count(group->find("one")), 16); ASSERT_EQ(group->count(group->find("two")), 16); ASSERT_EQ(group->count(group->find("three")), 15); @@ -290,36 +255,36 @@ TEST_F(GroupTest, Dynamic) { atomic_system(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable step atom id<=step"); command("group half id 1:1000:2"); command("group grow dynamic half var step every 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(group->count(group->find("grow")), 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("run 10 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(group->count(group->find("grow")), 5); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group grow dynamic half var step every 1"); command("run 10 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(group->count(group->find("grow")), 10); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group grow static"); command("run 10 post no"); command("group part variable step"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(group->count(group->find("grow")), 10); ASSERT_EQ(group->count(group->find("part")), 30); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group grow dynamic half var step every 1"); command("run 10 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(group->count(group->find("grow")), 20); TEST_FAILURE(".*ERROR: Cannot subtract groups using a dynamic group.*", command("group chunk subtract half grow");); @@ -328,10 +293,10 @@ TEST_F(GroupTest, Dynamic) TEST_FAILURE(".*ERROR: Cannot intersect groups using a dynamic group.*", command("group chunk intersect half grow");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group grow delete"); command("variable ramp equal step"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(group->ngroup, 4); TEST_FAILURE(".*ERROR: Group dynamic cannot reference itself.*", @@ -351,7 +316,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index 4261dbd61d..2ed5e7a989 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -24,6 +24,7 @@ #include "fmt/format.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -34,11 +35,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif using LAMMPS_NS::utils::split_words; @@ -47,43 +43,7 @@ using ::testing::ExitedWithCode; using ::testing::MatchesRegex; using ::testing::StrEq; -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } - -class SimpleCommandsTest : public ::testing::Test { -protected: - LAMMPS *lmp; - - void SetUp() override - { - const char *args[] = {"SimpleCommandsTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void TearDown() override - { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void command(const std::string &cmd) { lmp->input->one(cmd); } +class SimpleCommandsTest : public LAMMPSTest { }; TEST_F(SimpleCommandsTest, UnknownCommand) @@ -96,27 +56,27 @@ TEST_F(SimpleCommandsTest, Echo) ASSERT_EQ(lmp->input->echo_screen, 1); ASSERT_EQ(lmp->input->echo_log, 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("echo none"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->input->echo_screen, 0); ASSERT_EQ(lmp->input->echo_log, 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("echo both"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->input->echo_screen, 1); ASSERT_EQ(lmp->input->echo_log, 1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("echo screen"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->input->echo_screen, 1); ASSERT_EQ(lmp->input->echo_log, 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("echo log"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->input->echo_screen, 0); ASSERT_EQ(lmp->input->echo_log, 1); @@ -128,15 +88,15 @@ TEST_F(SimpleCommandsTest, Log) { ASSERT_EQ(lmp->logfile, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("log simple_command_test.log"); command("print 'test1'"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_NE(lmp->logfile, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("log none"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->logfile, nullptr); std::string text; @@ -146,14 +106,14 @@ TEST_F(SimpleCommandsTest, Log) in.close(); ASSERT_THAT(text, StrEq("test1")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("log simple_command_test.log append"); command("print 'test2'"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_NE(lmp->logfile, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("log none"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->logfile, nullptr); in.open("simple_command_test.log"); @@ -172,59 +132,57 @@ TEST_F(SimpleCommandsTest, Newton) // default setting is "on" for both ASSERT_EQ(lmp->force->newton_pair, 1); ASSERT_EQ(lmp->force->newton_bond, 1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("newton off"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->force->newton_pair, 0); ASSERT_EQ(lmp->force->newton_bond, 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("newton on off"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->force->newton_pair, 1); ASSERT_EQ(lmp->force->newton_bond, 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("newton off on"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->force->newton_pair, 0); ASSERT_EQ(lmp->force->newton_bond, 1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("newton on"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->force->newton_pair, 1); ASSERT_EQ(lmp->force->newton_bond, 1); } TEST_F(SimpleCommandsTest, Partition) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("echo none"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal partition command .*", command("partition xxx 1 echo none");); TEST_FAILURE(".*ERROR: Numeric index 2 is out of bounds.*", command("partition yes 2 echo none");); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("partition yes 1 print 'test'"); - auto text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + auto text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, StrEq("test\n")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("partition no 1 print 'test'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, StrEq("")); } TEST_F(SimpleCommandsTest, Quit) { - ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("echo none"); - ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Expected integer .*", command("quit xxx");); // the following tests must be skipped with OpenMPI due to using threads - if (have_openmpi) GTEST_SKIP(); + if (Info::get_mpi_vendor() == "Open MPI") GTEST_SKIP(); ASSERT_EXIT(command("quit"), ExitedWithCode(0), ""); ASSERT_EXIT(command("quit 9"), ExitedWithCode(9), ""); } @@ -233,14 +191,14 @@ TEST_F(SimpleCommandsTest, ResetTimestep) { ASSERT_EQ(lmp->update->ntimestep, 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_timestep 10"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->update->ntimestep, 10); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_timestep 0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->update->ntimestep, 0); TEST_FAILURE(".*ERROR: Timestep must be >= 0.*", command("reset_timestep -10");); @@ -257,31 +215,31 @@ TEST_F(SimpleCommandsTest, Suffix) TEST_FAILURE(".*ERROR: May only enable suffixes after defining one.*", command("suffix on");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("suffix one"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(lmp->suffix, StrEq("one")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("suffix hybrid two three"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(lmp->suffix, StrEq("two")); ASSERT_THAT(lmp->suffix2, StrEq("three")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("suffix four"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(lmp->suffix, StrEq("four")); ASSERT_EQ(lmp->suffix2, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("suffix off"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->suffix_enable, 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("suffix on"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->suffix_enable, 1); TEST_FAILURE(".*ERROR: Illegal suffix command.*", command("suffix");); @@ -293,20 +251,20 @@ TEST_F(SimpleCommandsTest, Thermo) { ASSERT_EQ(lmp->output->thermo_every, 0); ASSERT_EQ(lmp->output->var_thermo, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("thermo 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->output->thermo_every, 2); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable step equal logfreq(10,3,10)"); command("thermo v_step"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(lmp->output->var_thermo, StrEq("step")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("thermo 10"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->output->thermo_every, 10); ASSERT_EQ(lmp->output->var_thermo, nullptr); @@ -317,26 +275,26 @@ TEST_F(SimpleCommandsTest, Thermo) TEST_F(SimpleCommandsTest, TimeStep) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("timestep 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->update->dt, 1.0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("timestep 0.1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->update->dt, 0.1); // zero timestep is legal and works (atoms don't move) - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("timestep 0.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->update->dt, 0.0); // negative timestep also creates a viable MD. - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("timestep -0.1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->update->dt, -0.1); TEST_FAILURE(".*ERROR: Illegal timestep command.*", command("timestep");); @@ -352,16 +310,16 @@ TEST_F(SimpleCommandsTest, Units) ASSERT_THAT(lmp->update->unit_style, StrEq("lj")); for (std::size_t i = 0; i < num; ++i) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("units {}", names[i])); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(lmp->update->unit_style, StrEq(names[i])); ASSERT_EQ(lmp->update->dt, dt[i]); } - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(lmp->update->unit_style, StrEq("lj")); TEST_FAILURE(".*ERROR: Illegal units command.*", command("units unknown");); @@ -369,18 +327,18 @@ TEST_F(SimpleCommandsTest, Units) TEST_F(SimpleCommandsTest, Shell) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("shell putenv TEST_VARIABLE=simpletest"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); char *test_var = getenv("TEST_VARIABLE"); ASSERT_NE(test_var, nullptr); ASSERT_THAT(test_var, StrEq("simpletest")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("shell putenv TEST_VARIABLE=simpletest"); command("shell putenv TEST_VARIABLE2=simpletest2 OTHER_VARIABLE=2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); char *test_var2 = getenv("TEST_VARIABLE2"); char *other_var = getenv("OTHER_VARIABLE"); @@ -398,32 +356,30 @@ TEST_F(SimpleCommandsTest, CiteMe) lmp->citeme = new LAMMPS_NS::CiteMe(lmp, CiteMe::TERSE, CiteMe::TERSE, nullptr); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); lmp->citeme->add("test citation one:\n 1\n"); lmp->citeme->add("test citation two:\n 2\n"); lmp->citeme->add("test citation one:\n 1\n"); lmp->citeme->flush(); - std::string text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + std::string text = END_CAPTURE_OUTPUT(); // find the two unique citations, but not the third ASSERT_THAT(text, MatchesRegex(".*one.*two.*")); ASSERT_THAT(text, Not(MatchesRegex(".*one.*two.*one.*"))); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); lmp->citeme->add("test citation one:\n 0\n"); lmp->citeme->add("test citation two:\n 2\n"); lmp->citeme->add("test citation three:\n 3\n"); lmp->citeme->flush(); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); // find the forth (only differs in long citation) and sixth added citation ASSERT_THAT(text, MatchesRegex(".*one.*three.*")); ASSERT_THAT(text, Not(MatchesRegex(".*two.*"))); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); lmp->citeme->add("test citation one:\n 1\n"); lmp->citeme->add("test citation two:\n 2\n"); lmp->citeme->add("test citation one:\n 0\n"); @@ -431,8 +387,7 @@ TEST_F(SimpleCommandsTest, CiteMe) lmp->citeme->add("test citation three:\n 3\n"); lmp->citeme->flush(); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); // no new citation. no CITE-CITE-CITE- lines ASSERT_THAT(text, Not(MatchesRegex(".*CITE-CITE-CITE-CITE.*"))); @@ -444,7 +399,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/testing/core.h b/unittest/testing/core.h index 19013bf90a..01c5872579 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -129,6 +129,7 @@ protected: info = nullptr; lmp = nullptr; }); + std::cout.flush(); } }; From e85f945d8e22ab813c472c6b3857fc5a4576440f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 26 Mar 2021 23:12:29 -0400 Subject: [PATCH 167/257] fix typos --- cmake/CMakeLists.txt | 2 +- doc/src/pair_polymorphic.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 06600d02c4..6d98385d02 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -31,7 +31,7 @@ endif() # If enabled, no need to use LD_LIBRARY_PATH / DYLD_LIBRARY_PATH when installed option(LAMMPS_INSTALL_RPATH "Set runtime path for shared libraries linked to LAMMPS binaries" OFF) -if (LAMMPS_INSTALL_RPATH) +if(LAMMPS_INSTALL_RPATH) set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) endif() diff --git a/doc/src/pair_polymorphic.rst b/doc/src/pair_polymorphic.rst index 6abe037581..3df70a017c 100644 --- a/doc/src/pair_polymorphic.rst +++ b/doc/src/pair_polymorphic.rst @@ -319,7 +319,7 @@ This pair style is part of the MANYBODY package. It is only enabled if LAMMPS was built with that package. See the :doc:`Build package ` doc page for more info. -This pair potential requires the :doc:`newtion ` setting to be +This pair potential requires the :doc:`newton ` setting to be "on" for pair interactions. The potential files provided with LAMMPS (see the potentials directory) From 35abca1b40de24c634bce37c2173f56028d07ae9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 27 Mar 2021 11:18:59 -0400 Subject: [PATCH 168/257] we should include when using strcasecmp() --- src/USER-DIFFRACTION/compute_saed.cpp | 1 + src/USER-DIFFRACTION/compute_xrd.cpp | 1 + src/USER-MOLFILE/molfile_interface.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/src/USER-DIFFRACTION/compute_saed.cpp b/src/USER-DIFFRACTION/compute_saed.cpp index e825006dba..b1fa296315 100644 --- a/src/USER-DIFFRACTION/compute_saed.cpp +++ b/src/USER-DIFFRACTION/compute_saed.cpp @@ -30,6 +30,7 @@ #include #include +#include // for strcasecmp() #include "omp_compat.h" using namespace LAMMPS_NS; diff --git a/src/USER-DIFFRACTION/compute_xrd.cpp b/src/USER-DIFFRACTION/compute_xrd.cpp index a077df0183..720e5809b1 100644 --- a/src/USER-DIFFRACTION/compute_xrd.cpp +++ b/src/USER-DIFFRACTION/compute_xrd.cpp @@ -31,6 +31,7 @@ #include #include +#include // for strcasecmp() #include "omp_compat.h" using namespace LAMMPS_NS; diff --git a/src/USER-MOLFILE/molfile_interface.cpp b/src/USER-MOLFILE/molfile_interface.cpp index 1ced86da86..dc40859127 100644 --- a/src/USER-MOLFILE/molfile_interface.cpp +++ b/src/USER-MOLFILE/molfile_interface.cpp @@ -23,6 +23,7 @@ #include #include #include +#include // for strcasecmp() #if defined(_WIN32) #include From 0b73ab96d2fa979f5fe3c8bb9e1c7514c52f97d1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 27 Mar 2021 11:10:36 -0400 Subject: [PATCH 169/257] avoid replicated code, consolidate variables and element mapping --- src/GPU/pair_sw_gpu.cpp | 6 +- src/GPU/pair_tersoff_gpu.cpp | 4 +- src/GPU/pair_tersoff_mod_gpu.cpp | 4 +- src/GPU/pair_tersoff_zbl_gpu.cpp | 4 +- src/GPU/pair_vashishta_gpu.cpp | 4 +- src/KOKKOS/pair_sw_kokkos.cpp | 36 ++-- src/KOKKOS/pair_sw_kokkos.h | 2 +- src/KOKKOS/pair_tersoff_kokkos.cpp | 2 +- src/KOKKOS/pair_tersoff_mod_kokkos.cpp | 2 +- src/KOKKOS/pair_tersoff_zbl_kokkos.cpp | 2 +- src/KOKKOS/pair_vashishta_kokkos.cpp | 38 ++-- src/KOKKOS/pair_vashishta_kokkos.h | 2 +- src/MANYBODY/pair_adp.cpp | 2 - src/MANYBODY/pair_adp.h | 2 - src/MANYBODY/pair_bop.cpp | 13 +- src/MANYBODY/pair_bop.h | 5 - src/MANYBODY/pair_comb.cpp | 105 ++-------- src/MANYBODY/pair_comb.h | 6 - src/MANYBODY/pair_comb3.cpp | 183 ++++++------------ src/MANYBODY/pair_comb3.h | 6 - src/MANYBODY/pair_eam.cpp | 4 +- src/MANYBODY/pair_eam.h | 2 - src/MANYBODY/pair_eim.cpp | 63 +----- src/MANYBODY/pair_eim.h | 4 - src/MANYBODY/pair_gw.cpp | 85 +------- src/MANYBODY/pair_gw.h | 6 - src/MANYBODY/pair_lcbop.cpp | 45 +---- src/MANYBODY/pair_lcbop.h | 3 - src/MANYBODY/pair_nb3b_harmonic.cpp | 83 +------- src/MANYBODY/pair_nb3b_harmonic.h | 6 - src/MANYBODY/pair_polymorphic.cpp | 70 +------ src/MANYBODY/pair_polymorphic.h | 5 - src/MANYBODY/pair_sw.cpp | 85 +------- src/MANYBODY/pair_sw.h | 6 - src/MANYBODY/pair_tersoff.cpp | 85 +------- src/MANYBODY/pair_tersoff.h | 6 - src/MANYBODY/pair_tersoff_mod.cpp | 8 +- src/MANYBODY/pair_vashishta.cpp | 85 +------- src/MANYBODY/pair_vashishta.h | 6 - src/MANYBODY/pair_vashishta_table.cpp | 10 +- src/SNAP/pair_snap.cpp | 94 +-------- src/SNAP/pair_snap.h | 3 - src/USER-INTEL/pair_sw_intel.cpp | 4 +- src/USER-INTEL/pair_tersoff_intel.cpp | 4 +- src/USER-MEAMC/pair_meamc.cpp | 119 ++++++------ src/USER-MEAMC/pair_meamc.h | 9 +- src/USER-MISC/pair_agni.cpp | 78 +------- src/USER-MISC/pair_agni.h | 5 - src/USER-MISC/pair_drip.cpp | 78 +------- src/USER-MISC/pair_drip.h | 4 - src/USER-MISC/pair_edip.cpp | 101 ++-------- src/USER-MISC/pair_edip.h | 6 - src/USER-MISC/pair_edip_multi.cpp | 84 +------- src/USER-MISC/pair_edip_multi.h | 6 - src/USER-MISC/pair_extep.cpp | 89 ++------- src/USER-MISC/pair_extep.h | 26 +-- src/USER-MISC/pair_ilp_graphene_hbn.cpp | 85 +------- src/USER-MISC/pair_ilp_graphene_hbn.h | 6 - src/USER-MISC/pair_kolmogorov_crespi_full.cpp | 85 +------- src/USER-MISC/pair_kolmogorov_crespi_full.h | 6 - src/USER-MISC/pair_kolmogorov_crespi_z.cpp | 49 +---- src/USER-MISC/pair_kolmogorov_crespi_z.h | 6 - src/USER-MISC/pair_lebedeva_z.cpp | 54 +----- src/USER-MISC/pair_lebedeva_z.h | 6 - src/USER-MISC/pair_meam_spline.cpp | 27 +-- src/USER-MISC/pair_meam_spline.h | 4 - src/USER-MISC/pair_meam_sw_spline.cpp | 78 +------- src/USER-MISC/pair_meam_sw_spline.h | 3 - src/USER-MISC/pair_tersoff_table.cpp | 130 +++---------- src/USER-MISC/pair_tersoff_table.h | 6 - src/USER-OMP/pair_agni_omp.cpp | 2 +- src/USER-OMP/pair_comb_omp.cpp | 18 +- src/USER-OMP/pair_edip_omp.cpp | 6 +- src/USER-OMP/pair_sw_omp.cpp | 8 +- src/USER-OMP/pair_tersoff_mod_c_omp.cpp | 8 +- src/USER-OMP/pair_tersoff_mod_omp.cpp | 8 +- src/USER-OMP/pair_tersoff_omp.cpp | 8 +- src/USER-OMP/pair_tersoff_table_omp.cpp | 24 +-- src/USER-OMP/pair_vashishta_omp.cpp | 8 +- src/USER-OMP/pair_vashishta_table_omp.cpp | 8 +- src/USER-REAXC/pair_reaxc.cpp | 25 ++- src/USER-REAXC/pair_reaxc.h | 3 - src/USER-SMTBQ/pair_smtbq.cpp | 78 +------- src/USER-SMTBQ/pair_smtbq.h | 9 +- src/input.cpp | 3 + src/pair.cpp | 74 +++++++ src/pair.h | 28 ++- src/pair_coul_streitz.cpp | 84 ++------ src/pair_coul_streitz.h | 8 +- 89 files changed, 601 insertions(+), 2159 deletions(-) diff --git a/src/GPU/pair_sw_gpu.cpp b/src/GPU/pair_sw_gpu.cpp index 7bfbe2810f..b819580488 100644 --- a/src/GPU/pair_sw_gpu.cpp +++ b/src/GPU/pair_sw_gpu.cpp @@ -186,7 +186,7 @@ void PairSWGPU::init_style() if (i < 0 || j < 0) continue; else { - int ijparam = elem2param[i][j][j]; + int ijparam = elem3param[i][j][j]; ncutsq[ii][jj] = params[ijparam].cutsq; ncut[ii][jj] = params[ijparam].cut; sigma[ii][jj] = params[ijparam].sigma; @@ -206,7 +206,7 @@ void PairSWGPU::init_style() if (k < 0) continue; else { - int ijkparam = elem2param[i][j][k]; + int ijkparam = elem3param[i][j][k]; costheta[ii][jj][kk] = params[ijkparam].costheta; lambda_epsilon[ii][jj][kk] = params[ijkparam].lambda_epsilon; } @@ -218,7 +218,7 @@ void PairSWGPU::init_style() int success = sw_gpu_init(tp1, atom->nlocal, atom->nlocal+atom->nghost, mnf, cell_size, gpu_mode, screen, ncutsq, ncut, sigma, powerp, powerq, sigma_gamma, c1, c2, c3, c4, c5, - c6, lambda_epsilon, costheta, map, elem2param); + c6, lambda_epsilon, costheta, map, elem3param); memory->destroy(ncutsq); memory->destroy(ncut); diff --git a/src/GPU/pair_tersoff_gpu.cpp b/src/GPU/pair_tersoff_gpu.cpp index e675ba6903..c2f3413d3d 100644 --- a/src/GPU/pair_tersoff_gpu.cpp +++ b/src/GPU/pair_tersoff_gpu.cpp @@ -41,7 +41,7 @@ using namespace LAMMPS_NS; int tersoff_gpu_init(const int ntypes, const int inum, const int nall, const int max_nbors, const double cell_size, int &gpu_mode, FILE *screen, int* host_map, const int nelements, - int*** host_elem2param, const int nparams, + int*** host_elem3param, const int nparams, const double* ts_lam1, const double* ts_lam2, const double* ts_lam3, const double* ts_powermint, const double* ts_biga, const double* ts_bigb, @@ -218,7 +218,7 @@ void PairTersoffGPU::init_style() int success = tersoff_gpu_init(atom->ntypes+1, atom->nlocal, atom->nlocal+atom->nghost, mnf, cell_size, gpu_mode, screen, map, nelements, - elem2param, nparams, lam1, lam2, lam3, + elem3param, nparams, lam1, lam2, lam3, powermint, biga, bigb, bigr, bigd, c1, c2, c3, c4, c, d, h, gamma, beta, powern, _cutsq); diff --git a/src/GPU/pair_tersoff_mod_gpu.cpp b/src/GPU/pair_tersoff_mod_gpu.cpp index 98a7248c1f..6a5e9892ec 100644 --- a/src/GPU/pair_tersoff_mod_gpu.cpp +++ b/src/GPU/pair_tersoff_mod_gpu.cpp @@ -40,7 +40,7 @@ using namespace LAMMPS_NS; int tersoff_mod_gpu_init(const int ntypes, const int inum, const int nall, const int max_nbors, const double cell_size, int &gpu_mode, FILE *screen, - int* host_map, const int nelements, int*** host_elem2param, const int nparams, + int* host_map, const int nelements, int*** host_elem3param, const int nparams, const double* ts_lam1, const double* ts_lam2, const double* ts_lam3, const double* ts_powermint, const double* ts_biga, const double* ts_bigb, const double* ts_bigr, const double* ts_bigd, const double* ts_c1, @@ -211,7 +211,7 @@ void PairTersoffMODGPU::init_style() int success = tersoff_mod_gpu_init(atom->ntypes+1, atom->nlocal, atom->nlocal+atom->nghost, mnf, cell_size, gpu_mode, screen, map, nelements, - elem2param, nparams, lam1, lam2, lam3, + elem3param, nparams, lam1, lam2, lam3, powermint, biga, bigb, bigr, bigd, c1, c2, c3, c4, c5, h, beta, powern, powern_del, ca1, _cutsq); diff --git a/src/GPU/pair_tersoff_zbl_gpu.cpp b/src/GPU/pair_tersoff_zbl_gpu.cpp index e17b48fec5..0c56212fef 100644 --- a/src/GPU/pair_tersoff_zbl_gpu.cpp +++ b/src/GPU/pair_tersoff_zbl_gpu.cpp @@ -41,7 +41,7 @@ using namespace LAMMPS_NS; int tersoff_zbl_gpu_init(const int ntypes, const int inum, const int nall, const int max_nbors, const double cell_size, int &gpu_mode, FILE *screen, int* host_map, const int nelements, - int*** host_elem2param, const int nparams, + int*** host_elem3param, const int nparams, const double* ts_lam1, const double* ts_lam2, const double* ts_lam3, const double* ts_powermint, const double* ts_biga, const double* ts_bigb, @@ -227,7 +227,7 @@ void PairTersoffZBLGPU::init_style() int success = tersoff_zbl_gpu_init(atom->ntypes+1, atom->nlocal, atom->nlocal+atom->nghost, mnf, cell_size, gpu_mode, screen, map, nelements, - elem2param, nparams, lam1, lam2, lam3, + elem3param, nparams, lam1, lam2, lam3, powermint, biga, bigb, bigr, bigd, c1, c2, c3, c4, c, d, h, gamma, beta, powern, Z_i, Z_j, ZBLcut, ZBLexpscale, diff --git a/src/GPU/pair_vashishta_gpu.cpp b/src/GPU/pair_vashishta_gpu.cpp index c5dd722974..b3c703952f 100644 --- a/src/GPU/pair_vashishta_gpu.cpp +++ b/src/GPU/pair_vashishta_gpu.cpp @@ -41,7 +41,7 @@ using namespace LAMMPS_NS; int vashishta_gpu_init(const int ntypes, const int inum, const int nall, const int max_nbors, const double cell_size, int &gpu_mode, FILE *screen, int* host_map, - const int nelements, int*** host_elem2param, + const int nelements, int*** host_elem3param, const int nparams, const double* cutsq, const double* r0, const double* gamma, const double* eta, const double* lam1inv, const double* lam4inv, @@ -217,7 +217,7 @@ void PairVashishtaGPU::init_style() int mnf = 5e-2 * neighbor->oneatom; int success = vashishta_gpu_init(atom->ntypes+1, atom->nlocal, atom->nlocal+atom->nghost, mnf, cell_size, gpu_mode, screen, map, nelements, - elem2param, nparams, cutsq, r0, gamma, eta, lam1inv, + elem3param, nparams, cutsq, r0, gamma, eta, lam1inv, lam4inv, zizj, mbigd, dvrc, big6w, heta, bigh, bigw, c0, costheta, bigb, big2b, bigc); memory->destroy(cutsq); diff --git a/src/KOKKOS/pair_sw_kokkos.cpp b/src/KOKKOS/pair_sw_kokkos.cpp index 5d629dc42a..2fb90b7aec 100644 --- a/src/KOKKOS/pair_sw_kokkos.cpp +++ b/src/KOKKOS/pair_sw_kokkos.cpp @@ -289,7 +289,7 @@ void PairSWKokkos::operator()(TagPairSWComputeHalf const X_FLOAT delz = ztmp - x(j,2); const F_FLOAT rsq = delx*delx + dely*dely + delz*delz; - const int ijparam = d_elem2param(itype,jtype,jtype); + const int ijparam = d_elem3param(itype,jtype,jtype); if (rsq >= d_params[ijparam].cutsq) continue; twobody(d_params[ijparam],rsq,fpair,eflag,evdwl); @@ -313,7 +313,7 @@ void PairSWKokkos::operator()(TagPairSWComputeHalf int j = d_neighbors_short(i,jj); j &= NEIGHMASK; const int jtype = d_map[type[j]]; - const int ijparam = d_elem2param(itype,jtype,jtype); + const int ijparam = d_elem3param(itype,jtype,jtype); delr1[0] = x(j,0) - xtmp; delr1[1] = x(j,1) - ytmp; delr1[2] = x(j,2) - ztmp; @@ -328,8 +328,8 @@ void PairSWKokkos::operator()(TagPairSWComputeHalf int k = d_neighbors_short(i,kk); k &= NEIGHMASK; const int ktype = d_map[type[k]]; - const int ikparam = d_elem2param(itype,ktype,ktype); - const int ijkparam = d_elem2param(itype,jtype,ktype); + const int ikparam = d_elem3param(itype,ktype,ktype); + const int ijkparam = d_elem3param(itype,jtype,ktype); delr2[0] = x(k,0) - xtmp; delr2[1] = x(k,1) - ytmp; @@ -412,7 +412,7 @@ void PairSWKokkos::operator()(TagPairSWComputeFullA= d_params[ijparam].cutsq) continue; @@ -434,7 +434,7 @@ void PairSWKokkos::operator()(TagPairSWComputeFullA::operator()(TagPairSWComputeFullA::operator()(TagPairSWComputeFullB= nlocal) continue; const int jtype = d_map[type[j]]; - const int jiparam = d_elem2param(jtype,itype,itype); + const int jiparam = d_elem3param(jtype,itype,itype); const X_FLOAT xtmpj = x(j,0); const X_FLOAT ytmpj = x(j,1); const X_FLOAT ztmpj = x(j,2); @@ -530,8 +530,8 @@ void PairSWKokkos::operator()(TagPairSWComputeFullB::setup_params() { PairSW::setup_params(); - // sync elem2param and params + // sync elem3param and params - tdual_int_3d k_elem2param = tdual_int_3d("pair:elem2param",nelements,nelements,nelements); - t_host_int_3d h_elem2param = k_elem2param.h_view; + tdual_int_3d k_elem3param = tdual_int_3d("pair:elem3param",nelements,nelements,nelements); + t_host_int_3d h_elem3param = k_elem3param.h_view; tdual_param_1d k_params = tdual_param_1d("pair:params",nparams); t_host_param_1d h_params = k_params.h_view; @@ -646,17 +646,17 @@ void PairSWKokkos::setup_params() for (int i = 0; i < nelements; i++) for (int j = 0; j < nelements; j++) for (int k = 0; k < nelements; k++) - h_elem2param(i,j,k) = elem2param[i][j][k]; + h_elem3param(i,j,k) = elem3param[i][j][k]; for (int m = 0; m < nparams; m++) h_params[m] = params[m]; - k_elem2param.template modify(); - k_elem2param.template sync(); + k_elem3param.template modify(); + k_elem3param.template sync(); k_params.template modify(); k_params.template sync(); - d_elem2param = k_elem2param.template view(); + d_elem3param = k_elem3param.template view(); d_params = k_params.template view(); } diff --git a/src/KOKKOS/pair_sw_kokkos.h b/src/KOKKOS/pair_sw_kokkos.h index 31b7f3301d..b9f4559bc2 100644 --- a/src/KOKKOS/pair_sw_kokkos.h +++ b/src/KOKKOS/pair_sw_kokkos.h @@ -102,7 +102,7 @@ class PairSWKokkos : public PairSW { typedef typename tdual_int_3d::t_dev_const_randomread t_int_3d_randomread; typedef typename tdual_int_3d::t_host t_host_int_3d; - t_int_3d_randomread d_elem2param; + t_int_3d_randomread d_elem3param; typename AT::t_int_1d_randomread d_map; typedef Kokkos::DualView tdual_param_1d; diff --git a/src/KOKKOS/pair_tersoff_kokkos.cpp b/src/KOKKOS/pair_tersoff_kokkos.cpp index 41a32a61e3..72a79c0b49 100644 --- a/src/KOKKOS/pair_tersoff_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_kokkos.cpp @@ -125,7 +125,7 @@ void PairTersoffKokkos::setup_params() for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) for (k = 1; k <= n; k++) { - m = elem2param[map[i]][map[j]][map[k]]; + m = elem3param[map[i]][map[j]][map[k]]; k_params.h_view(i,j,k).powerm = params[m].powerm; k_params.h_view(i,j,k).gamma = params[m].gamma; k_params.h_view(i,j,k).lam3 = params[m].lam3; diff --git a/src/KOKKOS/pair_tersoff_mod_kokkos.cpp b/src/KOKKOS/pair_tersoff_mod_kokkos.cpp index bd8e4d7528..c8431abc4b 100644 --- a/src/KOKKOS/pair_tersoff_mod_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_mod_kokkos.cpp @@ -124,7 +124,7 @@ void PairTersoffMODKokkos::setup_params() for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) for (k = 1; k <= n; k++) { - m = elem2param[map[i]][map[j]][map[k]]; + m = elem3param[map[i]][map[j]][map[k]]; k_params.h_view(i,j,k).powerm = params[m].powerm; k_params.h_view(i,j,k).lam3 = params[m].lam3; k_params.h_view(i,j,k).h = params[m].h; diff --git a/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp b/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp index 5e201dbc1c..3c362ad340 100644 --- a/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp @@ -135,7 +135,7 @@ void PairTersoffZBLKokkos::setup_params() for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) for (k = 1; k <= n; k++) { - m = elem2param[map[i]][map[j]][map[k]]; + m = elem3param[map[i]][map[j]][map[k]]; k_params.h_view(i,j,k).powerm = params[m].powerm; k_params.h_view(i,j,k).gamma = params[m].gamma; k_params.h_view(i,j,k).lam3 = params[m].lam3; diff --git a/src/KOKKOS/pair_vashishta_kokkos.cpp b/src/KOKKOS/pair_vashishta_kokkos.cpp index 4b7b50afe9..71f3215931 100644 --- a/src/KOKKOS/pair_vashishta_kokkos.cpp +++ b/src/KOKKOS/pair_vashishta_kokkos.cpp @@ -208,7 +208,7 @@ void PairVashishtaKokkos::operator()(TagPairVashishtaComputeShortNei int j = d_neighbors(i,jj); j &= NEIGHMASK; const int jtype = d_map[type[j]]; - const int ijparam = d_elem2param(itype,jtype,jtype); + const int ijparam = d_elem3param(itype,jtype,jtype); const X_FLOAT delx = xtmp - x(j,0); const X_FLOAT dely = ytmp - x(j,1); @@ -279,7 +279,7 @@ void PairVashishtaKokkos::operator()(TagPairVashishtaComputeHalf::operator()(TagPairVashishtaComputeHalf::operator()(TagPairVashishtaComputeHalf::operator()(TagPairVashishtaComputeFullA::operator()(TagPairVashishtaComputeFullA::operator()(TagPairVashishtaComputeFullA::operator()(TagPairVashishtaComputeFullB= nlocal) continue; const int jtype = d_map[type[j]]; - const int jiparam = d_elem2param(jtype,itype,itype); + const int jiparam = d_elem3param(jtype,itype,itype); const X_FLOAT xtmpj = x(j,0); const X_FLOAT ytmpj = x(j,1); const X_FLOAT ztmpj = x(j,2); @@ -508,8 +508,8 @@ void PairVashishtaKokkos::operator()(TagPairVashishtaComputeFullB::setup_params() { PairVashishta::setup_params(); - // sync elem2param and params + // sync elem3param and params - tdual_int_3d k_elem2param = tdual_int_3d("pair:elem2param",nelements,nelements,nelements); - t_host_int_3d h_elem2param = k_elem2param.h_view; + tdual_int_3d k_elem3param = tdual_int_3d("pair:elem3param",nelements,nelements,nelements); + t_host_int_3d h_elem3param = k_elem3param.h_view; tdual_param_1d k_params = tdual_param_1d("pair:params",nparams); t_host_param_1d h_params = k_params.h_view; @@ -622,17 +622,17 @@ void PairVashishtaKokkos::setup_params() for (int i = 0; i < nelements; i++) for (int j = 0; j < nelements; j++) for (int k = 0; k < nelements; k++) - h_elem2param(i,j,k) = elem2param[i][j][k]; + h_elem3param(i,j,k) = elem3param[i][j][k]; for (int m = 0; m < nparams; m++) h_params[m] = params[m]; - k_elem2param.template modify(); - k_elem2param.template sync(); + k_elem3param.template modify(); + k_elem3param.template sync(); k_params.template modify(); k_params.template sync(); - d_elem2param = k_elem2param.template view(); + d_elem3param = k_elem3param.template view(); d_params = k_params.template view(); } diff --git a/src/KOKKOS/pair_vashishta_kokkos.h b/src/KOKKOS/pair_vashishta_kokkos.h index 14dcf755df..aa8543e751 100644 --- a/src/KOKKOS/pair_vashishta_kokkos.h +++ b/src/KOKKOS/pair_vashishta_kokkos.h @@ -102,7 +102,7 @@ class PairVashishtaKokkos : public PairVashishta { typedef typename tdual_int_3d::t_dev_const_randomread t_int_3d_randomread; typedef typename tdual_int_3d::t_host t_host_int_3d; - t_int_3d_randomread d_elem2param; + t_int_3d_randomread d_elem3param; typename AT::t_int_1d_randomread d_map; typedef Kokkos::DualView tdual_param_1d; diff --git a/src/MANYBODY/pair_adp.cpp b/src/MANYBODY/pair_adp.cpp index aa11e0682a..59afbc280b 100644 --- a/src/MANYBODY/pair_adp.cpp +++ b/src/MANYBODY/pair_adp.cpp @@ -45,7 +45,6 @@ PairADP::PairADP(LAMMPS *lmp) : Pair(lmp) fp = nullptr; mu = nullptr; lambda = nullptr; - map = nullptr; setfl = nullptr; @@ -86,7 +85,6 @@ PairADP::~PairADP() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; delete [] type2frho; memory->destroy(type2rhor); memory->destroy(type2z2r); diff --git a/src/MANYBODY/pair_adp.h b/src/MANYBODY/pair_adp.h index 65596113ba..6a292dda14 100644 --- a/src/MANYBODY/pair_adp.h +++ b/src/MANYBODY/pair_adp.h @@ -67,8 +67,6 @@ class PairADP : public Pair { // potentials as file data - int *map; // which element each atom type maps to - struct Setfl { char **elements; int nelements,nrho,nr; diff --git a/src/MANYBODY/pair_bop.cpp b/src/MANYBODY/pair_bop.cpp index be4f17b291..a8f64853bc 100644 --- a/src/MANYBODY/pair_bop.cpp +++ b/src/MANYBODY/pair_bop.cpp @@ -69,7 +69,6 @@ PairBOP::PairBOP(LAMMPS *lmp) : Pair(lmp) BOP_index3 = nullptr; BOP_total = nullptr; BOP_total3 = nullptr; - map = nullptr; pi_a = nullptr; pro_delta = nullptr; pi_delta = nullptr; @@ -184,7 +183,6 @@ PairBOP::~PairBOP() if (allocated) { memory_theta_destroy(); if (otfly==0) memory->destroy(cos_index); - delete [] map; memory->destroy(BOP_index); memory->destroy(BOP_total); @@ -620,11 +618,6 @@ void PairBOP::coeff(int narg, char **arg) if (narg != 3 + atom->ntypes) error->all(FLERR,"Incorrect args for pair coefficients"); - // ensure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - // read the potential file nr=2000; nBOt=2000; @@ -657,6 +650,7 @@ void PairBOP::coeff(int narg, char **arg) if (elements) { for (i = 0; i < bop_types; i++) delete [] elements[i]; delete [] elements; + elements = nullptr; } } // clear setflag since coeff() called once with I,J = * * @@ -4922,10 +4916,7 @@ void _noopt PairBOP::read_table(char *filename) ValueTokenizer values = reader.next_values(3); values.next_int(); values.next_double(); - std::string name = values.next_string(); - - elements[i] = new char[name.length()+1]; - strcpy(elements[i], name.c_str()); + elements[i] = utils::strdup(values.next_string()); } ValueTokenizer values = reader.next_values(2); diff --git a/src/MANYBODY/pair_bop.h b/src/MANYBODY/pair_bop.h index d61c969094..ba75d5c591 100644 --- a/src/MANYBODY/pair_bop.h +++ b/src/MANYBODY/pair_bop.h @@ -46,17 +46,12 @@ class PairBOP : public Pair { int update_list; // check for changing maximum size of neighbor list int maxbopn; // maximum size of bop neighbor list for allocation int maxnall; // maximum size of bop neighbor list for allocation - int *map; // mapping from atom types to elements - int nelements; // # of unique elements int nr; // increments for the BOP pair potential int ntheta; // increments for the angle function int npower; // power of the angular function int nBOt; // second BO increments int bop_types; // number of elements in potential int npairs; // number of element pairs - char **elements; // names of unique elements - int ***elem2param; - int nparams; int bop_step; int allocate_neigh; int nb_pi,nb_sg; diff --git a/src/MANYBODY/pair_comb.cpp b/src/MANYBODY/pair_comb.cpp index 2d93c6783e..a1fc65deb7 100644 --- a/src/MANYBODY/pair_comb.cpp +++ b/src/MANYBODY/pair_comb.cpp @@ -62,12 +62,7 @@ PairComb::PairComb(LAMMPS *lmp) : Pair(lmp) map = nullptr; esm = nullptr; - nelements = 0; - elements = nullptr; - nparams = 0; - maxparam = 0; params = nullptr; - elem2param = nullptr; intype = nullptr; fafb = nullptr; @@ -97,12 +92,8 @@ PairComb::~PairComb() { memory->destroy(NCo); - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - - delete [] elements; memory->sfree(params); - memory->destroy(elem2param); + memory->destroy(elem3param); memory->destroy(intype); memory->destroy(fafb); @@ -120,7 +111,6 @@ PairComb::~PairComb() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; delete [] esm; } } @@ -184,7 +174,7 @@ void PairComb::compute(int eflag, int vflag) iq = q[i]; NCo[i] = 0; nj = 0; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; // self energy, only on i atom @@ -223,7 +213,7 @@ void PairComb::compute(int eflag, int vflag) dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; // long range q-dependent @@ -282,7 +272,7 @@ void PairComb::compute(int eflag, int vflag) for (jj = 0; jj < sht_jnum; jj++) { j = sht_jlist[jj]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (params[iparam_ij].hfocor > 0.0) { delr1[0] = x[j][0] - xtmp; @@ -303,7 +293,7 @@ void PairComb::compute(int eflag, int vflag) j = sht_jlist[jj]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; // this Qj for q-dependent BSi @@ -326,7 +316,7 @@ void PairComb::compute(int eflag, int vflag) k = sht_jlist[kk]; if (j == k) continue; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -370,7 +360,7 @@ void PairComb::compute(int eflag, int vflag) k = sht_jlist[kk]; if (j == k) continue; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -445,54 +435,15 @@ void PairComb::settings(int narg, char **/*arg*/) void PairComb::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - n = atom->ntypes; - // generate streitz-mintmire direct 1/r energy look-up table if (comm->me == 0 && screen) @@ -506,24 +457,6 @@ void PairComb::coeff(int narg, char **arg) else fputs(" will not apply over-coordination correction ...\n",screen); } - - // clear setflag since coeff() called once with I,J = * * - - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -741,12 +674,12 @@ void PairComb::setup_params() { int i,j,k,m,n; - // set elem2param for all element triplet combinations + // set elem3param for all element triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -760,7 +693,7 @@ void PairComb::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // compute parameter values derived from inputs @@ -1403,7 +1336,7 @@ void PairComb::sm_table() if (map[i+1] < 0) continue; r = drin; itype = params[map[i+1]].ielement; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; z = params[iparam_i].esm1; if (comm->me == 0 && screen) @@ -1425,7 +1358,7 @@ void PairComb::sm_table() if (j == i) { itype = params[map[i+1]].ielement; inty = intype[itype][itype]; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; z = params[iparam_i].esm1; zrc = z * rc; exp2ersh = exp(-2.0 * zrc); @@ -1451,10 +1384,10 @@ void PairComb::sm_table() itype = params[map[i+1]].ielement; jtype = params[map[j+1]].ielement; inty = intype[itype][jtype]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; ea = params[iparam_ij].esm1; ea3 = ea*ea*ea; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ji = elem3param[jtype][itype][itype]; eb = params[iparam_ji].esm1; eb3 = eb*eb*eb; E1 = ea*eb3*eb/((ea+eb)*(ea+eb)*(ea-eb)*(ea-eb)); @@ -1672,7 +1605,7 @@ double PairComb::yasu_char(double *qf_fix, int &igroup) ytmp = x[i][1]; ztmp = x[i][2]; iq = q[i]; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; // charge force from self energy @@ -1706,7 +1639,7 @@ double PairComb::yasu_char(double *qf_fix, int &igroup) delr1[2] = x[j][2] - ztmp; rsq1 = dot3(delr1,delr1); - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; // long range q-dependent @@ -1743,7 +1676,7 @@ double PairComb::yasu_char(double *qf_fix, int &igroup) delr1[2] = x[j][2] - ztmp; rsq1 = dot3(delr1,delr1); - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq1 > params[iparam_ij].cutsq) continue; nj ++; diff --git a/src/MANYBODY/pair_comb.h b/src/MANYBODY/pair_comb.h index c127bc0543..51b522badf 100644 --- a/src/MANYBODY/pair_comb.h +++ b/src/MANYBODY/pair_comb.h @@ -62,12 +62,6 @@ class PairComb : public Pair { }; double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets double precision; Param *params; // parameter set for an I-J-K interaction diff --git a/src/MANYBODY/pair_comb3.cpp b/src/MANYBODY/pair_comb3.cpp index d7814737ea..a0fa3b96b6 100644 --- a/src/MANYBODY/pair_comb3.cpp +++ b/src/MANYBODY/pair_comb3.cpp @@ -63,12 +63,7 @@ PairComb3::PairComb3(LAMMPS *lmp) : Pair(lmp) map = nullptr; esm = nullptr; - nelements = 0; - elements = nullptr; - nparams = 0; - maxparam = 0; params = nullptr; - elem2param = nullptr; intype = nullptr; afb = nullptr; @@ -107,12 +102,8 @@ PairComb3::~PairComb3() { memory->destroy(NCo); - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - - delete [] elements; memory->sfree(params); - memory->destroy(elem2param); + memory->destroy(elem3param); memory->destroy(afb); memory->destroy(dpl); @@ -139,7 +130,6 @@ PairComb3::~PairComb3() memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cutghost); - delete [] map; delete [] esm; } @@ -184,78 +174,31 @@ void PairComb3::settings(int narg, char **arg) void PairComb3::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); + cflag = 0; + for (int i = 3; i < narg; i++) + if (strcmp(arg[i],"C") == 0) { + cflag = 1; + break; + } - // insure I,J args are * * - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if ((strcmp(arg[i],"C") == 0) && (cflag == 0)) { - if (comm->me == 0 && screen) - fputs(" PairComb3: Found C: reading additional library file\n",screen); + if (cflag) { + if (comm->me == 0 && screen) + fputs(" PairComb3: Found C: reading additional library file\n",screen); read_lib(); - cflag = 1; - } - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } } + map_element2type(narg-3,arg+3); + // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - n = atom->ntypes; - // generate Wolf 1/r energy and van der Waals look-up tables + tables(); - - // clear setflag since coeff() called once with I,J = * * - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); - } /* ---------------------------------------------------------------------- @@ -687,12 +630,12 @@ void PairComb3::setup_params() { int i,j,k,m,n; - // set elem2param for all element triplet combinations + // set elem3param for all element triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -706,7 +649,7 @@ void PairComb3::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // compute parameter values derived from inputs @@ -804,7 +747,7 @@ void PairComb3::Short_neigh() delrj[2] = x[i][2] - x[j][2]; rsq1 = dot3(delrj,delrj); jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq1 > cutmin) continue; @@ -928,8 +871,8 @@ void PairComb3::compute(int eflag, int vflag) delrj[2] = x[j][2] - ztmp; rsq = dot3(delrj,delrj); - iparam_ij = elem2param[itype][jtype][jtype]; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ij = elem3param[itype][jtype][jtype]; + iparam_ji = elem3param[jtype][itype][itype]; if (rsq > params[iparam_ij].lcutsq) continue; @@ -950,7 +893,7 @@ void PairComb3::compute(int eflag, int vflag) ztmp = x[i][2]; iq = q[i]; nj = 0; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; // self energy, only on i atom yaself = self(¶ms[iparam_i],iq); @@ -991,8 +934,8 @@ void PairComb3::compute(int eflag, int vflag) dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; - iparam_ij = elem2param[itype][jtype][jtype]; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ij = elem3param[itype][jtype][jtype]; + iparam_ji = elem3param[jtype][itype][itype]; if (rsq > params[iparam_ij].lcutsq) continue; @@ -1091,8 +1034,8 @@ void PairComb3::compute(int eflag, int vflag) ycn = NCo[j]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ij = elem3param[itype][jtype][jtype]; + iparam_ji = elem3param[jtype][itype][itype]; delrj[0] = x[j][0] - xtmp; delrj[1] = x[j][1] - ytmp; @@ -1114,10 +1057,10 @@ void PairComb3::compute(int eflag, int vflag) if (j == k) continue; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; - iparam_ikj = elem2param[itype][ktype][jtype]; - iparam_jik = elem2param[jtype][itype][ktype]; - iparam_ik = elem2param[itype][ktype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; + iparam_ikj = elem3param[itype][ktype][jtype]; + iparam_jik = elem3param[jtype][itype][ktype]; + iparam_ik = elem3param[itype][ktype][ktype]; delrk[0] = x[k][0] - xtmp; delrk[1] = x[k][1] - ytmp; delrk[2] = x[k][2] - ztmp; @@ -1133,7 +1076,7 @@ void PairComb3::compute(int eflag, int vflag) if (params[iparam_ij].rad_flag > 0 && params[iparam_ik].ielementgp == 1 && params[iparam_ik].jelementgp == 1) { - iparam_ki = elem2param[ktype][itype][itype]; + iparam_ki = elem3param[ktype][itype][itype]; kcn=NCo[k]; kconjug += rad_init(rsq2,¶ms[iparam_ki],i,kradtot,kcn); @@ -1157,11 +1100,11 @@ void PairComb3::compute(int eflag, int vflag) delrl[1] = x[l][1] - x[j][1]; delrl[2] = x[l][2] - x[j][2]; rsq3 = dot3(delrl,delrl); - iparam_jl = elem2param[jtype][ltype][ltype]; + iparam_jl = elem3param[jtype][ltype][ltype]; if (rsq3 > params[iparam_jl].cutsq) continue; - iparam_ikl = elem2param[itype][ktype][ltype]; + iparam_ikl = elem3param[itype][ktype][ltype]; torindx = params[iparam_ij].tor_flag; bbtor += bbtor1(torindx, ¶ms[iparam_ikl],¶ms[iparam_jl], rsq1,rsq2,rsq3,delrj,delrk,delrl,srmu); @@ -1178,10 +1121,10 @@ void PairComb3::compute(int eflag, int vflag) if (l == i) continue; ltype = map[type[l]]; - iparam_jil = elem2param[jtype][itype][ltype]; - iparam_ijl = elem2param[itype][jtype][ltype]; - iparam_jl = elem2param[jtype][ltype][ltype]; - iparam_lj = elem2param[ltype][jtype][jtype]; + iparam_jil = elem3param[jtype][itype][ltype]; + iparam_ijl = elem3param[itype][jtype][ltype]; + iparam_jl = elem3param[jtype][ltype][ltype]; + iparam_lj = elem3param[ltype][jtype][jtype]; delrk[0] = x[l][0] - x[j][0]; delrk[1] = x[l][1] - x[j][1]; @@ -1204,7 +1147,7 @@ void PairComb3::compute(int eflag, int vflag) if (params[iparam_ji].rad_flag > 0 && params[iparam_jl].ielementgp == 1 && params[iparam_jl].jelementgp == 1) { - iparam_lj = elem2param[ltype][jtype][jtype]; + iparam_lj = elem3param[ltype][jtype][jtype]; lcn=NCo[l]; lconjug += rad_init(rsq2,¶ms[iparam_lj],j,lradtot,lcn); } @@ -1240,10 +1183,10 @@ void PairComb3::compute(int eflag, int vflag) sht_mnum = sht_num[k]; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; - iparam_ikj = elem2param[itype][ktype][jtype]; - iparam_jik = elem2param[jtype][itype][ktype]; - iparam_ik = elem2param[itype][ktype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; + iparam_ikj = elem3param[itype][ktype][jtype]; + iparam_jik = elem3param[jtype][itype][ktype]; + iparam_ik = elem3param[itype][ktype][ktype]; delrk[0] = x[k][0] - xtmp; delrk[1] = x[k][1] - ytmp; delrk[2] = x[k][2] - ztmp; @@ -1289,9 +1232,9 @@ void PairComb3::compute(int eflag, int vflag) delrl[2] = x[l][2] - x[j][2]; rsq3 = dot3(delrl,delrl); - iparam_jl = elem2param[jtype][ltype][ltype]; + iparam_jl = elem3param[jtype][ltype][ltype]; if (rsq3 > params[iparam_jl].cutsq) continue; - iparam_ikl = elem2param[itype][ktype][ltype]; + iparam_ikl = elem3param[itype][ktype][ltype]; torindx = params[iparam_ij].tor_flag; tor_force(torindx, ¶ms[iparam_ikl], ¶ms[iparam_jl],srmu, rsq1,rsq2,rsq3,delrj,delrk,delrl); @@ -1309,7 +1252,7 @@ void PairComb3::compute(int eflag, int vflag) if ( params[iparam_ijk].rad_flag>=1 && params[iparam_ijk].ielementgp==1 && params[iparam_ijk].kelementgp==1) { - iparam_ki = elem2param[ktype][itype][itype]; + iparam_ki = elem3param[ktype][itype][itype]; kcn=NCo[k]; double rik=sqrt(rsq2); kradtot = -comb_fc(rik,¶ms[iparam_ki])*params[iparam_ki].pcross+kcn; @@ -1333,8 +1276,8 @@ void PairComb3::compute(int eflag, int vflag) delrm[2] = x[m][2] - x[k][2]; rsq3 = dot3(delrm,delrm); - iparam_km = elem2param[ktype][mtype][mtype]; - iparam_ki = elem2param[ktype][itype][itype]; + iparam_km = elem3param[ktype][mtype][mtype]; + iparam_ki = elem3param[ktype][itype][itype]; if (rsq3 > params[iparam_km].cutsq) continue; @@ -1364,10 +1307,10 @@ void PairComb3::compute(int eflag, int vflag) sht_pnum = sht_num[l]; ltype = map[type[l]]; - iparam_jil = elem2param[jtype][itype][ltype]; - iparam_jli = elem2param[jtype][ltype][itype]; - iparam_ijl = elem2param[itype][jtype][ltype]; - iparam_jl = elem2param[jtype][ltype][ltype]; + iparam_jil = elem3param[jtype][itype][ltype]; + iparam_jli = elem3param[jtype][ltype][itype]; + iparam_ijl = elem3param[itype][jtype][ltype]; + iparam_jl = elem3param[jtype][ltype][ltype]; delrk[0] = x[l][0] - x[j][0]; delrk[1] = x[l][1] - x[j][1]; delrk[2] = x[l][2] - x[j][2]; @@ -1405,7 +1348,7 @@ void PairComb3::compute(int eflag, int vflag) if ( params[iparam_jil].rad_flag >= 1 && params[iparam_jil].ielementgp == 1 && params[iparam_jil].kelementgp == 1) { - iparam_lj = elem2param[ltype][jtype][jtype]; + iparam_lj = elem3param[ltype][jtype][jtype]; lcn=NCo[l]; double rjl=sqrt(rsq2); lradtot=-comb_fc(rjl,¶ms[iparam_lj])*params[iparam_lj].pcross +lcn; @@ -1428,7 +1371,7 @@ void PairComb3::compute(int eflag, int vflag) delrp[2] = x[p][2] - x[l][2]; rsq3 = dot3(delrp,delrp); - iparam_lp = elem2param[ltype][ptype][ptype]; + iparam_lp = elem3param[ltype][ptype][ptype]; if (rsq3 > params[iparam_lp].cutsq) continue; @@ -2354,7 +2297,7 @@ void PairComb3::tables() if (map[i+1] < 0) continue; r = drin - dra; itype = map[i+1]; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; z = params[iparam_i].esm; exp2ershift = exp(-2.0*z*rc); afbshift = -exp2ershift*(z+1.0/rc); @@ -2381,7 +2324,7 @@ void PairComb3::tables() if (j == i) { itype = map[i+1]; inty = intype[itype][itype]; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; z = params[iparam_i].esm; zrc = z * rc; exp2ersh = exp(-2.0 * zrc); @@ -2407,10 +2350,10 @@ void PairComb3::tables() itype = map[i+1]; jtype = map[j+1]; inty = intype[itype][jtype]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; ea = params[iparam_ij].esm; ea3 = ea*ea*ea; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ji = elem3param[jtype][itype][itype]; eb = params[iparam_ji].esm; eb3 = eb*eb*eb; E1 = ea*eb3*eb/((ea+eb)*(ea+eb)*(ea-eb)*(ea-eb)); @@ -2474,7 +2417,7 @@ void PairComb3::tables() itype = ii; jtype = jj; inty = intype[itype][jtype]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; // parameter check: eps > 0 if (params[iparam_ij].vdwflag > 0) { @@ -2521,7 +2464,7 @@ void PairComb3::tables() itype = ii; jtype = jj; inty = intype[itype][jtype]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; r = drin; for (k = 0; k < ncoul; k ++) { r6 = r*r*r*r*r*r; @@ -3229,7 +3172,7 @@ double PairComb3::combqeq(double *qf_fix, int &igroup) ytmp = x[i][1]; ztmp = x[i][2]; iq = q[i]; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; // charge force from self energy fqi = qfo_self(¶ms[iparam_i],iq); @@ -3257,8 +3200,8 @@ double PairComb3::combqeq(double *qf_fix, int &igroup) delrj[2] = ztmp - x[j][2]; rsq1 = dot3(delrj,delrj); - iparam_ij = elem2param[itype][jtype][jtype]; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ij = elem3param[itype][jtype][jtype]; + iparam_ji = elem3param[jtype][itype][itype]; // long range q-dependent @@ -3304,8 +3247,8 @@ double PairComb3::combqeq(double *qf_fix, int &igroup) delrj[2] = ztmp - x[j][2]; rsq1 = dot3(delrj,delrj); - iparam_ij = elem2param[itype][jtype][jtype]; - iparam_ji = elem2param[jtype][itype][itype]; + iparam_ij = elem3param[itype][jtype][jtype]; + iparam_ji = elem3param[jtype][itype][itype]; if (rsq1 >= params[iparam_ij].cutsq) continue; nj ++; diff --git a/src/MANYBODY/pair_comb3.h b/src/MANYBODY/pair_comb3.h index b999d2cece..d03ee0e474 100644 --- a/src/MANYBODY/pair_comb3.h +++ b/src/MANYBODY/pair_comb3.h @@ -61,16 +61,10 @@ class PairComb3 : public Pair { }; // general setups - int nelements; // # of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets double PI,PI2,PI4,PIsq; // PIs double cutmin; // min cutoff for all elements double cutmax; // max cutoff for all elements double precision; // tolerance for QEq convergence - char **elements; // names of unique elements Param *params; // parameter set for an I-J-K interaction int debug_eng1, debug_eng2, debug_fq; // logic controlling debugging outputs int pack_flag; diff --git a/src/MANYBODY/pair_eam.cpp b/src/MANYBODY/pair_eam.cpp index 03098904c8..b5fd507687 100644 --- a/src/MANYBODY/pair_eam.cpp +++ b/src/MANYBODY/pair_eam.cpp @@ -49,7 +49,6 @@ PairEAM::PairEAM(LAMMPS *lmp) : Pair(lmp) rho = nullptr; fp = nullptr; numforce = nullptr; - map = nullptr; type2frho = nullptr; nfuncfl = 0; @@ -90,9 +89,7 @@ PairEAM::~PairEAM() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; delete [] type2frho; - map = nullptr; type2frho = nullptr; memory->destroy(type2rhor); memory->destroy(type2z2r); @@ -348,6 +345,7 @@ void PairEAM::allocate() memory->create(cutsq,n+1,n+1,"pair:cutsq"); + delete[] map; map = new int[n+1]; for (int i = 1; i <= n; i++) map[i] = -1; diff --git a/src/MANYBODY/pair_eam.h b/src/MANYBODY/pair_eam.h index 7e47c0f4e9..e9cbd15f34 100644 --- a/src/MANYBODY/pair_eam.h +++ b/src/MANYBODY/pair_eam.h @@ -75,8 +75,6 @@ class PairEAM : public Pair { // potentials as file data - int *map; // which element each atom type maps to - struct Funcfl { char *file; int nrho,nr; diff --git a/src/MANYBODY/pair_eim.cpp b/src/MANYBODY/pair_eim.cpp index b82a410791..eda1838a5a 100644 --- a/src/MANYBODY/pair_eim.cpp +++ b/src/MANYBODY/pair_eim.cpp @@ -46,10 +46,6 @@ PairEIM::PairEIM(LAMMPS *lmp) : Pair(lmp) nmax = 0; rho = nullptr; fp = nullptr; - map = nullptr; - - nelements = 0; - elements = nullptr; negativity = nullptr; q0 = nullptr; @@ -80,15 +76,11 @@ PairEIM::~PairEIM() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; memory->destroy(type2Fij); memory->destroy(type2Gij); memory->destroy(type2phiij); } - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - deallocate_setfl(); delete [] negativity; @@ -353,8 +345,6 @@ void PairEIM::settings(int narg, char **/*arg*/) void PairEIM::coeff(int narg, char **arg) { - int i,j,m,n; - if (!allocated) allocate(); if (narg < 5) error->all(FLERR,"Incorrect args for pair coefficients"); @@ -364,23 +354,8 @@ void PairEIM::coeff(int narg, char **arg) if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) error->all(FLERR,"Incorrect args for pair coefficients"); - // read EIM element names before filename - // nelements = # of EIM elements to read from file - // elements = list of unique element names - - if (nelements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - nelements = narg - 3 - atom->ntypes; - if (nelements < 1) error->all(FLERR,"Incorrect args for pair coefficients"); - elements = new char*[nelements]; - - for (i = 0; i < nelements; i++) { - n = strlen(arg[i+2]) + 1; - elements[i] = new char[n]; - strcpy(elements[i],arg[i+2]); - } + const int ntypes = atom->ntypes; + map_element2type(ntypes,arg+(narg-ntypes)); // read EIM file @@ -388,38 +363,12 @@ void PairEIM::coeff(int narg, char **arg) setfl = new Setfl(); read_file(arg[2+nelements]); - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" + // set per-type atomic masses - for (i = 3 + nelements; i < narg; i++) { - m = i - (3+nelements) + 1; - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - if (j < nelements) map[m] = j; - else if (strcmp(arg[i],"NULL") == 0) map[m] = -1; - else error->all(FLERR,"Incorrect args for pair coefficients"); - } - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - // set mass of atom type if i = j - - int count = 0; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; + for (int i = 1; i <= ntypes; i++) + for (int j = i; j <= ntypes; j++) + if ((map[i] >= 0) && (map[j] >= 0)) if (i == j) atom->set_mass(FLERR,i,setfl->mass[map[i]]); - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- diff --git a/src/MANYBODY/pair_eim.h b/src/MANYBODY/pair_eim.h index 75f8ea6bea..7611898c45 100644 --- a/src/MANYBODY/pair_eim.h +++ b/src/MANYBODY/pair_eim.h @@ -60,10 +60,6 @@ class PairEIM : public Pair { int nmax; double *rho,*fp; int rhofp; - int *map; // which element each atom type maps to - - int nelements; // # of elements to read from potential file - char **elements; // element names Setfl *setfl; diff --git a/src/MANYBODY/pair_gw.cpp b/src/MANYBODY/pair_gw.cpp index 6039e00c0a..7e0cb3a3a2 100644 --- a/src/MANYBODY/pair_gw.cpp +++ b/src/MANYBODY/pair_gw.cpp @@ -51,12 +51,7 @@ PairGW::PairGW(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; - map = nullptr; } /* ---------------------------------------------------------------------- @@ -65,16 +60,12 @@ PairGW::PairGW(LAMMPS *lmp) : Pair(lmp) PairGW::~PairGW() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; } } @@ -142,7 +133,7 @@ void PairGW::compute(int eflag, int vflag) delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq > params[iparam_ij].cutsq) continue; repulsive(¶ms[iparam_ij],rsq,fpair,eflag,evdwl); @@ -165,7 +156,7 @@ void PairGW::compute(int eflag, int vflag) j = jlist[jj]; j &= NEIGHMASK; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; @@ -182,7 +173,7 @@ void PairGW::compute(int eflag, int vflag) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -214,7 +205,7 @@ void PairGW::compute(int eflag, int vflag) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -271,70 +262,14 @@ void PairGW::settings(int narg, char **/*arg*/) void PairGW::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -480,12 +415,12 @@ void PairGW::setup_params() { int i,j,k,m,n; - // set elem2param for all element triplet combinations + // set elem3param for all element triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -500,7 +435,7 @@ void PairGW::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } diff --git a/src/MANYBODY/pair_gw.h b/src/MANYBODY/pair_gw.h index 620f0b1af0..a1cbdb5c86 100644 --- a/src/MANYBODY/pair_gw.h +++ b/src/MANYBODY/pair_gw.h @@ -52,13 +52,7 @@ class PairGW : public Pair { }; Param *params; // parameter set for an I-J-K interaction - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to paramegw - int *map; // mapping from atom types to elements double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets int **pages; // neighbor list pages int maxlocal; // size of numneigh, firstneigh arrays diff --git a/src/MANYBODY/pair_lcbop.cpp b/src/MANYBODY/pair_lcbop.cpp index a2a8c3d1fa..727556dd50 100644 --- a/src/MANYBODY/pair_lcbop.cpp +++ b/src/MANYBODY/pair_lcbop.cpp @@ -74,8 +74,6 @@ PairLCBOP::~PairLCBOP() memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cutghost); - - delete [] map; } } @@ -128,48 +126,17 @@ void PairLCBOP::coeff(int narg, char **arg) { if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); + map_element2type(narg-3,arg+3); - // insure I,J args are * * + // only element "C" is allowed - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to C and "NULL" - // map[i] = which element (0 for C) the Ith atom type is, -1 if "NULL" - - for (int i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - } else if (strcmp(arg[i],"C") == 0) { - map[i-2] = 0; - } else error->all(FLERR,"Incorrect args for pair coefficients"); - } + if ((nelements != 1) || (strcmp(elements[0],"C") != 0)) + error->all(FLERR,"Incorrect args for pair coefficients"); // read potential file and initialize fitting splines read_file(arg[2]); spline_init(); - - // clear setflag since coeff() called once with I,J = * * - - int n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -965,11 +932,9 @@ void PairLCBOP::read_file(char *filename) int i,k,l; char s[MAXLINE]; - MPI_Comm_rank(world,&me); - // read file on proc 0 - if (me == 0) { + if (comm->me == 0) { FILE *fp = utils::open_potential(filename,lmp,nullptr); if (fp == nullptr) { char str[128]; diff --git a/src/MANYBODY/pair_lcbop.h b/src/MANYBODY/pair_lcbop.h index dacbe74158..4ee89b4148 100644 --- a/src/MANYBODY/pair_lcbop.h +++ b/src/MANYBODY/pair_lcbop.h @@ -39,9 +39,6 @@ class PairLCBOP : public Pair { protected: int **pages; // neighbor list pages - int *map; // 0 (C) or -1 ("NULL") for each type - - int me; double cutLR; // LR cutoff diff --git a/src/MANYBODY/pair_nb3b_harmonic.cpp b/src/MANYBODY/pair_nb3b_harmonic.cpp index a1dc903a43..dfc4046eda 100644 --- a/src/MANYBODY/pair_nb3b_harmonic.cpp +++ b/src/MANYBODY/pair_nb3b_harmonic.cpp @@ -50,12 +50,7 @@ PairNb3bHarmonic::PairNb3bHarmonic(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; - map = nullptr; } /* ---------------------------------------------------------------------- @@ -64,16 +59,12 @@ PairNb3bHarmonic::PairNb3bHarmonic(LAMMPS *lmp) : Pair(lmp) PairNb3bHarmonic::~PairNb3bHarmonic() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; } } @@ -117,7 +108,7 @@ void PairNb3bHarmonic::compute(int eflag, int vflag) j = jlist[jj]; j &= NEIGHMASK; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; delr1[2] = x[j][2] - ztmp; @@ -128,8 +119,8 @@ void PairNb3bHarmonic::compute(int eflag, int vflag) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -186,70 +177,14 @@ void PairNb3bHarmonic::settings(int narg, char **/*arg*/) void PairNb3bHarmonic::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } @@ -374,12 +309,12 @@ void PairNb3bHarmonic::setup_params() int i,j,k,m,n; double rtmp; - // set elem2param for all triplet combinations + // set elem3param for all triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -393,7 +328,7 @@ void PairNb3bHarmonic::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // compute parameter values derived from inputs diff --git a/src/MANYBODY/pair_nb3b_harmonic.h b/src/MANYBODY/pair_nb3b_harmonic.h index b68974e15f..38ec07c78b 100644 --- a/src/MANYBODY/pair_nb3b_harmonic.h +++ b/src/MANYBODY/pair_nb3b_harmonic.h @@ -44,12 +44,6 @@ class PairNb3bHarmonic : public Pair { }; double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets Param *params; // parameter set for an I-J-K interaction void allocate(); diff --git a/src/MANYBODY/pair_polymorphic.cpp b/src/MANYBODY/pair_polymorphic.cpp index a353ad1c47..e267031901 100644 --- a/src/MANYBODY/pair_polymorphic.cpp +++ b/src/MANYBODY/pair_polymorphic.cpp @@ -49,14 +49,11 @@ PairPolymorphic::PairPolymorphic(LAMMPS *lmp) : Pair(lmp) manybody_flag = 1; centroidstressflag = CENTROID_NOTAVAIL; - nelements = 0; - elements = nullptr; match = nullptr; pairParameters = nullptr; tripletParameters = nullptr; elem2param = nullptr; elem3param = nullptr; - map = nullptr; epsilon = 0.0; neighsize = 0; firstneighV = nullptr; @@ -78,9 +75,6 @@ PairPolymorphic::PairPolymorphic(LAMMPS *lmp) : Pair(lmp) PairPolymorphic::~PairPolymorphic() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; delete [] match; delete [] pairParameters; @@ -91,7 +85,6 @@ PairPolymorphic::~PairPolymorphic() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; delete [] firstneighV; delete [] firstneighW; delete [] firstneighW1; @@ -466,74 +459,19 @@ void PairPolymorphic::settings(int narg, char **/*arg*/) void PairPolymorphic::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg == 4 + atom->ntypes) { - narg--; - epsilon = atof(arg[narg]); - } else if (narg != 3 + atom->ntypes) { - error->all(FLERR,"Incorrect args for pair coefficients"); - } + // parse and remove optional last parameter - // insure I,J args are * * + if (narg == 4 + atom->ntypes) + epsilon = utils::numeric(FLERR,arg[--narg],false,lmp); - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- diff --git a/src/MANYBODY/pair_polymorphic.h b/src/MANYBODY/pair_polymorphic.h index c94acd6230..a8a74267cd 100644 --- a/src/MANYBODY/pair_polymorphic.h +++ b/src/MANYBODY/pair_polymorphic.h @@ -302,13 +302,8 @@ class PairPolymorphic : public Pair { double *delxV,*delyV,*delzV,*drV; double *delxW,*delyW,*delzW,*drW; - char **elements; // names of unique elements - int **elem2param; // map: element pairs to parameters - int ***elem3param; // map: element triplets to parameters - int *map; // mapping from atom types to elements double cutmax; // max cutoff for all elements double cutmaxsq; - int nelements; // # of unique elements int npair,ntriple; int *match; diff --git a/src/MANYBODY/pair_sw.cpp b/src/MANYBODY/pair_sw.cpp index e7a334d9a9..fe7e56456e 100644 --- a/src/MANYBODY/pair_sw.cpp +++ b/src/MANYBODY/pair_sw.cpp @@ -46,12 +46,7 @@ PairSW::PairSW(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; - map = nullptr; maxshort = 10; neighshort = nullptr; @@ -65,17 +60,13 @@ PairSW::~PairSW() { if (copymode) return; - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(neighshort); - delete [] map; } } @@ -135,7 +126,7 @@ void PairSW::compute(int eflag, int vflag) rsq = delx*delx + dely*dely + delz*delz; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (rsq >= params[ijparam].cutsq) { continue; } else { @@ -175,7 +166,7 @@ void PairSW::compute(int eflag, int vflag) for (jj = 0; jj < jnumm1; jj++) { j = neighshort[jj]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; delr1[2] = x[j][2] - ztmp; @@ -187,8 +178,8 @@ void PairSW::compute(int eflag, int vflag) for (kk = jj+1; kk < numshort; kk++) { k = neighshort[kk]; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -250,70 +241,14 @@ void PairSW::settings(int narg, char **/*arg*/) void PairSW::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -451,12 +386,12 @@ void PairSW::setup_params() int i,j,k,m,n; double rtmp; - // set elem2param for all triplet combinations + // set elem3param for all triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -470,7 +405,7 @@ void PairSW::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } diff --git a/src/MANYBODY/pair_sw.h b/src/MANYBODY/pair_sw.h index 4fdc538430..4e13caee85 100644 --- a/src/MANYBODY/pair_sw.h +++ b/src/MANYBODY/pair_sw.h @@ -50,12 +50,6 @@ class PairSW : public Pair { protected: double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets Param *params; // parameter set for an I-J-K interaction int maxshort; // size of short neighbor list array int *neighshort; // short neighbor list array diff --git a/src/MANYBODY/pair_tersoff.cpp b/src/MANYBODY/pair_tersoff.cpp index dea01589a6..2a642e6244 100644 --- a/src/MANYBODY/pair_tersoff.cpp +++ b/src/MANYBODY/pair_tersoff.cpp @@ -54,12 +54,7 @@ PairTersoff::PairTersoff(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; - map = nullptr; maxshort = 10; neighshort = nullptr; @@ -73,17 +68,13 @@ PairTersoff::~PairTersoff() { if (copymode) return; - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(neighshort); - delete [] map; } } @@ -204,7 +195,7 @@ void PairTersoff::eval() } jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq >= params[iparam_ij].cutsq) continue; repulsive(¶ms[iparam_ij],rsq,fpair,EFLAG,evdwl); @@ -231,7 +222,7 @@ void PairTersoff::eval() for (jj = 0; jj < numshort; jj++) { j = neighshort[jj]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; @@ -255,7 +246,7 @@ void PairTersoff::eval() if (jj == kk) continue; k = neighshort[kk]; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -295,7 +286,7 @@ void PairTersoff::eval() if (jj == kk) continue; k = neighshort[kk]; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -383,70 +374,14 @@ void PairTersoff::settings(int narg, char **arg) void PairTersoff::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -598,12 +533,12 @@ void PairTersoff::setup_params() { int i,j,k,m,n; - // set elem2param for all element triplet combinations + // set elem3param for all element triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -617,7 +552,7 @@ void PairTersoff::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } diff --git a/src/MANYBODY/pair_tersoff.h b/src/MANYBODY/pair_tersoff.h index 18c6ebc5f9..a4612d03be 100644 --- a/src/MANYBODY/pair_tersoff.h +++ b/src/MANYBODY/pair_tersoff.h @@ -59,13 +59,7 @@ class PairTersoff : public Pair { }; Param *params; // parameter set for an I-J-K interaction - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets int maxshort; // size of short neighbor list array int *neighshort; // short neighbor list array diff --git a/src/MANYBODY/pair_tersoff_mod.cpp b/src/MANYBODY/pair_tersoff_mod.cpp index 86994ccc0e..465bc0ebd0 100644 --- a/src/MANYBODY/pair_tersoff_mod.cpp +++ b/src/MANYBODY/pair_tersoff_mod.cpp @@ -163,12 +163,12 @@ void PairTersoffMOD::setup_params() { int i,j,k,m,n; - // set elem2param for all element triplet combinations + // set elem3param for all element triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -182,7 +182,7 @@ void PairTersoffMOD::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } diff --git a/src/MANYBODY/pair_vashishta.cpp b/src/MANYBODY/pair_vashishta.cpp index 94f211dd95..cacfa7078e 100644 --- a/src/MANYBODY/pair_vashishta.cpp +++ b/src/MANYBODY/pair_vashishta.cpp @@ -48,12 +48,7 @@ PairVashishta::PairVashishta(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; - map = nullptr; r0max = 0.0; maxshort = 10; @@ -68,17 +63,13 @@ PairVashishta::~PairVashishta() { if (copymode) return; - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(neighshort); - delete [] map; } } @@ -158,7 +149,7 @@ void PairVashishta::compute(int eflag, int vflag) } jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (rsq >= params[ijparam].cutsq) continue; twobody(¶ms[ijparam],rsq,fpair,eflag,evdwl); @@ -179,7 +170,7 @@ void PairVashishta::compute(int eflag, int vflag) for (jj = 0; jj < jnumm1; jj++) { j = neighshort[jj]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; delr1[2] = x[j][2] - ztmp; @@ -192,8 +183,8 @@ void PairVashishta::compute(int eflag, int vflag) for (kk = jj+1; kk < numshort; kk++) { k = neighshort[kk]; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -257,70 +248,14 @@ void PairVashishta::settings(int narg, char **/*arg*/) void PairVashishta::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -465,12 +400,12 @@ void PairVashishta::setup_params() { int i,j,k,m,n; - // set elem2param for all triplet combinations + // set elem3param for all triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -484,7 +419,7 @@ void PairVashishta::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // compute parameter values derived from inputs diff --git a/src/MANYBODY/pair_vashishta.h b/src/MANYBODY/pair_vashishta.h index 19a8e01cd9..06c23b2384 100644 --- a/src/MANYBODY/pair_vashishta.h +++ b/src/MANYBODY/pair_vashishta.h @@ -48,12 +48,6 @@ class PairVashishta : public Pair { }; protected: double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets Param *params; // parameter set for an I-J-K interaction double r0max; // largest value of r0 int maxshort; // size of short neighbor list array diff --git a/src/MANYBODY/pair_vashishta_table.cpp b/src/MANYBODY/pair_vashishta_table.cpp index 76b44d8664..14dacdae3f 100644 --- a/src/MANYBODY/pair_vashishta_table.cpp +++ b/src/MANYBODY/pair_vashishta_table.cpp @@ -120,7 +120,7 @@ void PairVashishtaTable::compute(int eflag, int vflag) } jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (rsq >= params[ijparam].cutsq) continue; twobody_table(params[ijparam],rsq,fpair,eflag,evdwl); @@ -141,7 +141,7 @@ void PairVashishtaTable::compute(int eflag, int vflag) for (jj = 0; jj < jnumm1; jj++) { j = neighshort[jj]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; delr1[2] = x[j][2] - ztmp; @@ -154,8 +154,8 @@ void PairVashishtaTable::compute(int eflag, int vflag) for (kk = jj+1; kk < numshort; kk++) { k = neighshort[kk]; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -272,7 +272,7 @@ void PairVashishtaTable::create_tables() for (i = 0; i < nelements; i++) { for (j = 0; j < nelements; j++) { - int ijparam = elem2param[i][j][j]; + int ijparam = elem3param[i][j][j]; for (idx = 0; idx <= ntable; idx++) { rsq = tabinnersq + idx*deltaR2; PairVashishta::twobody(¶ms[ijparam],rsq,fpair,1,eng); diff --git a/src/SNAP/pair_snap.cpp b/src/SNAP/pair_snap.cpp index 7d57ca3673..ae0023ddec 100644 --- a/src/SNAP/pair_snap.cpp +++ b/src/SNAP/pair_snap.cpp @@ -42,8 +42,6 @@ PairSNAP::PairSNAP(LAMMPS *lmp) : Pair(lmp) manybody_flag = 1; centroidstressflag = CENTROID_NOTAVAIL; - nelements = 0; - elements = nullptr; radelem = nullptr; wjelem = nullptr; coeffelem = nullptr; @@ -60,14 +58,9 @@ PairSNAP::~PairSNAP() { if (copymode) return; - if (nelements) { - for (int i = 0; i < nelements; i++) - delete[] elements[i]; - delete[] elements; - memory->destroy(radelem); - memory->destroy(wjelem); - memory->destroy(coeffelem); - } + memory->destroy(radelem); + memory->destroy(wjelem); + memory->destroy(coeffelem); memory->destroy(beta); memory->destroy(bispectrum); @@ -77,7 +70,6 @@ PairSNAP::~PairSNAP() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - memory->destroy(map); } } @@ -362,7 +354,7 @@ void PairSNAP::allocate() memory->create(setflag,n+1,n+1,"pair:setflag"); memory->create(cutsq,n+1,n+1,"pair:cutsq"); - memory->create(map,n+1,"pair:map"); + map = new int[n+1]; } /* ---------------------------------------------------------------------- @@ -384,61 +376,11 @@ void PairSNAP::coeff(int narg, char **arg) if (!allocated) allocate(); if (narg != 4 + atom->ntypes) error->all(FLERR,"Incorrect args for pair coefficients"); - char* type1 = arg[0]; - char* type2 = arg[1]; - char* coefffilename = arg[2]; - char* paramfilename = arg[3]; - char** elemtypes = &arg[4]; - - // insure I,J args are * * - - if (strcmp(type1,"*") != 0 || strcmp(type2,"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // clean out old arrays - - if (elements) { - for (int i = 0; i < nelements; i++) - delete[] elements[i]; - delete[] elements; - memory->destroy(radelem); - memory->destroy(wjelem); - memory->destroy(coeffelem); - } - - // nelements = # of unique elements declared - // elements = list of unique element names - // allocate as ntypes >= nelements - - elements = new char*[atom->ntypes]; - for (int i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - // read args that map atom types to SNAP elements - // map[i] = which element the Ith atom type is, -1 if not mapped - // map[0] is not used - - nelements = 0; - for (int i = 1; i <= atom->ntypes; i++) { - char* elemstring = elemtypes[i-1]; - if (strcmp(elemstring,"NULL") == 0) { - map[i] = -1; - continue; - } - int j; - for (j = 0; j < nelements; j++) - if (strcmp(elemstring,elements[j]) == 0) break; - map[i] = j; - if (j == nelements) { - int n = strlen(elemstring) + 1; - elements[j] = new char[n]; - strcpy(elements[j],elemstring); - nelements++; - } - } + map_element2type(narg-4,arg+4); // read snapcoeff and snapparam files - read_files(coefffilename,paramfilename); + read_files(arg[2],arg[3]); if (!quadraticflag) ncoeff = ncoeffall - 1; @@ -455,25 +397,6 @@ void PairSNAP::coeff(int narg, char **arg) } } - // clear setflag since coeff() called once with I,J = * * - - int n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); - snaptr = new SNA(lmp, rfac0, twojmax, rmin0, switchflag, bzeroflag, chemflag, bnormflag, wselfallflag, nelements); @@ -571,8 +494,11 @@ void PairSNAP::read_files(char *coefffilename, char *paramfilename) "file: {}", e.what())); } - // set up element lists + // clean out old arrays and set up element lists + memory->destroy(radelem); + memory->destroy(wjelem); + memory->destroy(coeffelem); memory->create(radelem,nelements,"pair:radelem"); memory->create(wjelem,nelements,"pair:wjelem"); memory->create(coeffelem,nelements,ncoeffall,"pair:coeffelem"); diff --git a/src/SNAP/pair_snap.h b/src/SNAP/pair_snap.h index d60000da3a..ee596d2ba7 100644 --- a/src/SNAP/pair_snap.h +++ b/src/SNAP/pair_snap.h @@ -50,14 +50,11 @@ protected: void compute_bispectrum(); double rcutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements double *radelem; // element radii double *wjelem; // elements weights double **coeffelem; // element bispectrum coefficients double** beta; // betas for all atoms in list double** bispectrum; // bispectrum components for all atoms in list - int *map; // mapping from atom types to elements int twojmax, switchflag, bzeroflag, bnormflag; int chemflag, wselfallflag; int chunksize; diff --git a/src/USER-INTEL/pair_sw_intel.cpp b/src/USER-INTEL/pair_sw_intel.cpp index 984b2100a3..bc5c40a258 100644 --- a/src/USER-INTEL/pair_sw_intel.cpp +++ b/src/USER-INTEL/pair_sw_intel.cpp @@ -1204,7 +1204,7 @@ void PairSWIntel::pack_force_const(ForceConst &fc, fc.p2e[ii][jj].c5 = 0; fc.p2e[ii][jj].c6 = 0; } else { - int ijparam = elem2param[i][j][j]; + int ijparam = elem3param[i][j][j]; fc.p2[ii][jj].cutsq = params[ijparam].cutsq; fc.p2[ii][jj].cut = params[ijparam].cut; fc.p2[ii][jj].sigma_gamma = params[ijparam].sigma_gamma; @@ -1237,7 +1237,7 @@ void PairSWIntel::pack_force_const(ForceConst &fc, mytypes++; _onetype = ii * tp1 + jj; _onetype3 = ii * tp1 * tp1 + jj * tp1 + kk; - int ijkparam = elem2param[i][j][k]; + int ijkparam = elem3param[i][j][k]; fc.p3[ii][jj][kk].costheta = params[ijkparam].costheta; fc.p3[ii][jj][kk].lambda_epsilon = params[ijkparam].lambda_epsilon; fc.p3[ii][jj][kk].lambda_epsilon2 = params[ijkparam].lambda_epsilon2; diff --git a/src/USER-INTEL/pair_tersoff_intel.cpp b/src/USER-INTEL/pair_tersoff_intel.cpp index 4284309b74..eb3ce562fa 100644 --- a/src/USER-INTEL/pair_tersoff_intel.cpp +++ b/src/USER-INTEL/pair_tersoff_intel.cpp @@ -482,7 +482,7 @@ void PairTersoffIntel::pack_force_const(ForceConst &fc, fc.c_inner_loop[i][0][j].d2 = 1.0; fc.c_inner_loop[0][i][j].d2 = 1.0; for (int k = 1; k < tp1; k++) { - Param * param = ¶ms[elem2param[map[i]][map[j]][map[k]]]; + Param * param = ¶ms[elem3param[map[i]][map[j]][map[k]]]; fc.c_cutoff_inner[i][k][j].cutsq = static_cast(param->cutsq); fc.c_inner_loop[i][j][k].lam3 = static_cast(param->lam3); fc.c_inner_loop[i][j][k].bigr = static_cast(param->bigr); @@ -504,7 +504,7 @@ void PairTersoffIntel::pack_force_const(ForceConst &fc, fc.c_inner[i][j][k].powermint = static_cast(param->powermint); } - Param * param = ¶ms[elem2param[map[i]][map[j]][map[j]]]; + Param * param = ¶ms[elem3param[map[i]][map[j]][map[j]]]; fc.c_cutoff_outer[i][j].cutsq = static_cast(param->cutsq); fc.c_first_loop[i][j].bigr = static_cast(param->bigr); fc.c_first_loop[i][j].bigd = static_cast(param->bigd); diff --git a/src/USER-MEAMC/pair_meamc.cpp b/src/USER-MEAMC/pair_meamc.cpp index 29d81e9516..67ab3522ad 100644 --- a/src/USER-MEAMC/pair_meamc.cpp +++ b/src/USER-MEAMC/pair_meamc.cpp @@ -55,7 +55,7 @@ PairMEAMC::PairMEAMC(LAMMPS *lmp) : Pair(lmp) allocated = 0; - nelements = 0; + nlibelements = 0; meam_inst = new MEAM(memory); scale = nullptr; @@ -78,7 +78,6 @@ PairMEAMC::~PairMEAMC() memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(scale); - delete [] map; } } @@ -239,23 +238,23 @@ void PairMEAMC::coeff(int narg, char **arg) error->all(FLERR,"Incorrect args for pair coefficients"); // MEAM element names between 2 filenames - // nelements = # of MEAM elements + // nlibelements = # of MEAM elements // elements = list of unique element names - if (nelements) { - elements.clear(); + if (nlibelements) { + libelements.clear(); mass.clear(); } - nelements = paridx - 3; - if (nelements < 1) error->all(FLERR,"Incorrect args for pair coefficients"); - if (nelements > maxelt) + nlibelements = paridx - 3; + if (nlibelements < 1) error->all(FLERR,"Incorrect args for pair coefficients"); + if (nlibelements > maxelt) error->all(FLERR,fmt::format("Too many elements extracted from MEAM " "library (current limit: {}). Increase " "'maxelt' in meam.h and recompile.", maxelt)); - for (int i = 0; i < nelements; i++) { - elements.push_back(arg[i+3]); + for (int i = 0; i < nlibelements; i++) { + libelements.push_back(arg[i+3]); mass.push_back(0.0); } @@ -269,12 +268,12 @@ void PairMEAMC::coeff(int narg, char **arg) // read args that map atom types to MEAM elements // map[i] = which element the Ith atom type is, -1 if not mapped - for (int i = 4 + nelements; i < narg; i++) { - m = i - (4+nelements) + 1; + for (int i = 4 + nlibelements; i < narg; i++) { + m = i - (4+nlibelements) + 1; int j; - for (j = 0; j < nelements; j++) - if (elements[j] == arg[i]) break; - if (j < nelements) map[m] = j; + for (j = 0; j < nlibelements; j++) + if (libelements[j] == arg[i]) break; + if (j < nlibelements) map[m] = j; else if (strcmp(arg[i],"NULL") == 0) map[m] = -1; else error->all(FLERR,"Incorrect args for pair coefficients"); } @@ -359,25 +358,25 @@ void PairMEAMC::read_files(const std::string &globalfile, void PairMEAMC::read_global_meamc_file(const std::string &globalfile) { // allocate parameter arrays - std::vector lat(nelements); - std::vector ielement(nelements); - std::vector ibar(nelements); - std::vector z(nelements); - std::vector atwt(nelements); - std::vector alpha(nelements); - std::vector b0(nelements); - std::vector b1(nelements); - std::vector b2(nelements); - std::vector b3(nelements); - std::vector alat(nelements); - std::vector esub(nelements); - std::vector asub(nelements); - std::vector t0(nelements); - std::vector t1(nelements); - std::vector t2(nelements); - std::vector t3(nelements); - std::vector rozero(nelements); - std::vector found(nelements, false); + std::vector lat(nlibelements); + std::vector ielement(nlibelements); + std::vector ibar(nlibelements); + std::vector z(nlibelements); + std::vector atwt(nlibelements); + std::vector alpha(nlibelements); + std::vector b0(nlibelements); + std::vector b1(nlibelements); + std::vector b2(nlibelements); + std::vector b3(nlibelements); + std::vector alat(nlibelements); + std::vector esub(nlibelements); + std::vector asub(nlibelements); + std::vector t0(nlibelements); + std::vector t1(nlibelements); + std::vector t2(nlibelements); + std::vector t3(nlibelements); + std::vector rozero(nlibelements); + std::vector found(nlibelements, false); // open global meamf file on proc 0 @@ -401,9 +400,9 @@ void PairMEAMC::read_global_meamc_file(const std::string &globalfile) // skip if element name isn't in element list int index; - for (index = 0; index < nelements; index++) - if (elements[index] == element) break; - if (index == nelements) continue; + for (index = 0; index < nlibelements; index++) + if (libelements[index] == element) break; + if (index == nlibelements) continue; // skip if element already appeared (technically error in library file, but always ignored) @@ -452,47 +451,47 @@ void PairMEAMC::read_global_meamc_file(const std::string &globalfile) // error if didn't find all elements in file - if (nset != nelements) { + if (nset != nlibelements) { std::string msg = "Did not find all elements in MEAM library file, missing:"; - for (int i = 0; i < nelements; i++) + for (int i = 0; i < nlibelements; i++) if (!found[i]) { msg += " "; - msg += elements[i]; + msg += libelements[i]; } error->one(FLERR,msg); } } // distribute complete parameter sets - MPI_Bcast(lat.data(), nelements, MPI_INT, 0, world); - MPI_Bcast(ielement.data(), nelements, MPI_INT, 0, world); - MPI_Bcast(ibar.data(), nelements, MPI_INT, 0, world); - MPI_Bcast(z.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(atwt.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(alpha.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(b0.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(b1.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(b2.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(b3.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(alat.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(esub.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(asub.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(t0.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(t1.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(t2.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(t3.data(), nelements, MPI_DOUBLE, 0, world); - MPI_Bcast(rozero.data(), nelements, MPI_DOUBLE, 0, world); + MPI_Bcast(lat.data(), nlibelements, MPI_INT, 0, world); + MPI_Bcast(ielement.data(), nlibelements, MPI_INT, 0, world); + MPI_Bcast(ibar.data(), nlibelements, MPI_INT, 0, world); + MPI_Bcast(z.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(atwt.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(alpha.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(b0.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(b1.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(b2.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(b3.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(alat.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(esub.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(asub.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(t0.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(t1.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(t2.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(t3.data(), nlibelements, MPI_DOUBLE, 0, world); + MPI_Bcast(rozero.data(), nlibelements, MPI_DOUBLE, 0, world); // pass element parameters to MEAM package - meam_inst->meam_setup_global(nelements, lat.data(), ielement.data(), atwt.data(), + meam_inst->meam_setup_global(nlibelements, lat.data(), ielement.data(), atwt.data(), alpha.data(), b0.data(), b1.data(), b2.data(), b3.data(), alat.data(), esub.data(), asub.data(), t0.data(), t1.data(), t2.data(), t3.data(), rozero.data(), ibar.data()); // set element masses - for (int i = 0; i < nelements; i++) mass[i] = atwt[i]; + for (int i = 0; i < nlibelements; i++) mass[i] = atwt[i]; } /* ---------------------------------------------------------------------- */ diff --git a/src/USER-MEAMC/pair_meamc.h b/src/USER-MEAMC/pair_meamc.h index 6bf6923869..24625c4076 100644 --- a/src/USER-MEAMC/pair_meamc.h +++ b/src/USER-MEAMC/pair_meamc.h @@ -47,12 +47,11 @@ class PairMEAMC : public Pair { private: class MEAM *meam_inst; - double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - std::vector elements; // names of unique elements - std::vector mass; // mass of each element + double cutmax; // max cutoff for all elements + int nlibelements; // # of library elements + std::vector libelements; // names of library elements + std::vector mass; // mass of library element - int *map; // mapping from atom types (1-indexed) to elements (1-indexed) double **scale; // scaling factor for adapt void allocate(); diff --git a/src/USER-MISC/pair_agni.cpp b/src/USER-MISC/pair_agni.cpp index 7481ca35d4..7acaf90e4f 100644 --- a/src/USER-MISC/pair_agni.cpp +++ b/src/USER-MISC/pair_agni.cpp @@ -67,12 +67,7 @@ PairAGNI::PairAGNI(LAMMPS *lmp) : Pair(lmp) no_virial_fdotr_compute = 1; - nelements = 0; - elements = nullptr; - elem2param = nullptr; - nparams = 0; params = nullptr; - map = nullptr; cutmax = 0.0; } @@ -82,9 +77,6 @@ PairAGNI::PairAGNI(LAMMPS *lmp) : Pair(lmp) PairAGNI::~PairAGNI() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; if (params) { for (int i = 0; i < nparams; ++i) { memory->destroy(params[i].eta); @@ -94,12 +86,11 @@ PairAGNI::~PairAGNI() memory->destroy(params); params = nullptr; } - memory->destroy(elem2param); + memory->destroy(elem1param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; } } @@ -135,7 +126,7 @@ void PairAGNI::compute(int eflag, int vflag) ztmp = x[i][2]; fxtmp = fytmp = fztmp = 0.0; - const Param &iparam = params[elem2param[itype]]; + const Param &iparam = params[elem1param[itype]]; Vx = new double[iparam.numeta]; Vy = new double[iparam.numeta]; Vz = new double[iparam.numeta]; @@ -238,46 +229,10 @@ void PairAGNI::settings(int narg, char ** /* arg */) void PairAGNI::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); + map_element2type(narg-3,arg+3); - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } if (nelements != 1) error->all(FLERR,"Cannot handle multi-element systems with this potential"); @@ -285,25 +240,6 @@ void PairAGNI::coeff(int narg, char **arg) read_file(arg[2]); setup_params(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -466,10 +402,10 @@ void PairAGNI::setup_params() int i,m,n; double rtmp; - // set elem2param for all elements + // set elem1param for all elements - memory->destroy(elem2param); - memory->create(elem2param,nelements,"pair:elem2param"); + memory->destroy(elem1param); + memory->create(elem1param,nelements,"pair:elem1param"); for (i = 0; i < nelements; i++) { n = -1; @@ -480,7 +416,7 @@ void PairAGNI::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i] = n; + elem1param[i] = n; } // compute parameter values derived from inputs diff --git a/src/USER-MISC/pair_agni.h b/src/USER-MISC/pair_agni.h index 6fba506d04..0a33c11b95 100644 --- a/src/USER-MISC/pair_agni.h +++ b/src/USER-MISC/pair_agni.h @@ -45,11 +45,6 @@ class PairAGNI : public Pair { protected: double cutmax; // max cutoff for all elements - int nelements; // # of unique atom type labels - char **elements; // names of unique elements - int *elem2param; // mapping from element pairs to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets int atomic_feature_version; // version of fingerprint Param *params; // parameter set for an I-J interaction virtual void allocate(); diff --git a/src/USER-MISC/pair_drip.cpp b/src/USER-MISC/pair_drip.cpp index 45b49ee293..0f571dd41e 100644 --- a/src/USER-MISC/pair_drip.cpp +++ b/src/USER-MISC/pair_drip.cpp @@ -22,17 +22,17 @@ #include "pair_drip.h" -#include - -#include #include "atom.h" #include "comm.h" +#include "error.h" #include "force.h" -#include "neighbor.h" +#include "memory.h" #include "neigh_list.h" #include "neigh_request.h" -#include "memory.h" -#include "error.h" +#include "neighbor.h" + +#include +#include using namespace LAMMPS_NS; @@ -51,10 +51,6 @@ PairDRIP::PairDRIP(LAMMPS *lmp) : Pair(lmp) params = nullptr; nearest3neigh = nullptr; - elements = nullptr; - elem2param = nullptr; - map = nullptr; - nelements = 0; cutmax = 0.0; } @@ -65,14 +61,8 @@ PairDRIP::~PairDRIP() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; } - if (elements != nullptr) { - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - elements = nullptr; - } memory->destroy(params); memory->destroy(elem2param); memory->destroy(nearest3neigh); @@ -127,64 +117,10 @@ void PairDRIP::settings(int narg, char ** /* arg */) void PairDRIP::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } - + map_element2type(narg-3,arg+3); read_file(arg[2]); - - - // clear setflag since coeff() called once with I,J = * * - n = atom->ntypes; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - setflag[i][j] = 0; - - int count = 0; - for (i = 1; i <= n; i++) - for (j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } diff --git a/src/USER-MISC/pair_drip.h b/src/USER-MISC/pair_drip.h index 3ea6c735a6..59dac076c8 100644 --- a/src/USER-MISC/pair_drip.h +++ b/src/USER-MISC/pair_drip.h @@ -58,10 +58,6 @@ protected: }; Param *params; // parameter set for I-J interactions int **nearest3neigh; // nearest 3 neighbors of atoms - char **elements; // names of unique elements - int **elem2param; // mapping from element pairs to parameters - int *map; // mapping from atom types to elements - int nelements; // # of unique elements double cutmax; // max cutoff for all species void read_file(char *); diff --git a/src/USER-MISC/pair_edip.cpp b/src/USER-MISC/pair_edip.cpp index 12390ba69d..88b8728c38 100644 --- a/src/USER-MISC/pair_edip.cpp +++ b/src/USER-MISC/pair_edip.cpp @@ -23,18 +23,18 @@ #include "pair_edip.h" -#include -#include - -#include #include "atom.h" -#include "neighbor.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "memory.h" #include "neigh_list.h" #include "neigh_request.h" -#include "force.h" -#include "comm.h" -#include "memory.h" -#include "error.h" +#include "neighbor.h" + +#include +#include +#include using namespace LAMMPS_NS; @@ -64,11 +64,7 @@ PairEDIP::PairEDIP(LAMMPS *lmp) : manybody_flag = 1; centroidstressflag = CENTROID_NOTAVAIL; - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; } /* ---------------------------------------------------------------------- @@ -77,16 +73,12 @@ PairEDIP::PairEDIP(LAMMPS *lmp) : PairEDIP::~PairEDIP() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; deallocateGrids(); deallocatePreLoops(); @@ -198,7 +190,7 @@ void PairEDIP::compute(int eflag, int vflag) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; r_ij = sqrt(r_ij); @@ -313,7 +305,7 @@ void PairEDIP::compute(int eflag, int vflag) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; r_ij = sqrt(r_ij); @@ -367,7 +359,7 @@ void PairEDIP::compute(int eflag, int vflag) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; dr_ik[0] = x[k][0] - xtmp; dr_ik[1] = x[k][1] - ytmp; @@ -766,47 +758,9 @@ void PairEDIP::initGrids(void) void PairEDIP::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } - + map_element2type(narg-3,arg+3); if (nelements != 1) error->all(FLERR,"Pair style edip only supports single element potentials"); @@ -815,25 +769,6 @@ void PairEDIP::coeff(int narg, char **arg) read_file(arg[2]); setup_params(); - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); - // allocate tables and internal structures allocatePreLoops(); @@ -1015,12 +950,12 @@ void PairEDIP::setup_params() int i,j,k,m,n; double rtmp; - // set elem2param for all triplet combinations + // set elem3param for all triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -1034,7 +969,7 @@ void PairEDIP::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // set cutoff square diff --git a/src/USER-MISC/pair_edip.h b/src/USER-MISC/pair_edip.h index 6c4a37d795..006c124229 100644 --- a/src/USER-MISC/pair_edip.h +++ b/src/USER-MISC/pair_edip.h @@ -87,12 +87,6 @@ class PairEDIP : public Pair { double u4; double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets Param *params; // parameter set for an I-J-K interaction void allocate(); diff --git a/src/USER-MISC/pair_edip_multi.cpp b/src/USER-MISC/pair_edip_multi.cpp index c0969831b9..4db52da11a 100644 --- a/src/USER-MISC/pair_edip_multi.cpp +++ b/src/USER-MISC/pair_edip_multi.cpp @@ -82,11 +82,7 @@ PairEDIPMulti::PairEDIPMulti(LAMMPS *lmp) : Pair(lmp), preForceCoord(nullptr) manybody_flag = 1; centroidstressflag = CENTROID_NOTAVAIL; - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; } /* ---------------------------------------------------------------------- @@ -95,16 +91,12 @@ PairEDIPMulti::PairEDIPMulti(LAMMPS *lmp) : Pair(lmp), preForceCoord(nullptr) PairEDIPMulti::~PairEDIPMulti() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; } deallocatePreLoops(); } @@ -173,7 +165,7 @@ void PairEDIPMulti::compute(int eflag, int vflag) r_ij = delx * delx + dely * dely + delz * delz; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; r_ij = sqrt(r_ij); @@ -214,7 +206,7 @@ void PairEDIPMulti::compute(int eflag, int vflag) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; r_ij = sqrt(r_ij); @@ -246,8 +238,8 @@ void PairEDIPMulti::compute(int eflag, int vflag) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = x[k][0] - xtmp; dr_ik[1] = x[k][1] - ytmp; @@ -537,71 +529,15 @@ void PairEDIPMulti::settings(int narg, char **/*arg*/) void PairEDIPMulti::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup(); - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); - // (re-)allocate tables and internal structures deallocatePreLoops(); @@ -784,12 +720,12 @@ void PairEDIPMulti::setup() int i,j,k,m,n; double rtmp; - // set elem2param for all triplet combinations + // set elem3param for all triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -803,7 +739,7 @@ void PairEDIPMulti::setup() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // set cutoff square diff --git a/src/USER-MISC/pair_edip_multi.h b/src/USER-MISC/pair_edip_multi.h index cf1d56945f..2aba064aa9 100644 --- a/src/USER-MISC/pair_edip_multi.h +++ b/src/USER-MISC/pair_edip_multi.h @@ -54,12 +54,6 @@ class PairEDIPMulti : public Pair { double *preForceCoord; double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets Param *params; // parameter set for an I-J-K interaction void allocate(); diff --git a/src/USER-MISC/pair_extep.cpp b/src/USER-MISC/pair_extep.cpp index ea4a8031a1..c64c7474cd 100644 --- a/src/USER-MISC/pair_extep.cpp +++ b/src/USER-MISC/pair_extep.cpp @@ -52,18 +52,13 @@ PairExTeP::PairExTeP(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; ghostneigh = 1; - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; maxlocal = 0; SR_numneigh = nullptr; SR_firstneigh = nullptr; ipage = nullptr; pgsize = oneatom = 0; - map = nullptr; Nt = nullptr; Nd = nullptr; @@ -75,11 +70,8 @@ PairExTeP::PairExTeP(LAMMPS *lmp) : Pair(lmp) PairExTeP::~PairExTeP() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); memory->destroy(SR_numneigh); memory->sfree(SR_firstneigh); @@ -91,7 +83,6 @@ PairExTeP::~PairExTeP() memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cutghost); - delete [] map; } } @@ -159,7 +150,7 @@ void PairExTeP::SR_neigh() rsq = delx*delx + dely*dely + delz*delz; jtype=map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq < params[iparam_ij].cutsq) { neighptr[n++] = j; @@ -246,7 +237,7 @@ void PairExTeP::compute(int eflag, int vflag) delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq > params[iparam_ij].cutsq) continue; repulsive(¶ms[iparam_ij],rsq,fpair,eflag,evdwl); @@ -270,7 +261,7 @@ void PairExTeP::compute(int eflag, int vflag) j &= NEIGHMASK; jtag = tag[j]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; delr1[0] = x[j][0] - xtmp; delr1[1] = x[j][1] - ytmp; @@ -337,7 +328,7 @@ void PairExTeP::compute(int eflag, int vflag) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -352,7 +343,7 @@ void PairExTeP::compute(int eflag, int vflag) /* F_IJ (2) */ // compute force components due to spline derivatives // uses only the part with FXY_x (FXY_y is done when i and j are inversed) - int iparam_ik = elem2param[itype][ktype][0]; + int iparam_ik = elem3param[itype][ktype][0]; double fc_ik_d = ters_fc_d(r2,¶ms[iparam_ik]); double fc_prefac_ik_0 = 1.0 * fc_ik_d * fa / r2; double fc_prefac_ik = dFc_dNtij * fc_prefac_ik_0; @@ -396,7 +387,7 @@ void PairExTeP::compute(int eflag, int vflag) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -455,71 +446,15 @@ void PairExTeP::settings(int narg, char **/*arg*/) void PairExTeP::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); spline_init(); setup(); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -818,12 +753,12 @@ void PairExTeP::setup() { int i,j,k,m,n; - // set elem2param for all element triplet combinations + // set elem3param for all element triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -837,7 +772,7 @@ void PairExTeP::setup() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // compute parameter values derived from inputs diff --git a/src/USER-MISC/pair_extep.h b/src/USER-MISC/pair_extep.h index 599147c46e..08ee6d9a82 100644 --- a/src/USER-MISC/pair_extep.h +++ b/src/USER-MISC/pair_extep.h @@ -48,30 +48,24 @@ class PairExTeP : public Pair { double c1,c2,c3,c4; int ielement,jelement,kelement; int powermint; - double Z_i,Z_j; // added for ExTePZBL + double Z_i,Z_j; // added for ExTePZBL double ZBLcut,ZBLexpscale; - double c5,ca1,ca4; // added for ExTePMOD + double c5,ca1,ca4; // added for ExTePMOD double powern_del; }; Param *params; // parameter set for an I-J-K interaction - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets - int maxlocal; // size of numneigh, firstneigh arrays - int maxpage; // # of pages currently allocated - int pgsize; // size of neighbor page - int oneatom; // max # of neighbors for one atom - MyPage *ipage; // neighbor list pages - int *SR_numneigh; // # of pair neighbors for each atom - int **SR_firstneigh; // ptr to 1st neighbor of each atom + int maxlocal; // size of numneigh, firstneigh arrays + int maxpage; // # of pages currently allocated + int pgsize; // size of neighbor page + int oneatom; // max # of neighbors for one atom + MyPage *ipage; // neighbor list pages + int *SR_numneigh; // # of pair neighbors for each atom + int **SR_firstneigh; // ptr to 1st neighbor of each atom - double *Nt, *Nd; // sum of cutoff fns ( f_C ) with SR neighs + double *Nt, *Nd; // sum of cutoff fns ( f_C ) with SR neighs void allocate(); void spline_init(); diff --git a/src/USER-MISC/pair_ilp_graphene_hbn.cpp b/src/USER-MISC/pair_ilp_graphene_hbn.cpp index 982e67d4c1..2870d175c4 100644 --- a/src/USER-MISC/pair_ilp_graphene_hbn.cpp +++ b/src/USER-MISC/pair_ilp_graphene_hbn.cpp @@ -22,20 +22,19 @@ #include "pair_ilp_graphene_hbn.h" -#include - -#include #include "atom.h" +#include "citeme.h" #include "comm.h" +#include "error.h" #include "force.h" -#include "neighbor.h" +#include "memory.h" +#include "my_page.h" #include "neigh_list.h" #include "neigh_request.h" -#include "my_page.h" -#include "memory.h" -#include "error.h" -#include "citeme.h" +#include "neighbor.h" +#include +#include using namespace LAMMPS_NS; @@ -66,13 +65,8 @@ PairILPGrapheneHBN::PairILPGrapheneHBN(LAMMPS *lmp) : Pair(lmp) pvector = new double[nextra]; // initialize element to parameter maps - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; cutILPsq = nullptr; - map = nullptr; nmax = 0; maxlocal = 0; @@ -110,13 +104,8 @@ PairILPGrapheneHBN::~PairILPGrapheneHBN() memory->destroy(offset); } - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - memory->destroy(params); memory->destroy(elem2param); memory->destroy(cutILPsq); - if (allocated) delete [] map; } /* ---------------------------------------------------------------------- @@ -168,68 +157,10 @@ void PairILPGrapheneHBN::settings(int narg, char **arg) void PairILPGrapheneHBN::coeff(int narg, char **arg) { - int i,j,n; - - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } - - + map_element2type(narg-3,arg+3); read_file(arg[2]); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - cut[i][j] = cut_global; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } diff --git a/src/USER-MISC/pair_ilp_graphene_hbn.h b/src/USER-MISC/pair_ilp_graphene_hbn.h index aadb792cad..4f5e187782 100644 --- a/src/USER-MISC/pair_ilp_graphene_hbn.h +++ b/src/USER-MISC/pair_ilp_graphene_hbn.h @@ -56,12 +56,6 @@ class PairILPGrapheneHBN : public Pair { int ielement,jelement; }; Param *params; // parameter set for I-J interactions - char **elements; // names of unique elements - int **elem2param; // mapping from element pairs to parameters - int *map; // mapping from atom types to elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets int nmax; // max # of atoms double cut_global; diff --git a/src/USER-MISC/pair_kolmogorov_crespi_full.cpp b/src/USER-MISC/pair_kolmogorov_crespi_full.cpp index c5fa33bbac..45ad36dd7c 100644 --- a/src/USER-MISC/pair_kolmogorov_crespi_full.cpp +++ b/src/USER-MISC/pair_kolmogorov_crespi_full.cpp @@ -21,21 +21,20 @@ ------------------------------------------------------------------------- */ #include "pair_kolmogorov_crespi_full.h" -#include - -#include #include "atom.h" +#include "citeme.h" #include "comm.h" +#include "error.h" #include "force.h" -#include "neighbor.h" +#include "memory.h" +#include "my_page.h" #include "neigh_list.h" #include "neigh_request.h" -#include "my_page.h" -#include "memory.h" -#include "error.h" -#include "citeme.h" +#include "neighbor.h" +#include +#include using namespace LAMMPS_NS; @@ -66,13 +65,8 @@ PairKolmogorovCrespiFull::PairKolmogorovCrespiFull(LAMMPS *lmp) : Pair(lmp) pvector = new double[nextra]; // initialize element to parameter maps - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; cutKCsq = nullptr; - map = nullptr; nmax = 0; maxlocal = 0; @@ -111,13 +105,9 @@ PairKolmogorovCrespiFull::~PairKolmogorovCrespiFull() memory->destroy(offset); } - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); memory->destroy(elem2param); memory->destroy(cutKCsq); - if (allocated) delete [] map; } /* ---------------------------------------------------------------------- @@ -169,68 +159,9 @@ void PairKolmogorovCrespiFull::settings(int narg, char **arg) void PairKolmogorovCrespiFull::coeff(int narg, char **arg) { - int i,j,n; - - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } - - + map_element2type(narg-3,arg+3); read_file(arg[2]); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - cut[i][j] = cut_global; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } diff --git a/src/USER-MISC/pair_kolmogorov_crespi_full.h b/src/USER-MISC/pair_kolmogorov_crespi_full.h index f7d9237be4..dd2721d37e 100644 --- a/src/USER-MISC/pair_kolmogorov_crespi_full.h +++ b/src/USER-MISC/pair_kolmogorov_crespi_full.h @@ -57,12 +57,6 @@ class PairKolmogorovCrespiFull : public Pair { int ielement,jelement; }; Param *params; // parameter set for I-J interactions - char **elements; // names of unique elements - int **elem2param; // mapping from element pairs to parameters - int *map; // mapping from atom types to elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets int nmax; // max # of atoms double cut_global; diff --git a/src/USER-MISC/pair_kolmogorov_crespi_z.cpp b/src/USER-MISC/pair_kolmogorov_crespi_z.cpp index 1bea688be5..4b5de2314e 100644 --- a/src/USER-MISC/pair_kolmogorov_crespi_z.cpp +++ b/src/USER-MISC/pair_kolmogorov_crespi_z.cpp @@ -23,16 +23,15 @@ #include "pair_kolmogorov_crespi_z.h" -#include - -#include #include "atom.h" #include "comm.h" -#include "force.h" -#include "neigh_list.h" -#include "memory.h" #include "error.h" +#include "force.h" +#include "memory.h" +#include "neigh_list.h" +#include +#include using namespace LAMMPS_NS; @@ -69,12 +68,8 @@ PairKolmogorovCrespiZ::~PairKolmogorovCrespiZ() memory->destroy(offset); } - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); memory->destroy(elem2param); - if (allocated) delete [] map; } /* ---------------------------------------------------------------------- */ @@ -221,45 +216,13 @@ void PairKolmogorovCrespiZ::settings(int narg, char **arg) void PairKolmogorovCrespiZ::coeff(int narg, char **arg) { - int i,j,n; - - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; utils::bounds(FLERR,arg[0],1,atom->ntypes,ilo,ihi,error); utils::bounds(FLERR,arg[1],1,atom->ntypes,jlo,jhi,error); - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } - + map_element2type(narg-3,arg+3,false); read_file(arg[2]); // set setflag only for i,j pairs where both are mapped to elements diff --git a/src/USER-MISC/pair_kolmogorov_crespi_z.h b/src/USER-MISC/pair_kolmogorov_crespi_z.h index 1a90fdfa0b..7d242d67fd 100644 --- a/src/USER-MISC/pair_kolmogorov_crespi_z.h +++ b/src/USER-MISC/pair_kolmogorov_crespi_z.h @@ -43,12 +43,6 @@ class PairKolmogorovCrespiZ : public Pair { int ielement,jelement; }; Param *params; // parameter set for I-J interactions - char **elements; // names of unique elements - int **elem2param; // mapping from element pairs to parameters - int *map; // mapping from atom types to elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets double cut_global; double **cut; diff --git a/src/USER-MISC/pair_lebedeva_z.cpp b/src/USER-MISC/pair_lebedeva_z.cpp index a600f5b761..afd7209c6b 100644 --- a/src/USER-MISC/pair_lebedeva_z.cpp +++ b/src/USER-MISC/pair_lebedeva_z.cpp @@ -24,16 +24,15 @@ #include "pair_lebedeva_z.h" -#include - -#include #include "atom.h" #include "comm.h" -#include "force.h" -#include "neigh_list.h" -#include "memory.h" #include "error.h" +#include "force.h" +#include "memory.h" +#include "neigh_list.h" +#include +#include using namespace LAMMPS_NS; @@ -48,12 +47,7 @@ PairLebedevaZ::PairLebedevaZ(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; // initialize element to parameter maps - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; - map = nullptr; // always compute energy offset offset_flag = 1; @@ -70,12 +64,8 @@ PairLebedevaZ::~PairLebedevaZ() memory->destroy(offset); } - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); memory->destroy(elem2param); - if (allocated) delete [] map; } /* ---------------------------------------------------------------------- */ @@ -217,45 +207,13 @@ void PairLebedevaZ::settings(int narg, char **arg) void PairLebedevaZ::coeff(int narg, char **arg) { - int i,j,n; - - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; utils::bounds(FLERR,arg[0],1,atom->ntypes,ilo,ihi,error); utils::bounds(FLERR,arg[1],1,atom->ntypes,jlo,jhi,error); - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } - + map_element2type(narg-3,arg+3,false); read_file(arg[2]); // set setflag only for i,j pairs where both are mapped to elements diff --git a/src/USER-MISC/pair_lebedeva_z.h b/src/USER-MISC/pair_lebedeva_z.h index e221087a0a..57cf445889 100644 --- a/src/USER-MISC/pair_lebedeva_z.h +++ b/src/USER-MISC/pair_lebedeva_z.h @@ -43,12 +43,6 @@ class PairLebedevaZ : public Pair { int ielement,jelement; }; Param *params; // parameter set for I-J interactions - char **elements; // names of unique elements - int **elem2param; // mapping from element pairs to parameters - int *map; // mapping from atom types to elements - int nelements; // # of unique elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets double cut_global; double **cut; diff --git a/src/USER-MISC/pair_meam_spline.cpp b/src/USER-MISC/pair_meam_spline.cpp index a6bf602c70..e956d96cf2 100644 --- a/src/USER-MISC/pair_meam_spline.cpp +++ b/src/USER-MISC/pair_meam_spline.cpp @@ -32,18 +32,18 @@ ------------------------------------------------------------------------- */ #include "pair_meam_spline.h" -#include -#include #include "atom.h" -#include "force.h" #include "comm.h" -#include "neighbor.h" +#include "error.h" +#include "force.h" +#include "memory.h" #include "neigh_list.h" #include "neigh_request.h" -#include "memory.h" -#include "error.h" +#include "neighbor.h" +#include +#include using namespace LAMMPS_NS; @@ -55,10 +55,6 @@ PairMEAMSpline::PairMEAMSpline(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; - nelements = 0; - elements = nullptr; - map = nullptr; - Uprime_values = nullptr; nmax = 0; maxNeighbors = 0; @@ -80,10 +76,6 @@ PairMEAMSpline::PairMEAMSpline(LAMMPS *lmp) : Pair(lmp) PairMEAMSpline::~PairMEAMSpline() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - delete[] twoBodyInfo; memory->destroy(Uprime_values); @@ -98,8 +90,6 @@ PairMEAMSpline::~PairMEAMSpline() delete[] gs; delete[] zero_atom_energies; - - delete [] map; } } @@ -389,11 +379,6 @@ void PairMEAMSpline::coeff(int narg, char **arg) if (narg != 3 + atom->ntypes) error->all(FLERR,"Incorrect args for pair coefficients"); - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - // read potential file: also sets the number of elements. read_file(arg[2]); diff --git a/src/USER-MISC/pair_meam_spline.h b/src/USER-MISC/pair_meam_spline.h index d1dc5064f5..b20454f18d 100644 --- a/src/USER-MISC/pair_meam_spline.h +++ b/src/USER-MISC/pair_meam_spline.h @@ -67,10 +67,6 @@ public: double memory_usage(); protected: - char **elements; // names of unique elements - int *map; // mapping from atom types to elements - int nelements; // # of unique elements - class SplineFunction { public: /// Default constructor. diff --git a/src/USER-MISC/pair_meam_sw_spline.cpp b/src/USER-MISC/pair_meam_sw_spline.cpp index 58c0f75546..ff7b89fbe7 100644 --- a/src/USER-MISC/pair_meam_sw_spline.cpp +++ b/src/USER-MISC/pair_meam_sw_spline.cpp @@ -24,18 +24,18 @@ ------------------------------------------------------------------------- */ #include "pair_meam_sw_spline.h" -#include -#include #include "atom.h" -#include "force.h" #include "comm.h" -#include "neighbor.h" +#include "error.h" +#include "force.h" +#include "memory.h" #include "neigh_list.h" #include "neigh_request.h" -#include "memory.h" -#include "error.h" +#include "neighbor.h" +#include +#include using namespace LAMMPS_NS; @@ -49,9 +49,6 @@ PairMEAMSWSpline::PairMEAMSWSpline(LAMMPS *lmp) : Pair(lmp) manybody_flag = 1; centroidstressflag = CENTROID_NOTAVAIL; - nelements = 0; - elements = nullptr; - Uprime_values = nullptr; //ESWprime_values = nullptr; nmax = 0; @@ -66,10 +63,6 @@ PairMEAMSWSpline::PairMEAMSWSpline(LAMMPS *lmp) : Pair(lmp) PairMEAMSWSpline::~PairMEAMSWSpline() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - delete[] twoBodyInfo; memory->destroy(Uprime_values); //memory->destroy(ESWprime_values); @@ -77,7 +70,6 @@ PairMEAMSWSpline::~PairMEAMSWSpline() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; } } @@ -381,46 +373,9 @@ void PairMEAMSWSpline::settings(int narg, char **/*arg*/) void PairMEAMSWSpline::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // for now, only allow single element @@ -431,25 +386,6 @@ void PairMEAMSWSpline::coeff(int narg, char **arg) // read potential file read_file(arg[2]); - - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- diff --git a/src/USER-MISC/pair_meam_sw_spline.h b/src/USER-MISC/pair_meam_sw_spline.h index 7b40d123ed..ecf56c7931 100644 --- a/src/USER-MISC/pair_meam_sw_spline.h +++ b/src/USER-MISC/pair_meam_sw_spline.h @@ -54,9 +54,6 @@ public: double memory_usage(); protected: - char **elements; // names of unique elements - int *map; // mapping from atom types to elements - int nelements; // # of unique elements class SplineFunction { public: diff --git a/src/USER-MISC/pair_tersoff_table.cpp b/src/USER-MISC/pair_tersoff_table.cpp index 0d5bbc1147..ed05961fa7 100644 --- a/src/USER-MISC/pair_tersoff_table.cpp +++ b/src/USER-MISC/pair_tersoff_table.cpp @@ -22,21 +22,19 @@ #include "pair_tersoff_table.h" -#include - -#include #include "atom.h" -#include "neighbor.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "memory.h" #include "neigh_list.h" #include "neigh_request.h" -#include "force.h" -#include "comm.h" -#include "memory.h" - -#include "tokenizer.h" +#include "neighbor.h" #include "potential_file_reader.h" +#include "tokenizer.h" -#include "error.h" +#include +#include using namespace LAMMPS_NS; @@ -64,11 +62,7 @@ PairTersoffTable::PairTersoffTable(LAMMPS *lmp) : Pair(lmp) centroidstressflag = CENTROID_NOTAVAIL; unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); - nelements = 0; - elements = nullptr; - nparams = maxparam = 0; params = nullptr; - elem2param = nullptr; allocated = 0; preGtetaFunction = preGtetaFunctionDerived = nullptr; @@ -88,17 +82,12 @@ PairTersoffTable::PairTersoffTable(LAMMPS *lmp) : Pair(lmp) PairTersoffTable::~PairTersoffTable() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; memory->destroy(params); - memory->destroy(elem2param); + memory->destroy(elem3param); if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; - } deallocateGrids(); deallocatePreLoops(); @@ -177,7 +166,7 @@ void PairTersoffTable::compute(int eflag, int vflag) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; @@ -208,8 +197,8 @@ void PairTersoffTable::compute(int eflag, int vflag) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k][0]; dr_ik[1] = ytmp -x[k][1]; @@ -264,7 +253,7 @@ void PairTersoffTable::compute(int eflag, int vflag) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; @@ -308,8 +297,8 @@ void PairTersoffTable::compute(int eflag, int vflag) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k][0]; dr_ik[1] = ytmp -x[k][1]; @@ -333,8 +322,8 @@ void PairTersoffTable::compute(int eflag, int vflag) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k][0]; dr_ik[1] = ytmp -x[k][1]; @@ -392,8 +381,8 @@ void PairTersoffTable::compute(int eflag, int vflag) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k][0]; dr_ik[1] = ytmp -x[k][1]; @@ -457,8 +446,8 @@ void PairTersoffTable::compute(int eflag, int vflag) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k][0]; dr_ik[1] = ytmp -x[k][1]; @@ -608,7 +597,7 @@ void PairTersoffTable::allocateGrids(void) r = -1.0; deltaArgumentGtetaFunction = 1.0 / GRIDDENSITY_GTETA; - int iparam = elem2param[i][i][i]; + int iparam = elem3param[i][i][i]; double c = params[iparam].c; double d = params[iparam].d; double h = params[iparam].h; @@ -628,7 +617,7 @@ void PairTersoffTable::allocateGrids(void) for (i=0; intypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - // clear setflag since coeff() called once with I,J = * * - - n = atom->ntypes; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); - // allocate tables and internal structures + allocatePreLoops(); allocateGrids(); } @@ -966,12 +900,12 @@ void PairTersoffTable::setup_params() { int i,j,k,m,n; - // set elem2param for all triplet combinations + // set elem3param for all triplet combinations // must be a single exact match to lines read from file // do not allow for ACB in place of ABC - memory->destroy(elem2param); - memory->create(elem2param,nelements,nelements,nelements,"pair:elem2param"); + memory->destroy(elem3param); + memory->create(elem3param,nelements,nelements,nelements,"pair:elem3param"); for (i = 0; i < nelements; i++) for (j = 0; j < nelements; j++) @@ -985,7 +919,7 @@ void PairTersoffTable::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i][j][k] = n; + elem3param[i][j][k] = n; } // set cutoff square diff --git a/src/USER-MISC/pair_tersoff_table.h b/src/USER-MISC/pair_tersoff_table.h index d63a5be5a6..84e6f6fe50 100644 --- a/src/USER-MISC/pair_tersoff_table.h +++ b/src/USER-MISC/pair_tersoff_table.h @@ -59,12 +59,6 @@ class PairTersoffTable : public Pair { double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements - int ***elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets Param *params; // parameter set for an I-J-K interaction void allocate(); diff --git a/src/USER-OMP/pair_agni_omp.cpp b/src/USER-OMP/pair_agni_omp.cpp index 02a6126e03..258c833cdf 100644 --- a/src/USER-OMP/pair_agni_omp.cpp +++ b/src/USER-OMP/pair_agni_omp.cpp @@ -101,7 +101,7 @@ void PairAGNIOMP::eval(int iifrom, int iito, ThrData * const thr) ztmp = x[i].z; fxtmp = fytmp = fztmp = 0.0; - const Param &iparam = params[elem2param[itype]]; + const Param &iparam = params[elem1param[itype]]; Vx = new double[iparam.numeta]; Vy = new double[iparam.numeta]; Vz = new double[iparam.numeta]; diff --git a/src/USER-OMP/pair_comb_omp.cpp b/src/USER-OMP/pair_comb_omp.cpp index cfde8ff905..52c8855738 100644 --- a/src/USER-OMP/pair_comb_omp.cpp +++ b/src/USER-OMP/pair_comb_omp.cpp @@ -139,7 +139,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) iq = q[i]; NCo[i] = 0; nj = 0; - iparam_i = elem2param[itype][itype][itype]; + iparam_i = elem3param[itype][itype][itype]; // self energy, only on i atom @@ -180,7 +180,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) delz = ztmp - x[j][2]; rsq = delx*delx + dely*dely + delz*delz; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; // long range q-dependent @@ -242,7 +242,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) for (jj = 0; jj < sht_jnum; jj++) { j = sht_jlist[jj]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (params[iparam_ij].hfocor > 0.0) { delr1[0] = x[j][0] - xtmp; @@ -264,7 +264,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) j = sht_jlist[jj]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; // this Qj for q-dependent BSi @@ -288,7 +288,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) k = sht_jlist[kk]; if (j == k) continue; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -332,7 +332,7 @@ void PairCombOMP::eval(int iifrom, int iito, ThrData * const thr) k = sht_jlist[kk]; if (j == k) continue; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k][0] - xtmp; delr2[1] = x[k][1] - ytmp; @@ -434,7 +434,7 @@ double PairCombOMP::yasu_char(double *qf_fix, int &igroup) const double ytmp = x[i][1]; const double ztmp = x[i][2]; const double iq = q[i]; - const int iparam_i = elem2param[itype][itype][itype]; + const int iparam_i = elem3param[itype][itype][itype]; // charge force from self energy @@ -467,7 +467,7 @@ double PairCombOMP::yasu_char(double *qf_fix, int &igroup) delr1[2] = x[j][2] - ztmp; double rsq1 = dot3(delr1,delr1); - const int iparam_ij = elem2param[itype][jtype][jtype]; + const int iparam_ij = elem3param[itype][jtype][jtype]; // long range q-dependent @@ -505,7 +505,7 @@ double PairCombOMP::yasu_char(double *qf_fix, int &igroup) delr1[2] = x[j][2] - ztmp; double rsq1 = dot3(delr1,delr1); - const int iparam_ij = elem2param[itype][jtype][jtype]; + const int iparam_ij = elem3param[itype][jtype][jtype]; if (rsq1 > params[iparam_ij].cutsq) continue; nj ++; diff --git a/src/USER-OMP/pair_edip_omp.cpp b/src/USER-OMP/pair_edip_omp.cpp index 106d038743..b2e8708305 100644 --- a/src/USER-OMP/pair_edip_omp.cpp +++ b/src/USER-OMP/pair_edip_omp.cpp @@ -184,7 +184,7 @@ void PairEDIPOMP::eval(int iifrom, int iito, ThrData * const thr) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; r_ij = sqrt(r_ij); @@ -299,7 +299,7 @@ void PairEDIPOMP::eval(int iifrom, int iito, ThrData * const thr) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; r_ij = sqrt(r_ij); @@ -353,7 +353,7 @@ void PairEDIPOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; dr_ik[0] = x[k].x - xtmp; dr_ik[1] = x[k].y - ytmp; diff --git a/src/USER-OMP/pair_sw_omp.cpp b/src/USER-OMP/pair_sw_omp.cpp index 92d0d0c15a..28e450f517 100644 --- a/src/USER-OMP/pair_sw_omp.cpp +++ b/src/USER-OMP/pair_sw_omp.cpp @@ -121,7 +121,7 @@ void PairSWOMP::eval(int iifrom, int iito, ThrData * const thr) rsq = delx*delx + dely*dely + delz*delz; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (rsq >= params[ijparam].cutsq) { continue; } else { @@ -161,7 +161,7 @@ void PairSWOMP::eval(int iifrom, int iito, ThrData * const thr) for (jj = 0; jj < jnumm1; jj++) { j = neighshort_thr[jj]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j].x - xtmp; delr1[1] = x[j].y - ytmp; delr1[2] = x[j].z - ztmp; @@ -173,8 +173,8 @@ void PairSWOMP::eval(int iifrom, int iito, ThrData * const thr) for (kk = jj+1; kk < numshort; kk++) { k = neighshort_thr[kk]; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; diff --git a/src/USER-OMP/pair_tersoff_mod_c_omp.cpp b/src/USER-OMP/pair_tersoff_mod_c_omp.cpp index c6947bbde7..8f255ee1ba 100644 --- a/src/USER-OMP/pair_tersoff_mod_c_omp.cpp +++ b/src/USER-OMP/pair_tersoff_mod_c_omp.cpp @@ -157,7 +157,7 @@ void PairTersoffMODCOMP::eval(int iifrom, int iito, ThrData * const thr) rsq = rsqtmp; } - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq > params[iparam_ij].cutsq) continue; repulsive(¶ms[iparam_ij],rsq,fpair,EFLAG,evdwl); @@ -185,7 +185,7 @@ void PairTersoffMODCOMP::eval(int iifrom, int iito, ThrData * const thr) j = jlist[jj]; j &= NEIGHMASK; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; delr1[0] = x[j].x - xtmp; delr1[1] = x[j].y - ytmp; @@ -210,7 +210,7 @@ void PairTersoffMODCOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; @@ -251,7 +251,7 @@ void PairTersoffMODCOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; diff --git a/src/USER-OMP/pair_tersoff_mod_omp.cpp b/src/USER-OMP/pair_tersoff_mod_omp.cpp index e689803c38..454a387982 100644 --- a/src/USER-OMP/pair_tersoff_mod_omp.cpp +++ b/src/USER-OMP/pair_tersoff_mod_omp.cpp @@ -159,7 +159,7 @@ void PairTersoffMODOMP::eval(int iifrom, int iito, ThrData * const thr) rsq = rsqtmp; } - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq > params[iparam_ij].cutsq) continue; repulsive(¶ms[iparam_ij],rsq,fpair,EFLAG,evdwl); @@ -187,7 +187,7 @@ void PairTersoffMODOMP::eval(int iifrom, int iito, ThrData * const thr) j = jlist[jj]; j &= NEIGHMASK; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; delr1[0] = x[j].x - xtmp; delr1[1] = x[j].y - ytmp; @@ -212,7 +212,7 @@ void PairTersoffMODOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; @@ -253,7 +253,7 @@ void PairTersoffMODOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[kk]; k &= NEIGHMASK; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; diff --git a/src/USER-OMP/pair_tersoff_omp.cpp b/src/USER-OMP/pair_tersoff_omp.cpp index 7fb3c70d78..c12e3b9859 100644 --- a/src/USER-OMP/pair_tersoff_omp.cpp +++ b/src/USER-OMP/pair_tersoff_omp.cpp @@ -173,7 +173,7 @@ void PairTersoffOMP::eval(int iifrom, int iito, ThrData * const thr) } jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; if (rsq >= params[iparam_ij].cutsq) continue; repulsive(¶ms[iparam_ij],rsq,fpair,EFLAG,evdwl); @@ -200,7 +200,7 @@ void PairTersoffOMP::eval(int iifrom, int iito, ThrData * const thr) for (jj = 0; jj < numshort; jj++) { j = neighshort_thr[jj]; jtype = map[type[j]]; - iparam_ij = elem2param[itype][jtype][jtype]; + iparam_ij = elem3param[itype][jtype][jtype]; delr1[0] = x[j].x - xtmp; delr1[1] = x[j].y - ytmp; @@ -224,7 +224,7 @@ void PairTersoffOMP::eval(int iifrom, int iito, ThrData * const thr) if (jj == kk) continue; k = neighshort_thr[kk]; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; @@ -264,7 +264,7 @@ void PairTersoffOMP::eval(int iifrom, int iito, ThrData * const thr) if (jj == kk) continue; k = neighshort_thr[kk]; ktype = map[type[k]]; - iparam_ijk = elem2param[itype][jtype][ktype]; + iparam_ijk = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; diff --git a/src/USER-OMP/pair_tersoff_table_omp.cpp b/src/USER-OMP/pair_tersoff_table_omp.cpp index 2e52492491..02752c8577 100644 --- a/src/USER-OMP/pair_tersoff_table_omp.cpp +++ b/src/USER-OMP/pair_tersoff_table_omp.cpp @@ -154,7 +154,7 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; @@ -185,8 +185,8 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k].x; dr_ik[1] = ytmp -x[k].y; @@ -241,7 +241,7 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) r_ij = dr_ij[0]*dr_ij[0] + dr_ij[1]*dr_ij[1] + dr_ij[2]*dr_ij[2]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (r_ij > params[ijparam].cutsq) continue; @@ -285,8 +285,8 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k].x; dr_ik[1] = ytmp -x[k].y; @@ -310,8 +310,8 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k].x; dr_ik[1] = ytmp -x[k].y; @@ -370,8 +370,8 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k].x; dr_ik[1] = ytmp -x[k].y; @@ -436,8 +436,8 @@ void PairTersoffTableOMP::eval(int iifrom, int iito, ThrData * const thr) k = jlist[neighbor_k]; k &= NEIGHMASK; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; dr_ik[0] = xtmp -x[k].x; dr_ik[1] = ytmp -x[k].y; diff --git a/src/USER-OMP/pair_vashishta_omp.cpp b/src/USER-OMP/pair_vashishta_omp.cpp index 303de78e37..23d7235578 100644 --- a/src/USER-OMP/pair_vashishta_omp.cpp +++ b/src/USER-OMP/pair_vashishta_omp.cpp @@ -143,7 +143,7 @@ void PairVashishtaOMP::eval(int iifrom, int iito, ThrData * const thr) } jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (rsq >= params[ijparam].cutsq) continue; twobody(¶ms[ijparam],rsq,fpair,EFLAG,evdwl); @@ -164,7 +164,7 @@ void PairVashishtaOMP::eval(int iifrom, int iito, ThrData * const thr) for (jj = 0; jj < jnumm1; jj++) { j = neighshort_thr[jj]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j].x - xtmp; delr1[1] = x[j].y - ytmp; delr1[2] = x[j].z - ztmp; @@ -177,8 +177,8 @@ void PairVashishtaOMP::eval(int iifrom, int iito, ThrData * const thr) for (kk = jj+1; kk < numshort; kk++) { k = neighshort_thr[kk]; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; diff --git a/src/USER-OMP/pair_vashishta_table_omp.cpp b/src/USER-OMP/pair_vashishta_table_omp.cpp index 50c985ad68..c03d827d9b 100644 --- a/src/USER-OMP/pair_vashishta_table_omp.cpp +++ b/src/USER-OMP/pair_vashishta_table_omp.cpp @@ -141,7 +141,7 @@ void PairVashishtaTableOMP::eval(int iifrom, int iito, ThrData * const thr) } jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; if (rsq >= params[ijparam].cutsq) continue; twobody_table(params[ijparam],rsq,fpair,EFLAG,evdwl); @@ -162,7 +162,7 @@ void PairVashishtaTableOMP::eval(int iifrom, int iito, ThrData * const thr) for (jj = 0; jj < jnumm1; jj++) { j = neighshort_thr[jj]; jtype = map[type[j]]; - ijparam = elem2param[itype][jtype][jtype]; + ijparam = elem3param[itype][jtype][jtype]; delr1[0] = x[j].x - xtmp; delr1[1] = x[j].y - ytmp; delr1[2] = x[j].z - ztmp; @@ -175,8 +175,8 @@ void PairVashishtaTableOMP::eval(int iifrom, int iito, ThrData * const thr) for (kk = jj+1; kk < numshort; kk++) { k = neighshort_thr[kk]; ktype = map[type[k]]; - ikparam = elem2param[itype][ktype][ktype]; - ijkparam = elem2param[itype][jtype][ktype]; + ikparam = elem3param[itype][ktype][ktype]; + ijkparam = elem3param[itype][jtype][ktype]; delr2[0] = x[k].x - xtmp; delr2[1] = x[k].y - ytmp; diff --git a/src/USER-REAXC/pair_reaxc.cpp b/src/USER-REAXC/pair_reaxc.cpp index fe78fbbb37..4d6f240ec6 100644 --- a/src/USER-REAXC/pair_reaxc.cpp +++ b/src/USER-REAXC/pair_reaxc.cpp @@ -22,23 +22,23 @@ #include "pair_reaxc.h" -#include - -#include -#include #include "atom.h" -#include "update.h" -#include "force.h" +#include "citeme.h" #include "comm.h" -#include "neighbor.h" -#include "neigh_list.h" -#include "neigh_request.h" -#include "modify.h" +#include "error.h" #include "fix.h" #include "fix_reaxc.h" -#include "citeme.h" +#include "force.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "update.h" + +#include +#include +#include // for strcasecmp() #include "reaxc_defs.h" #include "reaxc_types.h" @@ -175,7 +175,6 @@ PairReaxC::~PairReaxC() memory->destroy(setflag); memory->destroy(cutsq); memory->destroy(cutghost); - delete [] map; delete [] chi; delete [] eta; diff --git a/src/USER-REAXC/pair_reaxc.h b/src/USER-REAXC/pair_reaxc.h index a833ddbcf0..53b41ba9c8 100644 --- a/src/USER-REAXC/pair_reaxc.h +++ b/src/USER-REAXC/pair_reaxc.h @@ -62,9 +62,6 @@ class PairReaxC : public Pair { protected: char *fix_id; double cutmax; - int nelements; // # of unique elements - char **elements; // names of unique elements - int *map; class FixReaxC *fix_reax; double *chi,*eta,*gamma; diff --git a/src/USER-SMTBQ/pair_smtbq.cpp b/src/USER-SMTBQ/pair_smtbq.cpp index 7ed37fefc4..5a27855a47 100644 --- a/src/USER-SMTBQ/pair_smtbq.cpp +++ b/src/USER-SMTBQ/pair_smtbq.cpp @@ -91,10 +91,6 @@ PairSMTBQ::PairSMTBQ(LAMMPS *lmp) : Pair(lmp) ds = 0.0; kmax = 0; - nelements = 0; - elements = nullptr; - nparams = 0; - maxparam = 0; params = nullptr; intparams = nullptr; @@ -153,8 +149,6 @@ PairSMTBQ::~PairSMTBQ() { int i; if (elements) { - for ( i = 0; i < nelements; i++) delete [] elements[i]; - for (i = 0; i < atom->ntypes ; i++ ) free( params[i].nom); for (i = 1; i <= maxintparam ; i++ ) free( intparams[i].typepot); for (i = 1; i <= maxintparam ; i++ ) free( intparams[i].mode); @@ -166,7 +160,6 @@ PairSMTBQ::~PairSMTBQ() free(writeenerg); free(Bavard); - delete [] elements; memory->sfree(params); memory->sfree(intparams); @@ -216,7 +209,6 @@ PairSMTBQ::~PairSMTBQ() if (allocated) { memory->destroy(setflag); memory->destroy(cutsq); - delete [] map; delete [] esm; } @@ -252,92 +244,30 @@ void PairSMTBQ::settings(int narg, char ** /* arg */) void PairSMTBQ::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (strstr(force->pair_style,"hybrid")) + if (utils::strmatch(force->pair_style,"^hybrid")) error->all(FLERR,"Pair style SMTBQ is not compatible with hybrid styles"); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - n = strlen(arg[i]) + 1; - elements[j] = new char[n]; - strcpy(elements[j],arg[i]); - nelements++; - } - } + map_element2type(narg-3,arg+3); // read potential file and initialize potential parameters read_file(arg[2]); - n = atom->ntypes; - // generate Coulomb 1/r energy look-up table - if (comm->me == 0 && screen) fprintf(screen,"Pair SMTBQ:\n"); if (comm->me == 0 && screen) - fprintf(screen," generating Coulomb integral lookup table ...\n"); + fputs("Pair SMTBQ: generating Coulomb integral lookup table ...\n",screen); tabqeq(); // ------------ - if (comm->me == 0 && screen) - fprintf(screen," generating Second Moment integral lookup table ...\n"); + fputs(" generating Second Moment integral lookup table ...\n",screen); tabsm(); - - // ------------ - - // clear setflag since coeff() called once with I,J = * * - - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- diff --git a/src/USER-SMTBQ/pair_smtbq.h b/src/USER-SMTBQ/pair_smtbq.h index 4681c94895..8bf1cba57c 100644 --- a/src/USER-SMTBQ/pair_smtbq.h +++ b/src/USER-SMTBQ/pair_smtbq.h @@ -60,8 +60,6 @@ protected: int loopmax; // max of iteration double cutmax; // max cutoff for all elements - int nelements; // # of unique elements - char **elements; // names of unique elements char *QEqMode; // name of QEqMode char *Bavard; // Verbose parameter char *writepot; // write or not the electronegativity component @@ -70,11 +68,8 @@ protected: double zlim1QEq; // z limit for QEq equilibration double zlim2QEq; // z limit for QEq equilibration double QOxInit; // Initial charge for oxygen atoms (if the charge is not specified) - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets - int maxintparam; // max # of interaction sets - int maxintsm; // max # of interaction SM + int maxintparam; // max # of interaction sets + int maxintsm; // max # of interaction SM double r1Coord,r2Coord; Param *params; // parameter set for an I atom Intparam *intparams; // parameter set for an I interaction diff --git a/src/input.cpp b/src/input.cpp index 53fcc606db..f96cf8c75c 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1697,6 +1697,9 @@ void Input::pair_coeff() error->all(FLERR,"Pair_coeff command before simulation box is defined"); if (force->pair == nullptr) error->all(FLERR,"Pair_coeff command before pair_style is defined"); + if ((narg < 2) || (force->pair->one_coeff && ((strcmp(arg[0],"*") != 0) + || (strcmp(arg[1],"*") != 0)))) + error->all(FLERR,"Incorrect args for pair coefficients"); force->pair->coeff(narg,arg); } diff --git a/src/pair.cpp b/src/pair.cpp index 27a8831eb1..767fa638cf 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -106,6 +106,13 @@ Pair::Pair(LAMMPS *lmp) : Pointers(lmp) num_tally_compute = 0; list_tally_compute = nullptr; + nelements = nparams = maxparam = 0; + elements = nullptr; + elem1param = nullptr; + elem2param = nullptr; + elem3param = nullptr; + map = nullptr; + nondefault_history_transfer = 0; beyond_contact = 0; @@ -129,6 +136,11 @@ Pair::~Pair() if (copymode) return; + if (elements) + for (int i = 0; i < nelements; i++) delete[] elements[i]; + delete[] elements; + + delete[] map; memory->destroy(eatom); memory->destroy(vatom); memory->destroy(cvatom); @@ -776,6 +788,68 @@ void Pair::del_tally_callback(Compute *ptr) } } +/* ------------------------------------------------------------------- + build element to atom type mapping for manybody potentials + also clear and reset setflag[][] array and check missing entries +---------------------------------------------------------------------- */ + +void Pair::map_element2type(int narg, char **arg, bool update_setflag) +{ + int i,j; + const int ntypes = atom->ntypes; + + // read args that map atom types to elements in potential file + // map[i] = which element the Ith atom type is, -1 if "NULL" + // nelements = # of unique elements + // elements = list of element names + + if (narg != ntypes) + error->all(FLERR,"Incorrect args for pair coefficients"); + + if (elements) { + for (i = 0; i < nelements; i++) delete[] elements[i]; + delete[] elements; + } + elements = new char*[ntypes]; + for (i = 0; i < ntypes; i++) elements[i] = nullptr; + + nelements = 0; + map[0] = -1; + for (i = 1; i <= narg; i++) { + std::string entry = arg[i-1]; + if (entry == "NULL") { + map[i] = -1; + continue; + } + for (j = 0; j < nelements; j++) + if (entry == elements[j]) break; + map[i] = j; + if (j == nelements) { + elements[j] = utils::strdup(entry); + nelements++; + } + } + + // if requested, clear setflag[i][j] and set it for type pairs + // where both are mapped to elements in map. + + if (update_setflag) { + + int count = 0; + for (i = 1; i <= ntypes; i++) { + for (j = i; j <= ntypes; j++) { + setflag[i][j] = 0; + if ((map[i] >= 0) && (map[j] >= 0)) { + setflag[i][j] = 1; + count++; + } + } + } + + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); + } +} + /* ---------------------------------------------------------------------- setup for energy, virial computation see integrate::ev_set() for bitwise settings of eflag/vflag diff --git a/src/pair.h b/src/pair.h index 9bca64fbf3..b25ad448eb 100644 --- a/src/pair.h +++ b/src/pair.h @@ -216,17 +216,27 @@ class Pair : protected Pointers { virtual void del_tally_callback(class Compute *); protected: - int instance_me; // which Pair class instantiation I am + int instance_me; // which Pair class instantiation I am + int special_lj[4]; // copied from force->special_lj for Kokkos + int suffix_flag; // suffix compatibility flag - int special_lj[4]; // copied from force->special_lj for Kokkos - - int suffix_flag; // suffix compatibility flag - - // pair_modify settings - int offset_flag,mix_flag; // flags for offset and mixing - double tabinner; // inner cutoff for Coulomb table - double tabinner_disp; // inner cutoff for dispersion table + // pair_modify settings + int offset_flag,mix_flag; // flags for offset and mixing + double tabinner; // inner cutoff for Coulomb table + double tabinner_disp; // inner cutoff for dispersion table + protected: + // for mapping of elements to atom types and parameters + // mostly used for manybody potentials + int nelements; // # of unique elements + char **elements; // names of unique elements + int *elem1param; // mapping from elements to parameters + int **elem2param; // mapping from element pairs to parameters + int ***elem3param; // mapping from element triplets to parameters + int *map; // mapping from atom types to elements + int nparams; // # of stored parameter sets + int maxparam; // max # of parameter sets + void map_element2type(int, char**, bool update_setflag=true); public: // custom data type for accessing Coulomb tables diff --git a/src/pair_coul_streitz.cpp b/src/pair_coul_streitz.cpp index 68790c0f03..55529f9eae 100644 --- a/src/pair_coul_streitz.cpp +++ b/src/pair_coul_streitz.cpp @@ -49,13 +49,8 @@ PairCoulStreitz::PairCoulStreitz(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; nmax = 0; - nelements = 0; - elements = nullptr; - nparams = 0; - maxparam = 0; params = nullptr; - elem2param = nullptr; } /* ---------------------------------------------------------------------- @@ -64,12 +59,8 @@ PairCoulStreitz::PairCoulStreitz(LAMMPS *lmp) : Pair(lmp) PairCoulStreitz::~PairCoulStreitz() { - if (elements) - for (int i = 0; i < nelements; i++) delete [] elements[i]; - - delete [] elements; memory->sfree(params); - memory->destroy(elem2param); + memory->destroy(elem1param); if (allocated) { memory->destroy(setflag); @@ -80,7 +71,6 @@ PairCoulStreitz::~PairCoulStreitz() memory->destroy(qeq_g); memory->destroy(qeq_z); memory->destroy(qeq_c); - delete [] map; } } @@ -130,69 +120,19 @@ void PairCoulStreitz::settings(int narg, char **arg) void PairCoulStreitz::coeff(int narg, char **arg) { - int i,j,n; - if (!allocated) allocate(); - if (narg != 3 + atom->ntypes) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // insure I,J args are * * - - if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) - error->all(FLERR,"Incorrect args for pair coefficients"); - - // read args that map atom types to elements in potential file - // map[i] = which element the Ith atom type is, -1 if "NULL" - // nelements = # of unique elements - // elements = list of element names - - if (elements) { - for (i = 0; i < nelements; i++) delete [] elements[i]; - delete [] elements; - } - elements = new char*[atom->ntypes]; - for (i = 0; i < atom->ntypes; i++) elements[i] = nullptr; - - nelements = 0; - for (i = 3; i < narg; i++) { - if (strcmp(arg[i],"NULL") == 0) { - map[i-2] = -1; - continue; - } - for (j = 0; j < nelements; j++) - if (strcmp(arg[i],elements[j]) == 0) break; - map[i-2] = j; - if (j == nelements) { - elements[j] = utils::strdup(arg[i]); - nelements++; - } - } + map_element2type(narg-3, arg+3); // read potential file and initialize potential parameters read_file(arg[2]); setup_params(); - n = atom->ntypes; - - // clear setflag since coeff() called once with I,J = * * + const int n = atom->ntypes; for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - setflag[i][j] = 0; - - // set setflag i,j for type pairs where both are mapped to elements - - int count = 0; - for (int i = 1; i <= n; i++) - for (int j = i; j <= n; j++) - if (map[i] >= 0 && map[j] >= 0) { + for (int j = 1; j <= n; j++) scale[i][j] = 1.0; - setflag[i][j] = 1; - count++; - } - - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } /* ---------------------------------------------------------------------- @@ -308,10 +248,10 @@ void PairCoulStreitz::setup_params() { int i,m,n; - // set elem2param + // set elem1param - memory->destroy(elem2param); - memory->create(elem2param,nelements,"pair:elem2param"); + memory->destroy(elem1param); + memory->create(elem1param,nelements,"pair:elem1param"); for (i = 0; i < nelements; i++) { n = -1; @@ -322,7 +262,7 @@ void PairCoulStreitz::setup_params() } } if (n < 0) error->all(FLERR,"Potential file is missing an entry"); - elem2param[i] = n; + elem1param[i] = n; } // Wolf sum self energy @@ -381,7 +321,7 @@ void PairCoulStreitz::compute(int eflag, int vflag) ytmp = x[i][1]; ztmp = x[i][2]; itype = map[type[i]]; - iparam_i = elem2param[itype]; + iparam_i = elem1param[itype]; qi = q[i]; zei = params[iparam_i].zeta; @@ -401,7 +341,7 @@ void PairCoulStreitz::compute(int eflag, int vflag) j &= NEIGHMASK; jtype = map[type[j]]; - iparam_j = elem2param[jtype]; + iparam_j = elem1param[jtype]; qj = q[j]; zej = params[iparam_j].zeta; zj = params[iparam_j].zcore; @@ -454,7 +394,7 @@ void PairCoulStreitz::compute(int eflag, int vflag) ytmp = x[i][1]; ztmp = x[i][2]; itype = map[type[i]]; - iparam_i = elem2param[itype]; + iparam_i = elem1param[itype]; qi = q[i]; zei = params[iparam_i].zeta; @@ -473,7 +413,7 @@ void PairCoulStreitz::compute(int eflag, int vflag) j = jlist[jj]; j &= NEIGHMASK; jtype = map[type[j]]; - iparam_j = elem2param[jtype]; + iparam_j = elem1param[jtype]; qj = q[j]; zej = params[iparam_j].zeta; zj = params[iparam_j].zcore; diff --git a/src/pair_coul_streitz.h b/src/pair_coul_streitz.h index 2f62846212..12da6afcfe 100644 --- a/src/pair_coul_streitz.h +++ b/src/pair_coul_streitz.h @@ -45,14 +45,8 @@ class PairCoulStreitz : public Pair { }; int nmax; - int nelements; // # of unique elements - char **elements; // names of unique elements - int *elem2param; // mapping from element triplets to parameters - int *map; // mapping from atom types to elements - int nparams; // # of stored parameter sets - int maxparam; // max # of parameter sets double precision; - Param *params; // parameter set for an I-J-K interaction + Param *params; // parameter sets for elements // Kspace parameters int kspacetype; From 436be824e14d23115506cf11639bd101818fa084 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 25 Mar 2021 21:13:24 -0400 Subject: [PATCH 170/257] use std:: namespace for STL containers --- src/USER-AWPMD/pair_awpmd_cut.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/USER-AWPMD/pair_awpmd_cut.cpp b/src/USER-AWPMD/pair_awpmd_cut.cpp index 3d4e1f12a7..54f851171b 100644 --- a/src/USER-AWPMD/pair_awpmd_cut.cpp +++ b/src/USER-AWPMD/pair_awpmd_cut.cpp @@ -150,7 +150,7 @@ void PairAWPMDCut::compute(int eflag, int vflag) # if 1 // mapping of the LAMMPS numbers to the AWPMC numbers - vector gmap(ntot,-1); + std::vector gmap(ntot,-1); for (int ii = 0; ii < inum; ii++) { int i = ilist[ii]; @@ -226,7 +226,7 @@ void PairAWPMDCut::compute(int eflag, int vflag) // prepare the solver object wpmd->reset(); - map > etmap; + std::map > etmap; // add particles to the AWPMD solver object for (int i = 0; i < ntot; i++) { //int i = ilist[ii]; @@ -246,8 +246,8 @@ void PairAWPMDCut::compute(int eflag, int vflag) fi= new Vector_3[wpmd->ni]; // adding electrons - for (map >::iterator it=etmap.begin(); it!= etmap.end(); ++it) { - vector &el=it->second; + for (std::map >::iterator it=etmap.begin(); it!= etmap.end(); ++it) { + std::vector &el=it->second; if (!el.size()) // should not happen continue; int s=spin[el[0]] >0 ? 0 : 1; From dfb18caf5a38b9e32ae6262ce6645f9a37135566 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 27 Mar 2021 15:52:14 -0400 Subject: [PATCH 171/257] simplify using utils::strdup(), update order of include files --- src/KOKKOS/pair_exp6_rx_kokkos.cpp | 10 +---- src/KOKKOS/pair_table_rx_kokkos.cpp | 18 +++------ src/LATTE/fix_latte.cpp | 5 +-- src/MC/fix_atom_swap.cpp | 45 +++++++++++---------- src/MC/fix_bond_swap.cpp | 34 ++++++++-------- src/MC/fix_gcmc.cpp | 53 +++++++++++-------------- src/MC/fix_widom.cpp | 4 +- src/MISC/compute_ti.cpp | 26 +++++------- src/MISC/fix_deposit.cpp | 12 ++---- src/MISC/fix_evaporate.cpp | 4 +- src/MISC/fix_oneway.cpp | 4 +- src/MISC/fix_orient_bcc.cpp | 16 ++------ src/MISC/fix_orient_fcc.cpp | 16 ++------ src/MLIAP/mliap_descriptor_snap.cpp | 9 ++--- src/MLIAP/mliap_model_nn.cpp | 2 +- src/REPLICA/compute_event_displace.cpp | 4 +- src/REPLICA/prd.cpp | 22 +++-------- src/REPLICA/tad.cpp | 19 +++------ src/RIGID/compute_erotate_rigid.cpp | 16 ++++---- src/RIGID/compute_ke_rigid.cpp | 16 ++++---- src/RIGID/compute_rigid_local.cpp | 4 +- src/RIGID/fix_ehex.cpp | 22 +++++------ src/RIGID/fix_rigid_nh.cpp | 8 +--- src/RIGID/fix_rigid_nh_small.cpp | 8 +--- src/RIGID/fix_rigid_nph.cpp | 27 ++----------- src/RIGID/fix_rigid_nph_small.cpp | 27 ++----------- src/RIGID/fix_rigid_npt.cpp | 27 ++----------- src/RIGID/fix_rigid_npt_small.cpp | 27 ++----------- src/SHOCK/fix_msst.cpp | 25 ++++++------ src/SHOCK/fix_nphug.cpp | 55 +++++++------------------- src/SPIN/fix_neb_spin.cpp | 28 +++++-------- 31 files changed, 191 insertions(+), 402 deletions(-) diff --git a/src/KOKKOS/pair_exp6_rx_kokkos.cpp b/src/KOKKOS/pair_exp6_rx_kokkos.cpp index 5c1a3b3589..c0cfd11466 100644 --- a/src/KOKKOS/pair_exp6_rx_kokkos.cpp +++ b/src/KOKKOS/pair_exp6_rx_kokkos.cpp @@ -1800,14 +1800,8 @@ void PairExp6rxKokkos::read_file(char *file) } params[nparams].ispecies = ispecies; - - n = strlen(&atom->dname[ispecies][0]) + 1; - params[nparams].name = new char[n]; - strcpy(params[nparams].name,&atom->dname[ispecies][0]); - - n = strlen(words[1]) + 1; - params[nparams].potential = new char[n]; - strcpy(params[nparams].potential,words[1]); + params[nparams].name = utils::strdup(&atom->dname[ispecies][0]); + params[nparams].potential = utils::strdup(words[1]); if (strcmp(params[nparams].potential,"exp6") == 0) { params[nparams].alpha = atof(words[2]); params[nparams].epsilon = atof(words[3]); diff --git a/src/KOKKOS/pair_table_rx_kokkos.cpp b/src/KOKKOS/pair_table_rx_kokkos.cpp index c3e23b6e5e..41b0343443 100644 --- a/src/KOKKOS/pair_table_rx_kokkos.cpp +++ b/src/KOKKOS/pair_table_rx_kokkos.cpp @@ -1040,25 +1040,19 @@ void PairTableRXKokkos::coeff(int narg, char **arg) nspecies = atom->nspecies_dpd; if (nspecies==0) error->all(FLERR,"There are no rx species specified."); - int n; - n = strlen(arg[4]) + 1; - site1 = new char[n]; - strcpy(site1,arg[4]); + site1 = utils::strdup(arg[4]); int ispecies; - for (ispecies = 0; ispecies < nspecies; ispecies++) { + for (ispecies = 0; ispecies < nspecies; ispecies++) if (strcmp(site1,&atom->dname[ispecies][0]) == 0) break; - } + if (ispecies == nspecies && strcmp(site1,"1fluid") != 0) error->all(FLERR,"Site1 name not recognized in pair coefficients"); - n = strlen(arg[5]) + 1; - site2 = new char[n]; - strcpy(site2,arg[5]); - - for (ispecies = 0; ispecies < nspecies; ispecies++) { + site2 = utils::strdup(arg[5]); + for (ispecies = 0; ispecies < nspecies; ispecies++) if (strcmp(site2,&atom->dname[ispecies][0]) == 0) break; - } + if (ispecies == nspecies && strcmp(site2,"1fluid") != 0) error->all(FLERR,"Site2 name not recognized in pair coefficients"); diff --git a/src/LATTE/fix_latte.cpp b/src/LATTE/fix_latte.cpp index ababe2f185..81d7cb3201 100644 --- a/src/LATTE/fix_latte.cpp +++ b/src/LATTE/fix_latte.cpp @@ -84,10 +84,7 @@ FixLatte::FixLatte(LAMMPS *lmp, int narg, char **arg) : error->all(FLERR,"Fix latte does not yet support a LAMMPS calculation " "of a Coulomb potential"); - int n = strlen(arg[3]) + 1; - id_pe = new char[n]; - strcpy(id_pe,arg[3]); - + id_pe = utils::strdup(arg[3]); int ipe = modify->find_compute(id_pe); if (ipe < 0) error->all(FLERR,"Could not find fix latte compute ID"); if (modify->compute[ipe]->peatomflag == 0) diff --git a/src/MC/fix_atom_swap.cpp b/src/MC/fix_atom_swap.cpp index 92671fb637..954ce46aa6 100644 --- a/src/MC/fix_atom_swap.cpp +++ b/src/MC/fix_atom_swap.cpp @@ -18,30 +18,31 @@ #include "fix_atom_swap.h" +#include "angle.h" +#include "atom.h" +#include "bond.h" +#include "comm.h" +#include "compute.h" +#include "dihedral.h" +#include "domain.h" +#include "error.h" +#include "fix.h" +#include "force.h" +#include "group.h" +#include "improper.h" +#include "kspace.h" +#include "memory.h" +#include "modify.h" +#include "neighbor.h" +#include "pair.h" +#include "random_park.h" +#include "region.h" +#include "update.h" + #include #include #include #include -#include "atom.h" -#include "update.h" -#include "modify.h" -#include "fix.h" -#include "comm.h" -#include "compute.h" -#include "group.h" -#include "domain.h" -#include "region.h" -#include "random_park.h" -#include "force.h" -#include "pair.h" -#include "bond.h" -#include "angle.h" -#include "dihedral.h" -#include "improper.h" -#include "kspace.h" -#include "memory.h" -#include "error.h" -#include "neighbor.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -138,9 +139,7 @@ void FixAtomSwap::options(int narg, char **arg) iregion = domain->find_region(arg[iarg+1]); if (iregion == -1) error->all(FLERR,"Region ID for fix atom/swap does not exist"); - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); regionflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"ke") == 0) { diff --git a/src/MC/fix_bond_swap.cpp b/src/MC/fix_bond_swap.cpp index 119c95d842..84d89a9626 100644 --- a/src/MC/fix_bond_swap.cpp +++ b/src/MC/fix_bond_swap.cpp @@ -13,27 +13,27 @@ #include "fix_bond_swap.h" -#include -#include -#include "atom.h" -#include "force.h" -#include "pair.h" -#include "bond.h" #include "angle.h" -#include "neighbor.h" +#include "atom.h" +#include "bond.h" +#include "citeme.h" +#include "comm.h" +#include "compute.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 "comm.h" -#include "domain.h" -#include "modify.h" -#include "compute.h" +#include "neighbor.h" +#include "pair.h" #include "random_mars.h" -#include "citeme.h" -#include "memory.h" -#include "error.h" - #include "update.h" +#include +#include + using namespace LAMMPS_NS; using namespace FixConst; @@ -642,9 +642,7 @@ int FixBondSwap::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index b8eecf95ca..b946615b04 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -17,32 +17,33 @@ #include "fix_gcmc.h" -#include -#include +#include "angle.h" #include "atom.h" #include "atom_vec.h" -#include "molecule.h" -#include "update.h" -#include "modify.h" -#include "fix.h" +#include "bond.h" #include "comm.h" #include "compute.h" -#include "group.h" -#include "domain.h" -#include "region.h" -#include "random_park.h" -#include "force.h" -#include "pair.h" -#include "bond.h" -#include "angle.h" #include "dihedral.h" +#include "domain.h" +#include "error.h" +#include "fix.h" +#include "force.h" +#include "group.h" #include "improper.h" #include "kspace.h" -#include "math_extra.h" #include "math_const.h" +#include "math_extra.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "molecule.h" #include "neighbor.h" +#include "pair.h" +#include "random_park.h" +#include "region.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -301,9 +302,7 @@ void FixGCMC::options(int narg, char **arg) iregion = domain->find_region(arg[iarg+1]); if (iregion == -1) error->all(FLERR,"Region ID for fix gcmc does not exist"); - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); regionflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"maxangle") == 0) { @@ -327,18 +326,14 @@ void FixGCMC::options(int narg, char **arg) iarg += 2; } else if (strcmp(arg[iarg],"rigid") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix gcmc command"); - int n = strlen(arg[iarg+1]) + 1; delete [] idrigid; - idrigid = new char[n]; - strcpy(idrigid,arg[iarg+1]); + idrigid = utils::strdup(arg[iarg+1]); rigidflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"shake") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix gcmc command"); - int n = strlen(arg[iarg+1]) + 1; delete [] idshake; - idshake = new char[n]; - strcpy(idshake,arg[iarg+1]); + idshake = utils::strdup(arg[iarg+1]); shakeflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"full_energy") == 0) { @@ -353,9 +348,7 @@ void FixGCMC::options(int narg, char **arg) ngroupsmax*sizeof(char *), "fix_gcmc:groupstrings"); } - int n = strlen(arg[iarg+1]) + 1; - groupstrings[ngroups] = new char[n]; - strcpy(groupstrings[ngroups],arg[iarg+1]); + groupstrings[ngroups] = utils::strdup(arg[iarg+1]); ngroups++; iarg += 2; } else if (strcmp(arg[iarg],"grouptype") == 0) { @@ -370,9 +363,7 @@ void FixGCMC::options(int narg, char **arg) "fix_gcmc:grouptypestrings"); } grouptypes[ngrouptypes] = utils::inumeric(FLERR,arg[iarg+1],false,lmp); - int n = strlen(arg[iarg+2]) + 1; - grouptypestrings[ngrouptypes] = new char[n]; - strcpy(grouptypestrings[ngrouptypes],arg[iarg+2]); + grouptypestrings[ngrouptypes] = utils::strdup(arg[iarg+2]); ngrouptypes++; iarg += 3; } else if (strcmp(arg[iarg],"intra_energy") == 0) { diff --git a/src/MC/fix_widom.cpp b/src/MC/fix_widom.cpp index a1bdc32515..e898196e14 100644 --- a/src/MC/fix_widom.cpp +++ b/src/MC/fix_widom.cpp @@ -224,9 +224,7 @@ void FixWidom::options(int narg, char **arg) iregion = domain->find_region(arg[iarg+1]); if (iregion == -1) error->all(FLERR,"Region ID for fix widom does not exist"); - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); regionflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"charge") == 0) { diff --git a/src/MISC/compute_ti.cpp b/src/MISC/compute_ti.cpp index e81dd81c86..5ba85679a3 100644 --- a/src/MISC/compute_ti.cpp +++ b/src/MISC/compute_ti.cpp @@ -17,17 +17,17 @@ #include "compute_ti.h" -#include #include "atom.h" -#include "update.h" #include "domain.h" -#include "force.h" -#include "pair.h" -#include "kspace.h" -#include "input.h" -#include "variable.h" #include "error.h" +#include "force.h" +#include "input.h" +#include "kspace.h" +#include "pair.h" +#include "update.h" +#include "variable.h" +#include using namespace LAMMPS_NS; @@ -77,21 +77,15 @@ ComputeTI::ComputeTI(LAMMPS *lmp, int narg, char **arg) : else if (strcmp(arg[iarg],"tail") == 0) which[nterms] = TAIL; else which[nterms] = PAIR; - int n = strlen(arg[iarg]) + 1; - pstyle[nterms] = new char[n]; - strcpy(pstyle[nterms],arg[iarg]); + pstyle[nterms] = utils::strdup(arg[iarg]); utils::bounds(FLERR,arg[iarg+1],1,atom->ntypes,ilo[nterms],ihi[nterms],error); iarg += 1; if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) { - int n = strlen(&arg[iarg+1][2]) + 1; - var1[nterms] = new char[n]; - strcpy(var1[nterms],&arg[iarg+1][2]); + var1[nterms] = utils::strdup(&arg[iarg+1][2]); } else error->all(FLERR,"Illegal compute ti command"); if (strstr(arg[iarg+2],"v_") == arg[iarg+2]) { - int n = strlen(&arg[iarg+2][2]) + 1; - var2[nterms] = new char[n]; - strcpy(var2[nterms],&arg[iarg+2][2]); + var2[nterms] = utils::strdup(&arg[iarg+2][2]); } else error->all(FLERR,"Illegal compute ti command"); nterms++; diff --git a/src/MISC/fix_deposit.cpp b/src/MISC/fix_deposit.cpp index e832b37e67..6af537f6f4 100644 --- a/src/MISC/fix_deposit.cpp +++ b/src/MISC/fix_deposit.cpp @@ -697,9 +697,7 @@ void FixDeposit::options(int narg, char **arg) iregion = domain->find_region(arg[iarg+1]); if (iregion == -1) error->all(FLERR,"Region ID for fix deposit does not exist"); - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"mol") == 0) { @@ -728,18 +726,14 @@ void FixDeposit::options(int narg, char **arg) iarg += nmol+1; } else if (strcmp(arg[iarg],"rigid") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix deposit command"); - int n = strlen(arg[iarg+1]) + 1; delete [] idrigid; - idrigid = new char[n]; - strcpy(idrigid,arg[iarg+1]); + idrigid = utils::strdup(arg[iarg+1]); rigidflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"shake") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal fix deposit command"); - int n = strlen(arg[iarg+1]) + 1; delete [] idshake; - idshake = new char[n]; - strcpy(idshake,arg[iarg+1]); + idshake = utils::strdup(arg[iarg+1]); shakeflag = 1; iarg += 2; diff --git a/src/MISC/fix_evaporate.cpp b/src/MISC/fix_evaporate.cpp index d0e016b554..2a11d1675a 100644 --- a/src/MISC/fix_evaporate.cpp +++ b/src/MISC/fix_evaporate.cpp @@ -44,9 +44,7 @@ FixEvaporate::FixEvaporate(LAMMPS *lmp, int narg, char **arg) : nevery = utils::inumeric(FLERR,arg[3],false,lmp); nflux = utils::inumeric(FLERR,arg[4],false,lmp); iregion = domain->find_region(arg[5]); - int n = strlen(arg[5]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[5]); + idregion = utils::strdup(arg[5]); int seed = utils::inumeric(FLERR,arg[6],false,lmp); if (nevery <= 0 || nflux <= 0) diff --git a/src/MISC/fix_oneway.cpp b/src/MISC/fix_oneway.cpp index a2e612730c..7e655e60c6 100644 --- a/src/MISC/fix_oneway.cpp +++ b/src/MISC/fix_oneway.cpp @@ -42,9 +42,7 @@ FixOneWay::FixOneWay(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) nevery = utils::inumeric(FLERR,arg[3],false,lmp); if (nevery < 1) error->all(FLERR,"Illegal fix oneway command"); - int len = strlen(arg[4]); - regionstr = new char[len+1]; - strcpy(regionstr,arg[4]); + regionstr = utils::strdup(arg[4]); if (strcmp(arg[5], "x") == 0) direction = X|PLUS; if (strcmp(arg[5], "X") == 0) direction = X|PLUS; diff --git a/src/MISC/fix_orient_bcc.cpp b/src/MISC/fix_orient_bcc.cpp index 186e651504..4c6693f729 100644 --- a/src/MISC/fix_orient_bcc.cpp +++ b/src/MISC/fix_orient_bcc.cpp @@ -82,19 +82,11 @@ FixOrientBCC::FixOrientBCC(LAMMPS *lmp, int narg, char **arg) : uxif_high = utils::numeric(FLERR,arg[8],false,lmp); if (direction_of_motion == 0) { - int n = strlen(arg[9]) + 1; - chifilename = new char[n]; - strcpy(chifilename,arg[9]); - n = strlen(arg[10]) + 1; - xifilename = new char[n]; - strcpy(xifilename,arg[10]); + chifilename = utils::strdup(arg[9]); + xifilename = utils::strdup(arg[10]); } else if (direction_of_motion == 1) { - int n = strlen(arg[9]) + 1; - xifilename = new char[n]; - strcpy(xifilename,arg[9]); - n = strlen(arg[10]) + 1; - chifilename = new char[n]; - strcpy(chifilename,arg[10]); + xifilename = utils::strdup(arg[9]); + chifilename = utils::strdup(arg[10]); } else error->all(FLERR,"Illegal fix orient/bcc command"); // initializations diff --git a/src/MISC/fix_orient_fcc.cpp b/src/MISC/fix_orient_fcc.cpp index 04eae4ac3e..a59e412fde 100644 --- a/src/MISC/fix_orient_fcc.cpp +++ b/src/MISC/fix_orient_fcc.cpp @@ -80,19 +80,11 @@ FixOrientFCC::FixOrientFCC(LAMMPS *lmp, int narg, char **arg) : uxif_high = utils::numeric(FLERR,arg[8],false,lmp); if (direction_of_motion == 0) { - int n = strlen(arg[9]) + 1; - chifilename = new char[n]; - strcpy(chifilename,arg[9]); - n = strlen(arg[10]) + 1; - xifilename = new char[n]; - strcpy(xifilename,arg[10]); + chifilename = utils::strdup(arg[9]); + xifilename = utils::strdup(arg[10]); } else if (direction_of_motion == 1) { - int n = strlen(arg[9]) + 1; - xifilename = new char[n]; - strcpy(xifilename,arg[9]); - n = strlen(arg[10]) + 1; - chifilename = new char[n]; - strcpy(chifilename,arg[10]); + xifilename = utils::strdup(arg[9]); + chifilename = utils::strdup(arg[10]); } else error->all(FLERR,"Illegal fix orient/fcc command"); // initializations diff --git a/src/MLIAP/mliap_descriptor_snap.cpp b/src/MLIAP/mliap_descriptor_snap.cpp index 388561e248..0fdc548fc1 100644 --- a/src/MLIAP/mliap_descriptor_snap.cpp +++ b/src/MLIAP/mliap_descriptor_snap.cpp @@ -427,22 +427,19 @@ void MLIAPDescriptorSNAP::read_paramfile(char *paramfilename) if (strcmp(keywd,"elems") == 0) { for (int ielem = 0; ielem < nelements; ielem++) { - char* elemtmp = keyval; - int n = strlen(elemtmp) + 1; - elements[ielem] = new char[n]; - strcpy(elements[ielem],elemtmp); + elements[ielem] = utils::strdup(keyval); keyval = strtok(nullptr,"' \t\n\r\f"); } elementsflag = 1; } else if (strcmp(keywd,"radelems") == 0) { for (int ielem = 0; ielem < nelements; ielem++) { - radelem[ielem] = atof(keyval); + radelem[ielem] = utils::numeric(FLERR,keyval,false,lmp); keyval = strtok(nullptr,"' \t\n\r\f"); } radelemflag = 1; } else if (strcmp(keywd,"welems") == 0) { for (int ielem = 0; ielem < nelements; ielem++) { - wjelem[ielem] = atof(keyval); + wjelem[ielem] = utils::numeric(FLERR,keyval,false,lmp); keyval = strtok(nullptr,"' \t\n\r\f"); } wjelemflag = 1; diff --git a/src/MLIAP/mliap_model_nn.cpp b/src/MLIAP/mliap_model_nn.cpp index 2bf75385b4..3805a5761b 100644 --- a/src/MLIAP/mliap_model_nn.cpp +++ b/src/MLIAP/mliap_model_nn.cpp @@ -18,9 +18,9 @@ #include "mliap_model_nn.h" #include "pair_mliap.h" #include "mliap_data.h" -#include "error.h" #include "comm.h" +#include "error.h" #include "memory.h" #include "tokenizer.h" diff --git a/src/REPLICA/compute_event_displace.cpp b/src/REPLICA/compute_event_displace.cpp index 958c2d3c22..0ef14b8603 100644 --- a/src/REPLICA/compute_event_displace.cpp +++ b/src/REPLICA/compute_event_displace.cpp @@ -206,7 +206,5 @@ void ComputeEventDisplace::reset_extra_compute_fix(const char *id_new) id_event = nullptr; if (id_new == nullptr) return; - int n = strlen(id_new) + 1; - id_event = new char[n]; - strcpy(id_event,id_new); + id_event = utils::strdup(id_new); } diff --git a/src/REPLICA/prd.cpp b/src/REPLICA/prd.cpp index de45116194..40e5fc8833 100644 --- a/src/REPLICA/prd.cpp +++ b/src/REPLICA/prd.cpp @@ -77,8 +77,7 @@ void PRD::command(int narg, char **arg) t_dephase = utils::inumeric(FLERR,arg[3],false,lmp); t_corr = utils::inumeric(FLERR,arg[4],false,lmp); - char *id_compute = new char[strlen(arg[5])+1]; - strcpy(id_compute,arg[5]); + char *id_compute = utils::strdup(arg[5]); int seed = utils::inumeric(FLERR,arg[6],false,lmp); options(narg-7,&arg[7]); @@ -875,15 +874,8 @@ void PRD::options(int narg, char **arg) temp_flag = 0; stepmode = 0; - char *str = (char *) "geom"; - int n = strlen(str) + 1; - loop_setting = new char[n]; - strcpy(loop_setting,str); - - str = (char *) "gaussian"; - n = strlen(str) + 1; - dist_setting = new char[n]; - strcpy(dist_setting,str); + loop_setting = utils::strdup("geom"); + dist_setting = utils::strdup("gaussian"); int iarg = 0; while (iarg < narg) { @@ -912,16 +904,12 @@ void PRD::options(int narg, char **arg) else if (strcmp(arg[iarg+1],"local") == 0) loop_setting = nullptr; else if (strcmp(arg[iarg+1],"geom") == 0) loop_setting = nullptr; else error->all(FLERR,"Illegal prd command"); - int n = strlen(arg[iarg+1]) + 1; - loop_setting = new char[n]; - strcpy(loop_setting,arg[iarg+1]); + loop_setting = utils::strdup(arg[iarg+1]); if (strcmp(arg[iarg+2],"uniform") == 0) dist_setting = nullptr; else if (strcmp(arg[iarg+2],"gaussian") == 0) dist_setting = nullptr; else error->all(FLERR,"Illegal prd command"); - n = strlen(arg[iarg+2]) + 1; - dist_setting = new char[n]; - strcpy(dist_setting,arg[iarg+2]); + dist_setting = utils::strdup(arg[iarg+2]); iarg += 3; diff --git a/src/REPLICA/tad.cpp b/src/REPLICA/tad.cpp index 0fc611b307..0bab7a31c8 100644 --- a/src/REPLICA/tad.cpp +++ b/src/REPLICA/tad.cpp @@ -89,15 +89,12 @@ void TAD::command(int narg, char **arg) delta_conf = utils::numeric(FLERR,arg[4],false,lmp); tmax = utils::numeric(FLERR,arg[5],false,lmp); - char *id_compute = new char[strlen(arg[6])+1]; - strcpy(id_compute,arg[6]); + char *id_compute = utils::strdup(arg[6]); // quench minimizer is set by min_style command // NEB minimizer is set by options, default = quickmin - int n = strlen(update->minimize_style) + 1; - min_style = new char[n]; - strcpy(min_style,update->minimize_style); + min_style = utils::strdup(update->minimize_style); options(narg-7,&arg[7]); @@ -585,9 +582,7 @@ void TAD::options(int narg, char **arg) n2steps_neb = 100; nevery_neb = 10; - int n = strlen("quickmin") + 1; - min_style_neb = new char[n]; - strcpy(min_style_neb,"quickmin"); + min_style_neb = utils::strdup("quickmin"); dt_neb = update->dt; neb_logfilename = nullptr; @@ -619,9 +614,7 @@ void TAD::options(int narg, char **arg) } else if (strcmp(arg[iarg],"neb_style") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal tad command"); delete [] min_style_neb; - int n = strlen(arg[iarg+1]) + 1; - min_style_neb = new char[n]; - strcpy(min_style_neb,arg[iarg+1]); + min_style_neb = utils::strdup(arg[iarg+1]); iarg += 2; } else if (strcmp(arg[iarg],"neb_step") == 0) { @@ -635,9 +628,7 @@ void TAD::options(int narg, char **arg) if (iarg+2 > narg) error->all(FLERR,"Illegal tad command"); if (strcmp(arg[iarg+1],"none") == 0) neb_logfilename = nullptr; else { - int n = strlen(arg[iarg+1]) + 1; - neb_logfilename = new char[n]; - strcpy(neb_logfilename,arg[iarg+1]); + neb_logfilename = utils::strdup(arg[iarg+1]); } iarg += 2; } else error->all(FLERR,"Illegal tad command"); diff --git a/src/RIGID/compute_erotate_rigid.cpp b/src/RIGID/compute_erotate_rigid.cpp index b20e11e359..d1567cfe2e 100644 --- a/src/RIGID/compute_erotate_rigid.cpp +++ b/src/RIGID/compute_erotate_rigid.cpp @@ -12,14 +12,16 @@ ------------------------------------------------------------------------- */ #include "compute_erotate_rigid.h" -#include -#include "update.h" -#include "force.h" -#include "modify.h" + +#include "error.h" #include "fix.h" #include "fix_rigid.h" #include "fix_rigid_small.h" -#include "error.h" +#include "force.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; @@ -33,9 +35,7 @@ ComputeERotateRigid::ComputeERotateRigid(LAMMPS *lmp, int narg, char **arg) : scalar_flag = 1; extscalar = 1; - int n = strlen(arg[3]) + 1; - rfix = new char[n]; - strcpy(rfix,arg[3]); + rfix = utils::strdup(arg[3]); } /* ---------------------------------------------------------------------- */ diff --git a/src/RIGID/compute_ke_rigid.cpp b/src/RIGID/compute_ke_rigid.cpp index c005f6ac25..9da5aabb9a 100644 --- a/src/RIGID/compute_ke_rigid.cpp +++ b/src/RIGID/compute_ke_rigid.cpp @@ -12,14 +12,16 @@ ------------------------------------------------------------------------- */ #include "compute_ke_rigid.h" -#include -#include "update.h" -#include "force.h" -#include "modify.h" + +#include "error.h" #include "fix.h" #include "fix_rigid.h" #include "fix_rigid_small.h" -#include "error.h" +#include "force.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; @@ -33,9 +35,7 @@ ComputeKERigid::ComputeKERigid(LAMMPS *lmp, int narg, char **arg) : scalar_flag = 1; extscalar = 1; - int n = strlen(arg[3]) + 1; - rfix = new char[n]; - strcpy(rfix,arg[3]); + rfix = utils::strdup(arg[3]); } /* ---------------------------------------------------------------------- */ diff --git a/src/RIGID/compute_rigid_local.cpp b/src/RIGID/compute_rigid_local.cpp index 0a40062055..9de227531d 100644 --- a/src/RIGID/compute_rigid_local.cpp +++ b/src/RIGID/compute_rigid_local.cpp @@ -40,9 +40,7 @@ ComputeRigidLocal::ComputeRigidLocal(LAMMPS *lmp, int narg, char **arg) : local_flag = 1; nvalues = narg - 4; - int n = strlen(arg[3]) + 1; - idrigid = new char[n]; - strcpy(idrigid,arg[3]); + idrigid = utils::strdup(arg[3]); rstyle = new int[nvalues]; diff --git a/src/RIGID/fix_ehex.cpp b/src/RIGID/fix_ehex.cpp index 7229dc8b02..4bfabea3dd 100644 --- a/src/RIGID/fix_ehex.cpp +++ b/src/RIGID/fix_ehex.cpp @@ -24,17 +24,19 @@ #include "fix_ehex.h" -#include -#include #include "atom.h" #include "domain.h" -#include "region.h" -#include "group.h" -#include "force.h" -#include "update.h" -#include "modify.h" -#include "memory.h" #include "error.h" +#include "force.h" +#include "group.h" +#include "memory.h" +#include "modify.h" +#include "region.h" +#include "update.h" + +#include +#include + #include "fix_shake.h" using namespace LAMMPS_NS; @@ -91,9 +93,7 @@ FixEHEX::FixEHEX(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), iregion = domain->find_region(arg[iarg+1]); if (iregion == -1) error->all(FLERR,"Region ID for fix ehex does not exist"); - int n = strlen(arg[iarg+1]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[iarg+1]); + idregion = utils::strdup(arg[iarg+1]); iarg += 2; } diff --git a/src/RIGID/fix_rigid_nh.cpp b/src/RIGID/fix_rigid_nh.cpp index a29c8d9863..6fb2bd7a94 100644 --- a/src/RIGID/fix_rigid_nh.cpp +++ b/src/RIGID/fix_rigid_nh.cpp @@ -1202,9 +1202,7 @@ int FixRigidNH::modify_param(int narg, char **arg) tcomputeflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) @@ -1236,9 +1234,7 @@ int FixRigidNH::modify_param(int narg, char **arg) pcomputeflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/RIGID/fix_rigid_nh_small.cpp b/src/RIGID/fix_rigid_nh_small.cpp index cfefe285f3..af2adb540d 100644 --- a/src/RIGID/fix_rigid_nh_small.cpp +++ b/src/RIGID/fix_rigid_nh_small.cpp @@ -1319,9 +1319,7 @@ int FixRigidNHSmall::modify_param(int narg, char **arg) tcomputeflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) @@ -1353,9 +1351,7 @@ int FixRigidNHSmall::modify_param(int narg, char **arg) pcomputeflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/RIGID/fix_rigid_nph.cpp b/src/RIGID/fix_rigid_nph.cpp index a2eb079f5c..77c42f0873 100644 --- a/src/RIGID/fix_rigid_nph.cpp +++ b/src/RIGID/fix_rigid_nph.cpp @@ -55,34 +55,15 @@ FixRigidNPH::FixRigidNPH(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press,id_temp)); pcomputeflag = 1; } diff --git a/src/RIGID/fix_rigid_nph_small.cpp b/src/RIGID/fix_rigid_nph_small.cpp index 414e408a9a..55c0f55379 100644 --- a/src/RIGID/fix_rigid_nph_small.cpp +++ b/src/RIGID/fix_rigid_nph_small.cpp @@ -58,34 +58,15 @@ FixRigidNPHSmall::FixRigidNPHSmall(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press,id_temp)); pcomputeflag = 1; } diff --git a/src/RIGID/fix_rigid_npt.cpp b/src/RIGID/fix_rigid_npt.cpp index e50b1a5045..59d7fa2764 100644 --- a/src/RIGID/fix_rigid_npt.cpp +++ b/src/RIGID/fix_rigid_npt.cpp @@ -65,34 +65,15 @@ FixRigidNPT::FixRigidNPT(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press,id_temp)); pcomputeflag = 1; } diff --git a/src/RIGID/fix_rigid_npt_small.cpp b/src/RIGID/fix_rigid_npt_small.cpp index efb9c414f6..5b1ef61865 100644 --- a/src/RIGID/fix_rigid_npt_small.cpp +++ b/src/RIGID/fix_rigid_npt_small.cpp @@ -69,34 +69,15 @@ FixRigidNPTSmall::FixRigidNPTSmall(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press,id_temp)); pcomputeflag = 1; } diff --git a/src/SHOCK/fix_msst.cpp b/src/SHOCK/fix_msst.cpp index 10ec0f0351..7a1efa064f 100644 --- a/src/SHOCK/fix_msst.cpp +++ b/src/SHOCK/fix_msst.cpp @@ -19,19 +19,20 @@ #include "fix_msst.h" -#include -#include #include "atom.h" -#include "force.h" #include "comm.h" -#include "modify.h" -#include "fix_external.h" #include "compute.h" -#include "kspace.h" -#include "update.h" #include "domain.h" -#include "memory.h" #include "error.h" +#include "fix_external.h" +#include "force.h" +#include "kspace.h" +#include "memory.h" +#include "modify.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -840,9 +841,7 @@ int FixMSST::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) @@ -864,9 +863,7 @@ int FixMSST::modify_param(int narg, char **arg) pflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(id_press); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/SHOCK/fix_nphug.cpp b/src/SHOCK/fix_nphug.cpp index 1fa7b77f6a..7467b7a293 100644 --- a/src/SHOCK/fix_nphug.cpp +++ b/src/SHOCK/fix_nphug.cpp @@ -12,15 +12,17 @@ ------------------------------------------------------------------------- */ #include "fix_nphug.h" -#include -#include -#include "modify.h" -#include "error.h" -#include "update.h" + #include "compute.h" -#include "force.h" #include "domain.h" +#include "error.h" +#include "force.h" #include "group.h" +#include "modify.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -118,51 +120,22 @@ FixNPHug::FixNPHug(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(std::string(id_temp)+" all temp"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press,id_temp)); pcomputeflag = 1; // create a new compute potential energy compute - n = strlen(id) + 4; - id_pe = new char[n]; - strcpy(id_pe,id); - strcat(id_pe,"_pe"); - - newarg = new char*[3]; - newarg[0] = id_pe; - newarg[1] = (char*)"all"; - newarg[2] = (char*)"pe"; - modify->add_compute(3,newarg); - delete [] newarg; + id_pe = utils::strdup(std::string(id)+"_pe"); + modify->add_compute(std::string(id_pe)+" all pe"); peflag = 1; } diff --git a/src/SPIN/fix_neb_spin.cpp b/src/SPIN/fix_neb_spin.cpp index 935365ce1b..620d0a47bd 100644 --- a/src/SPIN/fix_neb_spin.cpp +++ b/src/SPIN/fix_neb_spin.cpp @@ -23,18 +23,19 @@ #include "fix_neb_spin.h" -#include -#include -#include "universe.h" -#include "update.h" #include "atom.h" #include "comm.h" -#include "modify.h" #include "compute.h" -#include "group.h" -#include "memory.h" #include "error.h" #include "force.h" +#include "group.h" +#include "memory.h" +#include "modify.h" +#include "universe.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -120,17 +121,8 @@ FixNEBSpin::FixNEBSpin(LAMMPS *lmp, int narg, char **arg) : // create a new compute pe style // id = fix-ID + pe, compute group = all - int n = strlen(id) + 4; - id_pe = new char[n]; - strcpy(id_pe,id); - strcat(id_pe,"_pe"); - - char **newarg = new char*[3]; - newarg[0] = id_pe; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pe"; - modify->add_compute(3,newarg); - delete [] newarg; + id_pe = utils::strdup(std::string(id)+"_pe"); + modify->add_compute(std::string(id_pe)+" all pe"); // initialize local storage From 31726f56e6b2605799144f9877b5f52ab803033f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 28 Mar 2021 13:12:39 -0400 Subject: [PATCH 172/257] refactor group2ndx and ndx2group commands to use fmtlib, tokenizer and utils --- src/USER-COLVARS/group_ndx.cpp | 189 ++++++++++++-------------- src/USER-COLVARS/group_ndx.h | 2 + src/USER-COLVARS/ndx_group.cpp | 233 ++++++++++++++------------------- src/USER-COLVARS/ndx_group.h | 3 +- src/group.cpp | 2 +- src/group.h | 2 +- 6 files changed, 187 insertions(+), 244 deletions(-) diff --git a/src/USER-COLVARS/group_ndx.cpp b/src/USER-COLVARS/group_ndx.cpp index 96c3663ca0..995f60ac85 100644 --- a/src/USER-COLVARS/group_ndx.cpp +++ b/src/USER-COLVARS/group_ndx.cpp @@ -23,6 +23,8 @@ #include "error.h" #include "group.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- @@ -40,96 +42,6 @@ static int cmptagint(const void *p1, const void *p2) } } -/* ---------------------------------------------------------------------- - helper function. writes out one group to a gromacs style index file - ---------------------------------------------------------------------- */ - -static void write_group(FILE *fp, int gid, Atom *atom, Group *group, int me, - int np, MPI_Comm world, FILE *screen, FILE *logfile) -{ - char fmt[16]; - tagint *sendlist, *recvlist; - bigint num = group->count(gid); - int lnum, cols; - - if (me == 0) { - if (screen) fprintf(screen, " writing group %s... ", group->names[gid]); - if (logfile) fprintf(logfile, " writing group %s... ", group->names[gid]); - - // the "all" group in LAMMPS is called "System" in gromacs - if (gid == 0) { - fputs("[ System ]\n", fp); - } else { - fprintf(fp,"[ %s ]\n", group->names[gid]); - } - - // derive format string for index lists - bigint j = atom->natoms; - int i=0; - while (j > 0) { - ++i; - j /= 10; - } - snprintf(fmt,16,"%%%dd ", i); - cols = 80 / (i+1); - } - - if (num > 0) { - const int * const mask = atom->mask; - const tagint * const tag = atom->tag; - const int groupbit = group->bitmask[gid]; - const int nlocal = atom->nlocal; - int i; - - sendlist = new tagint[nlocal]; - recvlist = new tagint[num]; - lnum = 0; - for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit) sendlist[lnum++] = tag[i]; - - int nrecv,allrecv; - if (me == 0) { - MPI_Status status; - MPI_Request request; - - for (i=0; i < lnum; i++) - recvlist[i] = sendlist[i]; - - allrecv = lnum; - for (i=1; i < np; ++i) { - MPI_Irecv(recvlist+allrecv,num-allrecv,MPI_LMP_TAGINT,i,0, world,&request); - MPI_Send(&nrecv,0,MPI_INT,i,0,world); - MPI_Wait(&request,&status); - MPI_Get_count(&status,MPI_LMP_TAGINT,&nrecv); - allrecv += nrecv; - } - - // sort received list - qsort((void *)recvlist, num, sizeof(tagint), cmptagint); - } else { - MPI_Recv(&nrecv,0,MPI_INT,0,0,world,MPI_STATUS_IGNORE); - MPI_Rsend(sendlist,lnum,MPI_LMP_TAGINT,0,0,world); - } - delete [] sendlist; - } - - if (me == 0) { - int i, j; - for (i=0, j=0; i < num; ++i) { - fprintf(fp,fmt,recvlist[i]); - ++j; - if (j == cols) { - fputs("\n",fp); - j = 0; - } - } - if (j > 0) fputs("\n",fp); - if (screen) fputs("done\n",screen); - if (logfile) fputs("done\n",logfile); - } - if (num > 0) delete[] recvlist; -} - /* ---------------------------------------------------------------------- */ void Group2Ndx::command(int narg, char **arg) @@ -144,31 +56,100 @@ void Group2Ndx::command(int narg, char **arg) if (comm->me == 0) { fp = fopen(arg[0], "w"); if (fp == nullptr) - error->one(FLERR,"Cannot open index file for writing"); - - if (screen) - fprintf(screen, "Writing groups to index file %s:\n",arg[0]); - if (logfile) - fprintf(logfile,"Writing groups to index file %s:\n",arg[0]); + error->one(FLERR,fmt::format("Cannot open index file for writing: {}", + utils::getsyserror())); + utils::logmesg(lmp,fmt::format("Writing groups to index file {}:\n",arg[0])); } if (narg == 1) { // write out all groups for (int i=0; i < group->ngroup; ++i) { - write_group(fp,i,atom,group,comm->me,comm->nprocs,world,screen,logfile); + write_group(fp,i); } - } else { // write only selected groups for (int i=1; i < narg; ++i) { int gid = group->find(arg[i]); if (gid < 0) error->all(FLERR, "Non-existing group requested"); - write_group(fp,gid,atom,group,comm->me,comm->nprocs,world,screen,logfile); + write_group(fp,gid); } } - if (comm->me == 0) { - if (screen) fputs("\n",screen); - if (logfile) fputs("\n",logfile); - fclose(fp); - } + if (comm->me == 0) fclose(fp); } +/* ---------------------------------------------------------------------- + write out one group to a Gromacs style index file + ---------------------------------------------------------------------- */ +void Group2Ndx::write_group(FILE *fp, int gid) +{ + tagint *sendlist, *recvlist; + bigint gcount = group->count(gid); + int lnum, width, cols; + + if (comm->me == 0) { + utils::logmesg(lmp,fmt::format(" writing group {}...",group->names[gid])); + + // the "all" group in LAMMPS is called "System" in Gromacs + if (gid == 0) { + fputs("[ System ]\n", fp); + } else { + fmt::print(fp,"[ {} ]\n", group->names[gid]); + } + width = log10((double) atom->natoms)+2; + cols = 80 / width; + } + + if (gcount > 0) { + const int * const mask = atom->mask; + const tagint * const tag = atom->tag; + const int groupbit = group->bitmask[gid]; + const int nlocal = atom->nlocal; + int i; + + sendlist = new tagint[nlocal]; + recvlist = new tagint[gcount]; + lnum = 0; + for (i = 0; i < nlocal; i++) + if (mask[i] & groupbit) sendlist[lnum++] = tag[i]; + + int nrecv=0; + bigint allrecv; + if (comm->me == 0) { + MPI_Status status; + MPI_Request request; + + for (i=0; i < lnum; i++) + recvlist[i] = sendlist[i]; + + allrecv = lnum; + for (i=1; i < comm->nprocs; ++i) { + MPI_Irecv(recvlist+allrecv,gcount-allrecv,MPI_LMP_TAGINT,i,0, world,&request); + MPI_Send(&nrecv,0,MPI_INT,i,0,world); // block rank "i" until we are ready to receive + MPI_Wait(&request,&status); + MPI_Get_count(&status,MPI_LMP_TAGINT,&nrecv); + allrecv += nrecv; + } + + // sort received list + qsort((void *)recvlist, allrecv, sizeof(tagint), cmptagint); + } else { + MPI_Recv(&nrecv,0,MPI_INT,0,0,world,MPI_STATUS_IGNORE); + MPI_Rsend(sendlist,lnum,MPI_LMP_TAGINT,0,0,world); + } + delete [] sendlist; + } + + if (comm->me == 0) { + int i, j; + for (i=0, j=0; i < gcount; ++i) { + fmt::print(fp,"{:>{}}",recvlist[i],width); + ++j; + if (j == cols) { + fputs("\n",fp); + j = 0; + } + } + if (j > 0) fputs("\n",fp); + utils::logmesg(lmp,"done\n"); + } + if (gcount > 0) delete[] recvlist; +} diff --git a/src/USER-COLVARS/group_ndx.h b/src/USER-COLVARS/group_ndx.h index 25c38dcf9f..fa15f0e82e 100644 --- a/src/USER-COLVARS/group_ndx.h +++ b/src/USER-COLVARS/group_ndx.h @@ -30,6 +30,8 @@ class Group2Ndx : protected Pointers { public: Group2Ndx(class LAMMPS *lmp) : Pointers(lmp) {}; void command(int, char **); + private: + void write_group(FILE *, int); }; } diff --git a/src/USER-COLVARS/ndx_group.cpp b/src/USER-COLVARS/ndx_group.cpp index bf1c5d060a..184faa62cc 100644 --- a/src/USER-COLVARS/ndx_group.cpp +++ b/src/USER-COLVARS/ndx_group.cpp @@ -22,64 +22,52 @@ #include "comm.h" #include "error.h" #include "group.h" +#include "memory.h" +#include "tokenizer.h" -#include +#include using namespace LAMMPS_NS; #define BUFLEN 4096 #define DELTA 16384 -static char *find_section(FILE *fp, const char *name) +// read file until next section "name" or any next section if name == "" + +static std::string find_section(FILE *fp, const std::string &name) { char linebuf[BUFLEN]; - char *n,*p,*t,*r; - while ((p = fgets(linebuf,BUFLEN,fp))) { - t = strtok(p," \t\n\r\f"); - if ((t != nullptr) && *t == '[') { - t = strtok(nullptr," \t\n\r\f"); - if (t != nullptr) { - n = t; - t = strtok(nullptr," \t\n\r\f"); - if ((t != nullptr) && *t == ']') { - if ((name == nullptr) || strcmp(name,n) == 0) { - int l = strlen(n); - r = new char[l+1]; - strncpy(r,n,l+1); - return r; - } - } - } - } + std::string pattern = "^\\s*\\[\\s+\\S+\\s+\\]\\s*$"; + if (!name.empty()) + pattern = fmt::format("^\\s*\\[\\s+{}\\s+\\]\\s*$",name); + + fgets(linebuf,BUFLEN,fp); + while (!feof(fp)) { + if (utils::strmatch(linebuf,pattern)) + return Tokenizer(linebuf).as_vector()[1]; + fgets(linebuf,BUFLEN,fp); } - return nullptr; + return ""; } -static tagint *read_section(FILE *fp, bigint &num) +static std::vector read_section(FILE *fp, std::string &name) { char linebuf[BUFLEN]; - char *p,*t; - tagint *tagbuf; - bigint nmax; + std::vector tagbuf; + std::string pattern = "^\\s*\\[\\s+\\S+\\s+\\]\\s*$"; - num = 0; - nmax = DELTA; - tagbuf = (tagint *)malloc(sizeof(tagint)*nmax); - - while ((p = fgets(linebuf,BUFLEN,fp))) { - t = strtok(p," \t\n\r\f"); - while (t != nullptr) { - // start of a new section. we are done here. - if (*t == '[') return tagbuf; - - tagbuf[num++] = ATOTAGINT(t); - if (num == nmax) { - nmax += DELTA; - tagbuf = (tagint *)realloc(tagbuf,sizeof(tagint)*nmax); - } - t = strtok(nullptr," \t\n\r\f"); + while (fgets(linebuf,BUFLEN,fp)) { + // start of new section. we are done, update "name" + if (utils::strmatch(linebuf,pattern)) { + name = Tokenizer(linebuf).as_vector()[1]; + return tagbuf; } + ValueTokenizer values(linebuf); + while (values.has_next()) + tagbuf.push_back(values.next_tagint()); } + // set empty name to indicate end of file + name = ""; return tagbuf; } @@ -90,151 +78,122 @@ void Ndx2Group::command(int narg, char **arg) int len; bigint num; FILE *fp; - char *name = nullptr; - tagint *tags; + tagint *tagbuf; + std::string name = "", next; if (narg < 1) error->all(FLERR,"Illegal ndx2group command"); - if (atom->tag_enable == 0) - error->all(FLERR,"Must have atom IDs for ndx2group command"); - + error->all(FLERR,"Must have atom IDs for ndx2group command"); if (comm->me == 0) { fp = fopen(arg[0], "r"); if (fp == nullptr) - error->one(FLERR,"Cannot open index file for reading"); - - if (screen) - fprintf(screen, "Reading groups from index file %s:\n",arg[0]); - if (logfile) - fprintf(logfile,"Reading groups from index file %s:\n",arg[0]); + error->one(FLERR,fmt::format("Cannot open index file for reading: {}", + utils::getsyserror())); + utils::logmesg(lmp,fmt::format("Reading groups from index file {}:\n",arg[0])); } - if (narg == 1) { // restore all groups + if (narg == 1) { // restore all groups - do { - if (comm->me == 0) { - len = 0; + if (comm->me == 0) { + name = find_section(fp,""); + while (!name.empty()) { - // find the next section. - // if we had processed a section, before we need to step back - if (name != nullptr) { - rewind(fp); - char *tmp = find_section(fp,name); - delete[] tmp; - delete[] name; - name = nullptr; + // skip over group "all", which is called "System" in gromacs + if (name == "System") { + name = find_section(fp,""); + continue; } - name = find_section(fp,nullptr); - if (name != nullptr) { - len=strlen(name)+1; - // skip over group "all", which is called "System" in gromacs - if (strcmp(name,"System") == 0) continue; - - if (screen) - fprintf(screen," Processing group '%s'\n",name); - if (logfile) - fprintf(logfile," Processing group '%s'\n",name); - } + utils::logmesg(lmp,fmt::format(" Processing group '{}'\n",name)); + len = name.size()+1; MPI_Bcast(&len,1,MPI_INT,0,world); - if (len > 0) { - MPI_Bcast(name,len,MPI_CHAR,0,world); + if (len > 1) { + MPI_Bcast((void *)name.c_str(),len,MPI_CHAR,0,world); // read tags for atoms in group and broadcast - num = 0; - tags = read_section(fp,num); + std::vector tags = read_section(fp,next); + num = tags.size(); MPI_Bcast(&num,1,MPI_LMP_BIGINT,0,world); - MPI_Bcast(tags,num,MPI_LMP_TAGINT,0,world); - create(name,num,tags); - free(tags); - } - } else { - MPI_Bcast(&len,1,MPI_INT,0,world); - if (len > 0) { - delete[] name; - name = new char[len]; - MPI_Bcast(name,len,MPI_CHAR,0,world); - - MPI_Bcast(&num,1,MPI_LMP_BIGINT,0,world); - tags = (tagint *)malloc(sizeof(tagint)*(num ? num : 1)); - MPI_Bcast(tags,num,MPI_LMP_TAGINT,0,world); - create(name,num,tags); - free(tags); + MPI_Bcast((void *)tags.data(),num,MPI_LMP_TAGINT,0,world); + create(name,tags); + name = next; } } - } while (len); + len = -1; + MPI_Bcast(&len,1,MPI_INT,0,world); + + } else { + + while (1) { + MPI_Bcast(&len,1,MPI_INT,0,world); + if (len < 0) break; + if (len > 1) { + char *buf = new char[len]; + MPI_Bcast(buf,len,MPI_CHAR,0,world); + MPI_Bcast(&num,1,MPI_LMP_BIGINT,0,world); + tagint *tbuf = new tagint[num]; + MPI_Bcast(tbuf,num,MPI_LMP_TAGINT,0,world); + create(buf,std::vector(tbuf,tbuf+num)); + delete[] buf; + delete[] tbuf; + } + } + } } else { // restore selected groups - for (int idx=1; idx < narg; ++idx) { + for (int idx=1; idx < narg; ++idx) { if (comm->me == 0) { - len = 0; // find named section, search from beginning of file - if (name != nullptr) delete[] name; rewind(fp); name = find_section(fp,arg[idx]); - if (name != nullptr) len=strlen(name)+1; - - if (screen) - fprintf(screen," %s group '%s'\n", - len ? "Processing" : "Skipping",arg[idx]); - if (logfile) - fprintf(logfile,"%s group '%s'\n", - len ? "Processing" : "Skipping",arg[idx]); - + utils::logmesg(lmp,fmt::format(" {} group '{}'\n", name.size() + ? "Processing" : "Skipping",arg[idx])); + len = name.size()+1; MPI_Bcast(&len,1,MPI_INT,0,world); - if (len > 0) { - MPI_Bcast(name,len,MPI_CHAR,0,world); + if (len > 1) { + MPI_Bcast((void *)name.c_str(),len,MPI_CHAR,0,world); + // read tags for atoms in group and broadcast - num = 0; - tags = read_section(fp,num); + std::vector tags = read_section(fp,name); + num = tags.size(); MPI_Bcast(&num,1,MPI_LMP_BIGINT,0,world); - MPI_Bcast(tags,num,MPI_LMP_TAGINT,0,world); - create(name,num,tags); - free(tags); + MPI_Bcast((void *)tags.data(),num,MPI_LMP_TAGINT,0,world); + create(name,tags); } } else { - MPI_Bcast(&len,1,MPI_INT,0,world); - if (len > 0) { - delete[] name; - name = new char[len]; - MPI_Bcast(name,len,MPI_CHAR,0,world); - + if (len > 1) { + char *buf = new char[len]; + MPI_Bcast(buf,len,MPI_CHAR,0,world); MPI_Bcast(&num,1,MPI_LMP_BIGINT,0,world); - tags = (tagint *)malloc(sizeof(tagint)*(num ? num : 1)); - MPI_Bcast(tags,num,MPI_LMP_TAGINT,0,world); - create(name,num,tags); - free(tags); + tagint *tbuf = new tagint[num]; + MPI_Bcast(tbuf,num,MPI_LMP_TAGINT,0,world); + create(buf,std::vector(tbuf,tbuf+num)); + delete[] buf; + delete[] tbuf; } } } } - - delete[] name; - if (comm->me == 0) { - if (screen) fputs("\n",screen); - if (logfile) fputs("\n",logfile); - fclose(fp); - } + if (comm->me == 0) fclose(fp); } /* ---------------------------------------------------------------------- */ -void Ndx2Group::create(char *name, bigint num, tagint *tags) +void Ndx2Group::create(const std::string &name, const std::vector &tags) { // wipe out all members if the group exists. gid==0 is group "all" int gid = group->find(name); - if (gid > 0) group->assign(std::string(name) + " clear"); + if (gid > 0) group->assign(name + " clear"); // map from global to local const int nlocal = atom->nlocal; int *flags = (int *)calloc(nlocal,sizeof(int)); - for (bigint i=0; i < num; ++i) { + for (bigint i=0; i < tags.size(); ++i) { const int id = atom->map(tags[i]); - if (id < nlocal && id >= 0) - flags[id] = 1; + if (id < nlocal && id >= 0) flags[id] = 1; } group->create(name,flags); free(flags); diff --git a/src/USER-COLVARS/ndx_group.h b/src/USER-COLVARS/ndx_group.h index cd3250a1d5..ceca1f9570 100644 --- a/src/USER-COLVARS/ndx_group.h +++ b/src/USER-COLVARS/ndx_group.h @@ -23,6 +23,7 @@ CommandStyle(ndx2group,Ndx2Group) #define LMP_NDX_GROUP_H #include "pointers.h" +#include namespace LAMMPS_NS { @@ -30,7 +31,7 @@ class Ndx2Group : protected Pointers { public: Ndx2Group(class LAMMPS *lmp) : Pointers(lmp) {}; void command(int, char **); - void create(char *, bigint, tagint *); + void create(const std::string &, const std::vector &); }; } diff --git a/src/group.cpp b/src/group.cpp index aa05ca6951..ebab78dd0f 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -553,7 +553,7 @@ void Group::assign(const std::string &groupcmd) add flagged atoms to a new or existing group ------------------------------------------------------------------------- */ -void Group::create(const char *name, int *flag) +void Group::create(const std::string &name, int *flag) { int i; diff --git a/src/group.h b/src/group.h index 0c5a18384c..37199712c5 100644 --- a/src/group.h +++ b/src/group.h @@ -32,7 +32,7 @@ class Group : protected Pointers { ~Group(); void assign(int, char **); // assign atoms to a group void assign(const std::string &); // convenience function - void create(const char *, int *); // add flagged atoms to a group + void create(const std::string &, int *); // add flagged atoms to a group int find(const std::string &); // lookup name in list of groups int find_or_create(const char *); // lookup name or create new group void write_restart(FILE *); From b32570c15ebbc0d03da0e03263888c96b15f2ce8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 28 Mar 2021 17:02:49 -0400 Subject: [PATCH 173/257] simplify by using utils::strdup() and reorder includes --- src/ASPHERE/fix_nph_asphere.cpp | 17 ++--- src/ASPHERE/fix_npt_asphere.cpp | 17 ++--- src/ASPHERE/fix_nve_asphere.cpp | 3 +- src/ASPHERE/fix_nvt_asphere.cpp | 13 ++-- src/BODY/fix_nph_body.cpp | 19 ++---- src/BODY/fix_npt_body.cpp | 19 ++---- src/BODY/fix_nvt_body.cpp | 13 ++-- src/GPU/fix_npt_gpu.cpp | 6 +- src/GPU/fix_nvt_gpu.cpp | 8 ++- src/KOKKOS/fix_nph_kokkos.cpp | 12 ++-- src/KOKKOS/fix_npt_kokkos.cpp | 12 ++-- src/KOKKOS/fix_nvt_kokkos.cpp | 2 +- src/MC/fix_bond_swap.cpp | 7 +- src/RIGID/fix_rigid_nph.cpp | 6 +- src/RIGID/fix_rigid_nph_small.cpp | 6 +- src/RIGID/fix_rigid_npt.cpp | 6 +- src/RIGID/fix_rigid_npt_small.cpp | 6 +- src/SHOCK/fix_nphug.cpp | 4 +- src/USER-BOCS/compute_pressure_bocs.cpp | 8 +-- src/USER-BOCS/fix_bocs.cpp | 43 +++--------- src/USER-DPD/fix_rx.cpp | 57 ++++------------ src/USER-DPD/pair_exp6_rx.cpp | 31 +++------ src/USER-DPD/pair_multi_lucy_rx.cpp | 9 +-- src/USER-DPD/pair_table_rx.cpp | 10 +-- src/USER-DRUDE/compute_temp_drude.cpp | 17 +++-- src/USER-DRUDE/fix_tgnh_drude.cpp | 32 +++++---- src/USER-DRUDE/fix_tgnpt_drude.cpp | 19 ++---- src/USER-DRUDE/fix_tgnvt_drude.cpp | 13 ++-- src/USER-EFF/compute_temp_region_eff.cpp | 17 +++-- src/USER-EFF/fix_nph_eff.cpp | 32 ++------- src/USER-EFF/fix_npt_eff.cpp | 32 ++------- src/USER-EFF/fix_nvt_eff.cpp | 21 ++---- src/USER-EFF/fix_nvt_sllod_eff.cpp | 32 ++++----- src/USER-EFF/fix_temp_rescale_eff.cpp | 29 +++----- src/USER-INTEL/fix_npt_intel.cpp | 36 +++------- src/USER-INTEL/fix_nvt_intel.cpp | 24 +++---- src/USER-INTEL/fix_nvt_sllod_intel.cpp | 15 +---- src/USER-LB/fix_lb_fluid.cpp | 24 +++---- src/USER-MANIFOLD/fix_nvt_manifold_rattle.cpp | 35 +--------- src/USER-MISC/fix_grem.cpp | 67 +++++-------------- src/USER-MISC/fix_npt_cauchy.cpp | 60 ++++++----------- src/USER-OMP/fix_nph_asphere_omp.cpp | 32 ++------- src/USER-OMP/fix_nph_omp.cpp | 12 ++-- src/USER-OMP/fix_nph_sphere_omp.cpp | 32 ++------- src/USER-OMP/fix_npt_asphere_omp.cpp | 32 ++------- src/USER-OMP/fix_npt_omp.cpp | 12 ++-- src/USER-OMP/fix_npt_sphere_omp.cpp | 32 ++------- src/USER-OMP/fix_nvt_asphere_omp.cpp | 15 +---- src/USER-OMP/fix_nvt_omp.cpp | 6 +- src/USER-OMP/fix_nvt_sllod_omp.cpp | 36 +++++----- src/USER-OMP/fix_nvt_sphere_omp.cpp | 19 ++---- src/USER-OMP/fix_rigid_nph_omp.cpp | 31 ++------- src/USER-OMP/fix_rigid_npt_omp.cpp | 33 ++------- src/USER-QTB/fix_qbmsst.cpp | 46 ++++--------- src/USER-UEF/fix_nh_uef.cpp | 54 ++++++--------- src/VORONOI/compute_voronoi_atom.cpp | 4 +- src/fix_box_relax.cpp | 31 ++++----- src/fix_nph.cpp | 19 ++---- src/fix_nph_sphere.cpp | 19 ++---- src/fix_npt.cpp | 19 ++---- src/fix_npt_sphere.cpp | 19 ++---- src/fix_nve.cpp | 12 ++-- src/fix_nvt.cpp | 12 +--- src/fix_nvt_sllod.cpp | 22 +++--- src/fix_nvt_sphere.cpp | 13 ++-- src/fix_press_berendsen.cpp | 31 ++++----- src/fix_temp_berendsen.cpp | 6 +- src/fix_temp_csld.cpp | 6 +- src/fix_temp_csvr.cpp | 6 +- src/fix_temp_rescale.cpp | 6 +- 70 files changed, 447 insertions(+), 1009 deletions(-) diff --git a/src/ASPHERE/fix_nph_asphere.cpp b/src/ASPHERE/fix_nph_asphere.cpp index 5231434a45..538e467133 100644 --- a/src/ASPHERE/fix_nph_asphere.cpp +++ b/src/ASPHERE/fix_nph_asphere.cpp @@ -12,10 +12,9 @@ ------------------------------------------------------------------------- */ #include "fix_nph_asphere.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -36,21 +35,15 @@ FixNPHAsphere::FixNPHAsphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - modify->add_compute(tcmd + " all temp/asphere"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/asphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/ASPHERE/fix_npt_asphere.cpp b/src/ASPHERE/fix_npt_asphere.cpp index 6492dfcde4..99909e5a2a 100644 --- a/src/ASPHERE/fix_npt_asphere.cpp +++ b/src/ASPHERE/fix_npt_asphere.cpp @@ -12,10 +12,9 @@ ------------------------------------------------------------------------- */ #include "fix_npt_asphere.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -35,21 +34,15 @@ FixNPTAsphere::FixNPTAsphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - modify->add_compute(tcmd + " all temp/asphere"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/asphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/ASPHERE/fix_nve_asphere.cpp b/src/ASPHERE/fix_nve_asphere.cpp index 95fb89d5c9..62bb1db172 100644 --- a/src/ASPHERE/fix_nve_asphere.cpp +++ b/src/ASPHERE/fix_nve_asphere.cpp @@ -16,10 +16,11 @@ ------------------------------------------------------------------------- */ #include "fix_nve_asphere.h" -#include "math_extra.h" + #include "atom.h" #include "atom_vec_ellipsoid.h" #include "error.h" +#include "math_extra.h" using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/ASPHERE/fix_nvt_asphere.cpp b/src/ASPHERE/fix_nvt_asphere.cpp index 903d88f97a..ef6d97ec99 100644 --- a/src/ASPHERE/fix_nvt_asphere.cpp +++ b/src/ASPHERE/fix_nvt_asphere.cpp @@ -12,12 +12,10 @@ ------------------------------------------------------------------------- */ #include "fix_nvt_asphere.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" - using namespace LAMMPS_NS; using namespace FixConst; @@ -35,11 +33,8 @@ FixNVTAsphere::FixNVTAsphere(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - std::string cmd = id + std::string("_temp"); - id_temp = new char[cmd.size()+1]; - strcpy(id_temp,cmd.c_str()); - - cmd += fmt::format(" {} temp/asphere",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/asphere", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/BODY/fix_nph_body.cpp b/src/BODY/fix_nph_body.cpp index 1ebde47de6..a876ac9dc7 100644 --- a/src/BODY/fix_nph_body.cpp +++ b/src/BODY/fix_nph_body.cpp @@ -16,12 +16,12 @@ ------------------------------------------------------------------------- */ #include "fix_nph_body.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -41,22 +41,15 @@ FixNPHBody::FixNPHBody(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += fmt::format(" {} temp/body",group->names[igroup]); - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/body",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/BODY/fix_npt_body.cpp b/src/BODY/fix_npt_body.cpp index adc5cd4587..bc669fc971 100644 --- a/src/BODY/fix_npt_body.cpp +++ b/src/BODY/fix_npt_body.cpp @@ -16,12 +16,12 @@ ------------------------------------------------------------------------- */ #include "fix_npt_body.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -41,22 +41,15 @@ FixNPTBody::FixNPTBody(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += fmt::format(" {} temp/body",group->names[igroup]); - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/body",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/BODY/fix_nvt_body.cpp b/src/BODY/fix_nvt_body.cpp index a3884f330a..442aed2c94 100644 --- a/src/BODY/fix_nvt_body.cpp +++ b/src/BODY/fix_nvt_body.cpp @@ -16,12 +16,12 @@ ------------------------------------------------------------------------- */ #include "fix_nvt_body.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -39,11 +39,8 @@ FixNVTBody::FixNVTBody(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += fmt::format(" {} temp/body",group->names[igroup]); - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/body", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/GPU/fix_npt_gpu.cpp b/src/GPU/fix_npt_gpu.cpp index 3847f31a65..ce601548d4 100644 --- a/src/GPU/fix_npt_gpu.cpp +++ b/src/GPU/fix_npt_gpu.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_npt_gpu.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -35,7 +35,7 @@ FixNPTGPU::FixNPTGPU(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style diff --git a/src/GPU/fix_nvt_gpu.cpp b/src/GPU/fix_nvt_gpu.cpp index 6858c26497..191039e343 100644 --- a/src/GPU/fix_nvt_gpu.cpp +++ b/src/GPU/fix_nvt_gpu.cpp @@ -11,11 +11,13 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nvt_gpu.h" + +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -33,7 +35,7 @@ FixNVTGPU::FixNVTGPU(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - id_temp = utils::strdup(std::string(id)+"_temp"); + id_temp = utils::strdup(std::string(id) + "_temp"); modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/KOKKOS/fix_nph_kokkos.cpp b/src/KOKKOS/fix_nph_kokkos.cpp index f679940eaf..e2c3bd8d14 100644 --- a/src/KOKKOS/fix_nph_kokkos.cpp +++ b/src/KOKKOS/fix_nph_kokkos.cpp @@ -16,8 +16,6 @@ #include "modify.h" #include "error.h" -#include - using namespace LAMMPS_NS; using namespace FixConst; @@ -38,17 +36,17 @@ FixNPHKokkos::FixNPHKokkos(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - this->id_temp = utils::strdup(std::string(this->id)+"_temp"); - this->modify->add_compute(std::string(this->id_temp)+" all temp/kk"); + this->id_temp = utils::strdup(std::string(this->id) + "_temp"); + this->modify->add_compute(fmt::format("{} all temp/kk",this->id_temp)); this->tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - this->id_press = utils::strdup(std::string(this->id)+"_press"); - this->modify->add_compute(std::string(this->id_press) - +" all pressure "+this->id_temp); + this->id_press = utils::strdup(std::string(this->id) + "_press"); + this->modify->add_compute(fmt::format("{} all pressure {}", + this->id_press, this->id_temp)); this->pcomputeflag = 1; } diff --git a/src/KOKKOS/fix_npt_kokkos.cpp b/src/KOKKOS/fix_npt_kokkos.cpp index baa47e026f..565703aa35 100644 --- a/src/KOKKOS/fix_npt_kokkos.cpp +++ b/src/KOKKOS/fix_npt_kokkos.cpp @@ -16,8 +16,6 @@ #include "modify.h" #include "error.h" -#include - using namespace LAMMPS_NS; using namespace FixConst; @@ -38,17 +36,17 @@ FixNPTKokkos::FixNPTKokkos(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - this->id_temp = utils::strdup(std::string(this->id)+"_temp"); - this->modify->add_compute(std::string(this->id_temp)+" all temp/kk"); + this->id_temp = utils::strdup(std::string(this->id) + "_temp"); + this->modify->add_compute(fmt::format("{} all temp/kk",this->id_temp)); this->tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - this->id_press = utils::strdup(std::string(this->id)+"_press"); - this->modify->add_compute(std::string(this->id_press) - +" all pressure "+this->id_temp); + this->id_press = utils::strdup(std::string(this->id) + "_press"); + this->modify->add_compute(fmt::format("{} all pressure {}", + this->id_press, this->id_temp)); this->pcomputeflag = 1; } diff --git a/src/KOKKOS/fix_nvt_kokkos.cpp b/src/KOKKOS/fix_nvt_kokkos.cpp index f589600dde..8eeffcb9f8 100644 --- a/src/KOKKOS/fix_nvt_kokkos.cpp +++ b/src/KOKKOS/fix_nvt_kokkos.cpp @@ -38,7 +38,7 @@ FixNVTKokkos::FixNVTKokkos(LAMMPS *lmp, int narg, char **arg) : // id = fix-ID + temp this->id_temp = utils::strdup(std::string(this->id)+"_temp"); - this->modify->add_compute(std::string(this->id_temp)+" all temp/kk"); + this->modify->add_compute(fmt::format("{} all temp/kk",this->id_temp)); this->tcomputeflag = 1; } diff --git a/src/MC/fix_bond_swap.cpp b/src/MC/fix_bond_swap.cpp index 84d89a9626..1f3026888a 100644 --- a/src/MC/fix_bond_swap.cpp +++ b/src/MC/fix_bond_swap.cpp @@ -86,11 +86,8 @@ FixBondSwap::FixBondSwap(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp, compute group = fix group - std::string cmd = id + std::string("_temp"); - id_temp = new char[cmd.size()+1]; - strcpy(id_temp,cmd.c_str()); - - modify->add_compute(cmd + " all temp"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tflag = 1; // initialize atom list diff --git a/src/RIGID/fix_rigid_nph.cpp b/src/RIGID/fix_rigid_nph.cpp index 77c42f0873..1c93df4599 100644 --- a/src/RIGID/fix_rigid_nph.cpp +++ b/src/RIGID/fix_rigid_nph.cpp @@ -18,9 +18,9 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_nph.h" -#include -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; @@ -56,7 +56,7 @@ FixRigidNPH::FixRigidNPH(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style diff --git a/src/RIGID/fix_rigid_nph_small.cpp b/src/RIGID/fix_rigid_nph_small.cpp index 55c0f55379..ad5a48f1c2 100644 --- a/src/RIGID/fix_rigid_nph_small.cpp +++ b/src/RIGID/fix_rigid_nph_small.cpp @@ -18,9 +18,9 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_nph_small.h" -#include -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; @@ -59,7 +59,7 @@ FixRigidNPHSmall::FixRigidNPHSmall(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style diff --git a/src/RIGID/fix_rigid_npt.cpp b/src/RIGID/fix_rigid_npt.cpp index 59d7fa2764..4f65929476 100644 --- a/src/RIGID/fix_rigid_npt.cpp +++ b/src/RIGID/fix_rigid_npt.cpp @@ -18,9 +18,9 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_npt.h" -#include -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; @@ -66,7 +66,7 @@ FixRigidNPT::FixRigidNPT(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style diff --git a/src/RIGID/fix_rigid_npt_small.cpp b/src/RIGID/fix_rigid_npt_small.cpp index 5b1ef61865..6f7c025bc8 100644 --- a/src/RIGID/fix_rigid_npt_small.cpp +++ b/src/RIGID/fix_rigid_npt_small.cpp @@ -18,9 +18,9 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_npt_small.h" -#include -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; @@ -70,7 +70,7 @@ FixRigidNPTSmall::FixRigidNPTSmall(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style diff --git a/src/SHOCK/fix_nphug.cpp b/src/SHOCK/fix_nphug.cpp index 7467b7a293..20038c7df6 100644 --- a/src/SHOCK/fix_nphug.cpp +++ b/src/SHOCK/fix_nphug.cpp @@ -121,7 +121,7 @@ FixNPHug::FixNPHug(LAMMPS *lmp, int narg, char **arg) : // and thus its KE/temperature contribution should use group all id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style @@ -135,7 +135,7 @@ FixNPHug::FixNPHug(LAMMPS *lmp, int narg, char **arg) : // create a new compute potential energy compute id_pe = utils::strdup(std::string(id)+"_pe"); - modify->add_compute(std::string(id_pe)+" all pe"); + modify->add_compute(fmt::format("{} all pe",id_pe)); peflag = 1; } diff --git a/src/USER-BOCS/compute_pressure_bocs.cpp b/src/USER-BOCS/compute_pressure_bocs.cpp index a84442e658..43cf7efb8f 100644 --- a/src/USER-BOCS/compute_pressure_bocs.cpp +++ b/src/USER-BOCS/compute_pressure_bocs.cpp @@ -59,9 +59,7 @@ ComputePressureBocs::ComputePressureBocs(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[3],"NULL") == 0) id_temp = nullptr; else { - int n = strlen(arg[3]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[3]); + id_temp = utils::strdup(arg[3]); int icompute = modify->find_compute(id_temp); if (icompute < 0) @@ -446,7 +444,5 @@ void ComputePressureBocs::virial_compute(int n, int ndiag) void ComputePressureBocs::reset_extra_compute_fix(const char *id_new) { delete [] id_temp; - int n = strlen(id_new) + 1; - id_temp = new char[n]; - strcpy(id_temp,id_new); + id_temp = utils::strdup(id_new); } diff --git a/src/USER-BOCS/fix_bocs.cpp b/src/USER-BOCS/fix_bocs.cpp index 28a0d6c01a..87d4653da5 100644 --- a/src/USER-BOCS/fix_bocs.cpp +++ b/src/USER-BOCS/fix_bocs.cpp @@ -16,11 +16,6 @@ #include "fix_bocs.h" -#include - -#include -#include - #include "atom.h" #include "citeme.h" #include "comm.h" @@ -29,7 +24,6 @@ #include "domain.h" #include "error.h" #include "fix_deform.h" - #include "force.h" #include "group.h" #include "irregular.h" @@ -40,6 +34,10 @@ #include "respa.h" #include "update.h" +#include +#include +#include + using namespace LAMMPS_NS; using namespace FixConst; @@ -70,7 +68,8 @@ const int NUM_INPUT_DATA_COLUMNS = 2; // columns in the pressure correction FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), - rfix(nullptr), id_dilate(nullptr), irregular(nullptr), id_temp(nullptr), id_press(nullptr), + rfix(nullptr), id_dilate(nullptr), irregular(nullptr), + id_temp(nullptr), id_press(nullptr), eta(nullptr), eta_dot(nullptr), eta_dotdot(nullptr), eta_mass(nullptr), etap(nullptr), etap_dot(nullptr), etap_dotdot(nullptr), etap_mass(nullptr) @@ -403,38 +402,16 @@ FixBocs::FixBocs(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id)+"_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "PRESSURE/BOCS"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id)+"_press"); + modify->add_compute(fmt::format("{} all PRESSURE/BOCS {}",id_press,id_temp)); pcomputeflag = 1; /*~ MRD End of stuff copied from fix_npt.cpp~*/ diff --git a/src/USER-DPD/fix_rx.cpp b/src/USER-DPD/fix_rx.cpp index c9d12506ab..675c3d6dea 100644 --- a/src/USER-DPD/fix_rx.cpp +++ b/src/USER-DPD/fix_rx.cpp @@ -257,7 +257,6 @@ void FixRX::post_constructor() bool match; char **tmpspecies = new char*[maxspecies]; - int tmpmaxstrlen = 0; for (int jj=0; jj < maxspecies; jj++) tmpspecies[jj] = nullptr; @@ -316,9 +315,7 @@ void FixRX::post_constructor() if (!match) { if (nUniqueSpecies+1>=maxspecies) error->all(FLERR,"Exceeded the maximum number of species permitted in fix rx."); - tmpspecies[nUniqueSpecies] = new char[strlen(word)+1]; - strcpy(tmpspecies[nUniqueSpecies],word); - tmpmaxstrlen = MAX(tmpmaxstrlen,(int)strlen(word)); + tmpspecies[nUniqueSpecies] = utils::strdup(word); nUniqueSpecies++; } word = strtok(nullptr, " \t\n\r\f"); @@ -335,61 +332,31 @@ void FixRX::post_constructor() id_fix_species = nullptr; id_fix_species_old = nullptr; - n = strlen(id) + strlen("_SPECIES") + 1; - id_fix_species = new char[n]; - n = strlen(id) + strlen("_SPECIES_OLD") + 1; - id_fix_species_old = new char[n]; + id_fix_species = utils::strdup(std::string(id)+"_SPECIES"); + id_fix_species_old = utils::strdup(std::string(id)+"_SPECIES_OLD"); - strcpy(id_fix_species,id); - strcat(id_fix_species,"_SPECIES"); - strcpy(id_fix_species_old,id); - strcat(id_fix_species_old,"_SPECIES_OLD"); - - char **newarg = new char*[nspecies+5]; - char **newarg2 = new char*[nspecies+5]; - newarg[0] = id_fix_species; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "property/atom"; - newarg2[0] = id_fix_species_old; - newarg2[1] = group->names[igroup]; - newarg2[2] = (char *) "property/atom"; - char *str1 = new char[tmpmaxstrlen+3]; - char *str2 = new char[tmpmaxstrlen+6]; + const std::string fmtstr = "{} {} property/atom "; + auto newcmd1 = fmt::format(fmtstr,id_fix_species,group->names[igroup]); + auto newcmd2 = fmt::format(fmtstr,id_fix_species_old,group->names[igroup]); for (int ii=0; iiadd_fix(nspecies+5,newarg,1); + modify->add_fix(newcmd1); fix_species = (FixPropertyAtom *) modify->fix[modify->nfix-1]; restartFlag = modify->fix[modify->nfix-1]->restart_reset; - modify->add_fix(nspecies+5,newarg2,1); + modify->add_fix(newcmd2); fix_species_old = (FixPropertyAtom *) modify->fix[modify->nfix-1]; if (nspecies==0) error->all(FLERR,"There are no rx species specified."); for (int jj=0;jjall(FLERR,"There are no rx species specified."); read_file(arg[2]); - n = strlen(arg[3]) + 1; - site1 = new char[n]; - strcpy(site1,arg[3]); + site1 = utils::strdup(arg[3]); int ispecies; for (ispecies = 0; ispecies < nspecies; ispecies++) { @@ -607,9 +605,7 @@ void PairExp6rx::coeff(int narg, char **arg) if (ispecies == nspecies && strcmp(site1,"1fluid") != 0) error->all(FLERR,"Site1 name not recognized in pair coefficients"); - n = strlen(arg[4]) + 1; - site2 = new char[n]; - strcpy(site2,arg[4]); + site2 = utils::strdup(arg[4]); for (ispecies = 0; ispecies < nspecies; ispecies++) { if (strcmp(site2,&atom->dname[ispecies][0]) == 0) break; @@ -806,17 +802,12 @@ void PairExp6rx::read_file(char *file) params[nparams].ispecies = ispecies; - n = strlen(&atom->dname[ispecies][0]) + 1; - params[nparams].name = new char[n]; - strcpy(params[nparams].name,&atom->dname[ispecies][0]); - - n = strlen(words[1]) + 1; - params[nparams].potential = new char[n]; - strcpy(params[nparams].potential,words[1]); + params[nparams].name = utils::strdup(&atom->dname[ispecies][0]); + params[nparams].potential = utils::strdup(words[1]); if (strcmp(params[nparams].potential,"exp6") == 0) { - params[nparams].alpha = atof(words[2]); - params[nparams].epsilon = atof(words[3]); - params[nparams].rm = atof(words[4]); + params[nparams].alpha = utils::numeric(FLERR,words[2],false,lmp); + params[nparams].epsilon = utils::numeric(FLERR,words[3],false,lmp); + params[nparams].rm = utils::numeric(FLERR,words[4],false,lmp); if (params[nparams].epsilon <= 0.0 || params[nparams].rm <= 0.0 || params[nparams].alpha < 0.0) error->all(FLERR,"Illegal exp6/rx parameters. Rm and Epsilon must be greater than zero. Alpha cannot be negative."); @@ -842,11 +833,9 @@ void PairExp6rx::read_file2(char *file) fp = nullptr; if (comm->me == 0) { fp = fopen(file,"r"); - if (fp == nullptr) { - char str[128]; - snprintf(str,128,"Cannot open polynomial file %s",file); - error->one(FLERR,str); - } + if (fp == nullptr) + error->one(FLERR,fmt::format("Cannot open polynomial file {}: {}", + file,utils::getsyserror())); } // one set of params can span multiple lines diff --git a/src/USER-DPD/pair_multi_lucy_rx.cpp b/src/USER-DPD/pair_multi_lucy_rx.cpp index bd720ae138..c0f6af8a7e 100644 --- a/src/USER-DPD/pair_multi_lucy_rx.cpp +++ b/src/USER-DPD/pair_multi_lucy_rx.cpp @@ -387,14 +387,9 @@ void PairMultiLucyRX::coeff(int narg, char **arg) bcast_table(tb); nspecies = atom->nspecies_dpd; - int n; - n = strlen(arg[4]) + 1; - site1 = new char[n]; - strcpy(site1,arg[4]); - n = strlen(arg[5]) + 1; - site2 = new char[n]; - strcpy(site2,arg[5]); + site1 = utils::strdup(arg[4]); + site2 = utils::strdup(arg[5]); // set table cutoff diff --git a/src/USER-DPD/pair_table_rx.cpp b/src/USER-DPD/pair_table_rx.cpp index cefbe5a73d..85879d11fa 100644 --- a/src/USER-DPD/pair_table_rx.cpp +++ b/src/USER-DPD/pair_table_rx.cpp @@ -322,10 +322,8 @@ void PairTableRX::coeff(int narg, char **arg) nspecies = atom->nspecies_dpd; if (nspecies==0) error->all(FLERR,"There are no rx species specified."); - int n; - n = strlen(arg[4]) + 1; - site1 = new char[n]; - strcpy(site1,arg[4]); + + site1 = utils::strdup(arg[4]); int ispecies; for (ispecies = 0; ispecies < nspecies; ispecies++) { @@ -334,9 +332,7 @@ void PairTableRX::coeff(int narg, char **arg) if (ispecies == nspecies && strcmp(site1,"1fluid") != 0) error->all(FLERR,"Site1 name not recognized in pair coefficients"); - n = strlen(arg[5]) + 1; - site2 = new char[n]; - strcpy(site2,arg[5]); + site2 = utils::strdup(arg[5]); for (ispecies = 0; ispecies < nspecies; ispecies++) { if (strcmp(site2,&atom->dname[ispecies][0]) == 0) break; diff --git a/src/USER-DRUDE/compute_temp_drude.cpp b/src/USER-DRUDE/compute_temp_drude.cpp index fe75c10fe3..4325c9d6ae 100644 --- a/src/USER-DRUDE/compute_temp_drude.cpp +++ b/src/USER-DRUDE/compute_temp_drude.cpp @@ -13,15 +13,16 @@ #include "compute_temp_drude.h" -#include #include "atom.h" -#include "update.h" -#include "force.h" -#include "modify.h" -#include "fix_drude.h" +#include "comm.h" #include "domain.h" #include "error.h" -#include "comm.h" +#include "fix_drude.h" +#include "force.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; @@ -116,9 +117,7 @@ int ComputeTempDrude::modify_param(int narg, char **arg) if (strcmp(arg[0],"temp") == 0) { if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) diff --git a/src/USER-DRUDE/fix_tgnh_drude.cpp b/src/USER-DRUDE/fix_tgnh_drude.cpp index 8185b9bcbb..49a4061878 100644 --- a/src/USER-DRUDE/fix_tgnh_drude.cpp +++ b/src/USER-DRUDE/fix_tgnh_drude.cpp @@ -16,23 +16,25 @@ ---------------------------------------------------------------------------------------- */ #include "fix_tgnh_drude.h" -#include -#include + #include "atom.h" +#include "comm.h" +#include "compute.h" +#include "domain.h" +#include "error.h" +#include "fix_deform.h" #include "force.h" #include "group.h" -#include "comm.h" -#include "neighbor.h" #include "irregular.h" -#include "modify.h" -#include "fix_deform.h" -#include "compute.h" #include "kspace.h" -#include "update.h" -#include "respa.h" -#include "domain.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -1428,9 +1430,7 @@ int FixTGNHDrude::modify_param(int narg, char **arg) tcomputeflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) @@ -1462,9 +1462,7 @@ int FixTGNHDrude::modify_param(int narg, char **arg) pcomputeflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/USER-DRUDE/fix_tgnpt_drude.cpp b/src/USER-DRUDE/fix_tgnpt_drude.cpp index 987af367c3..301e0aa029 100644 --- a/src/USER-DRUDE/fix_tgnpt_drude.cpp +++ b/src/USER-DRUDE/fix_tgnpt_drude.cpp @@ -12,10 +12,9 @@ ------------------------------------------------------------------------- */ #include "fix_tgnpt_drude.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -35,23 +34,15 @@ FixTGNPTDrude::FixTGNPTDrude(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp, tcmd.c_str()); - - tcmd += " all temp"; - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press, pcmd.c_str()); - - pcmd += " all pressure " + std::string(id_temp); - modify->add_compute(pcmd); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-DRUDE/fix_tgnvt_drude.cpp b/src/USER-DRUDE/fix_tgnvt_drude.cpp index bd6809aaed..2339a6f9a7 100644 --- a/src/USER-DRUDE/fix_tgnvt_drude.cpp +++ b/src/USER-DRUDE/fix_tgnvt_drude.cpp @@ -12,11 +12,12 @@ ------------------------------------------------------------------------- */ #include "fix_tgnvt_drude.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -34,11 +35,7 @@ FixTGNVTDrude::FixTGNVTDrude(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp, tcmd.c_str()); - - tcmd += fmt::format(" {} temp", group->names[igroup]); - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-EFF/compute_temp_region_eff.cpp b/src/USER-EFF/compute_temp_region_eff.cpp index 1ca62f39d3..ca13aac06b 100644 --- a/src/USER-EFF/compute_temp_region_eff.cpp +++ b/src/USER-EFF/compute_temp_region_eff.cpp @@ -16,17 +16,18 @@ ------------------------------------------------------------------------- */ -#include - #include "compute_temp_region_eff.h" + #include "atom.h" -#include "update.h" -#include "force.h" #include "domain.h" -#include "region.h" +#include "error.h" +#include "force.h" #include "group.h" #include "memory.h" -#include "error.h" +#include "region.h" +#include "update.h" + +#include using namespace LAMMPS_NS; @@ -43,9 +44,7 @@ ComputeTempRegionEff::ComputeTempRegionEff(LAMMPS *lmp, int narg, char **arg) : iregion = domain->find_region(arg[3]); if (iregion == -1) error->all(FLERR,"Region ID for compute temp/region/eff does not exist"); - int n = strlen(arg[3]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[3]); + idregion = utils::strdup(arg[3]); scalar_flag = vector_flag = 1; size_vector = 6; diff --git a/src/USER-EFF/fix_nph_eff.cpp b/src/USER-EFF/fix_nph_eff.cpp index 2478211c77..1e9871da02 100644 --- a/src/USER-EFF/fix_nph_eff.cpp +++ b/src/USER-EFF/fix_nph_eff.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nph_eff.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,35 +34,15 @@ FixNPHEff::FixNPHEff(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/eff"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/eff",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-EFF/fix_npt_eff.cpp b/src/USER-EFF/fix_npt_eff.cpp index 98b76b1b43..4612810c02 100644 --- a/src/USER-EFF/fix_npt_eff.cpp +++ b/src/USER-EFF/fix_npt_eff.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_npt_eff.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,35 +34,15 @@ FixNPTEff::FixNPTEff(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/eff"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/eff",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-EFF/fix_nvt_eff.cpp b/src/USER-EFF/fix_nvt_eff.cpp index 8f37cbf2b1..f5358b5db1 100644 --- a/src/USER-EFF/fix_nvt_eff.cpp +++ b/src/USER-EFF/fix_nvt_eff.cpp @@ -11,11 +11,13 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nvt_eff.h" + +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -33,17 +35,8 @@ FixNVTEff::FixNVTEff(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/eff"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/eff", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-EFF/fix_nvt_sllod_eff.cpp b/src/USER-EFF/fix_nvt_sllod_eff.cpp index b5d40251bf..36a5cbb8ab 100644 --- a/src/USER-EFF/fix_nvt_sllod_eff.cpp +++ b/src/USER-EFF/fix_nvt_sllod_eff.cpp @@ -11,19 +11,20 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include -#include - #include "fix_nvt_sllod_eff.h" -#include "math_extra.h" + #include "atom.h" +#include "compute.h" #include "domain.h" -#include "group.h" -#include "modify.h" +#include "error.h" #include "fix.h" #include "fix_deform.h" -#include "compute.h" -#include "error.h" +#include "group.h" +#include "math_extra.h" +#include "modify.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -45,18 +46,9 @@ FixNVTSllodEff::FixNVTSllodEff(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/deform/eff"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} tmp/deform/eff", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-EFF/fix_temp_rescale_eff.cpp b/src/USER-EFF/fix_temp_rescale_eff.cpp index f796c7cb02..1ebed8b9ff 100644 --- a/src/USER-EFF/fix_temp_rescale_eff.cpp +++ b/src/USER-EFF/fix_temp_rescale_eff.cpp @@ -15,18 +15,19 @@ Contributing author: Andres Jaramillo-Botero ------------------------------------------------------------------------- */ -#include - -#include #include "fix_temp_rescale_eff.h" + #include "atom.h" -#include "force.h" -#include "group.h" -#include "update.h" #include "comm.h" -#include "modify.h" #include "compute.h" #include "error.h" +#include "force.h" +#include "group.h" +#include "modify.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -56,17 +57,9 @@ FixTempRescaleEff::FixTempRescaleEff(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp/eff // id = fix-ID + temp, compute group = fix group - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[6]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/eff"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/eff", + id_temp,group->names[igroup])); tflag = 1; energy = 0.0; diff --git a/src/USER-INTEL/fix_npt_intel.cpp b/src/USER-INTEL/fix_npt_intel.cpp index 4d69e80515..3f48130f99 100644 --- a/src/USER-INTEL/fix_npt_intel.cpp +++ b/src/USER-INTEL/fix_npt_intel.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_npt_intel.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -25,44 +25,24 @@ FixNPTIntel::FixNPTIntel(LAMMPS *lmp, int narg, char **arg) : FixNHIntel(lmp, narg, arg) { if (!tstat_flag) - error->all(FLERR,"Temperature control must be used with fix npt/omp"); + error->all(FLERR,"Temperature control must be used with fix npt/intel"); if (!pstat_flag) - error->all(FLERR,"Pressure control must be used with fix npt/omp"); + error->all(FLERR,"Pressure control must be used with fix npt/intl"); // create a new compute temp style // id = fix-ID + temp // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-INTEL/fix_nvt_intel.cpp b/src/USER-INTEL/fix_nvt_intel.cpp index b9ceea4c71..61259fba2f 100644 --- a/src/USER-INTEL/fix_nvt_intel.cpp +++ b/src/USER-INTEL/fix_nvt_intel.cpp @@ -11,11 +11,13 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nvt_intel.h" + +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -26,25 +28,15 @@ FixNVTIntel::FixNVTIntel(LAMMPS *lmp, int narg, char **arg) : FixNHIntel(lmp, narg, arg) { if (!tstat_flag) - error->all(FLERR,"Temperature control must be used with fix nvt"); + error->all(FLERR,"Temperature control must be used with fix nvt/intel"); if (pstat_flag) - error->all(FLERR,"Pressure control can not be used with fix nvt"); + error->all(FLERR,"Pressure control can not be used with fix nvt/intel"); // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-INTEL/fix_nvt_sllod_intel.cpp b/src/USER-INTEL/fix_nvt_sllod_intel.cpp index 3880adc055..efe124cb2d 100644 --- a/src/USER-INTEL/fix_nvt_sllod_intel.cpp +++ b/src/USER-INTEL/fix_nvt_sllod_intel.cpp @@ -46,18 +46,9 @@ FixNVTSllodIntel::FixNVTSllodIntel(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/deform"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/deform", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-LB/fix_lb_fluid.cpp b/src/USER-LB/fix_lb_fluid.cpp index 351e078dad..dafd5d2a3a 100644 --- a/src/USER-LB/fix_lb_fluid.cpp +++ b/src/USER-LB/fix_lb_fluid.cpp @@ -17,22 +17,22 @@ ------------------------------------------------------------------------- */ #include "fix_lb_fluid.h" + +#include "atom.h" +#include "comm.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "group.h" +#include "memory.h" +#include "modify.h" +#include "random_mars.h" +#include "update.h" + #include - - #include #include #include -#include "comm.h" -#include "memory.h" -#include "error.h" -#include "domain.h" -#include "atom.h" -#include "group.h" -#include "random_mars.h" -#include "update.h" -#include "force.h" -#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/USER-MANIFOLD/fix_nvt_manifold_rattle.cpp b/src/USER-MANIFOLD/fix_nvt_manifold_rattle.cpp index 310dae8725..844f99b725 100644 --- a/src/USER-MANIFOLD/fix_nvt_manifold_rattle.cpp +++ b/src/USER-MANIFOLD/fix_nvt_manifold_rattle.cpp @@ -131,24 +131,10 @@ FixNVTManifoldRattle::FixNVTManifoldRattle(LAMMPS *lmp, int narg, char **arg, } // Create temperature compute: - const char *fix_id = arg[1]; - int n = strlen(fix_id)+6; - id_temp = new char[n]; - strcpy(id_temp,fix_id); - strcat(id_temp,"_temp"); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char*) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); int icompute = modify->find_compute(id_temp); - if (icompute < 0) { - error->all(FLERR,"Temperature ID for fix nvt/manifold/rattle " - "does not exist"); - } temperature = modify->compute[icompute]; if (temperature->tempbias) which = BIAS; else which = NOBIAS; @@ -167,8 +153,6 @@ FixNVTManifoldRattle::FixNVTManifoldRattle(LAMMPS *lmp, int narg, char **arg, for (int ich = 0; ich < mtchain; ++ich) { eta[ich] = eta_dot[ich] = eta_dotdot[ich] = 0.0; } - - } /* ---------------------------------------------------------------------- */ @@ -185,9 +169,6 @@ FixNVTManifoldRattle::~FixNVTManifoldRattle() if (id_temp) delete[] id_temp; } - - - int FixNVTManifoldRattle::setmask() { int mask = 0; @@ -198,7 +179,6 @@ int FixNVTManifoldRattle::setmask() return mask; } - /* -------------------------------------------------------------------------- Check that force modification happens before position and velocity update. Make sure respa is not used. @@ -219,8 +199,6 @@ void FixNVTManifoldRattle::init() } - - void FixNVTManifoldRattle::setup(int /*vflag*/) { compute_temp_target(); @@ -359,9 +337,6 @@ void FixNVTManifoldRattle::nh_v_temp() } } - - - // Most of this logic is based on fix_nh: void FixNVTManifoldRattle::initial_integrate(int /*vflag*/) { @@ -381,8 +356,6 @@ void FixNVTManifoldRattle::final_integrate() nhc_temp_integrate(); } - - /* ---------------------------------------------------------------------- */ void FixNVTManifoldRattle::reset_dt() { @@ -395,10 +368,6 @@ void FixNVTManifoldRattle::reset_dt() } - - - - double FixNVTManifoldRattle::memory_usage() { double bytes = FixNVEManifoldRattle::memory_usage(); diff --git a/src/USER-MISC/fix_grem.cpp b/src/USER-MISC/fix_grem.cpp index b1f1bded85..64c7e4a6b7 100644 --- a/src/USER-MISC/fix_grem.cpp +++ b/src/USER-MISC/fix_grem.cpp @@ -23,14 +23,16 @@ ------------------------------------------------------------------------- */ #include "fix_grem.h" -#include + #include "atom.h" -#include "force.h" -#include "update.h" -#include "modify.h" -#include "domain.h" #include "compute.h" +#include "domain.h" #include "error.h" +#include "force.h" +#include "modify.h" +#include "update.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -65,65 +67,28 @@ FixGrem::FixGrem(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[5]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "PRESSURE/GREM"; - newarg[3] = id_temp; - newarg[4] = id; - modify->add_compute(5,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all PRESSURE/GREM {}", + id_press, id_temp)); // create a new compute ke style // id = fix-ID + ke - n = strlen(id) + 8; - id_ke = new char[n]; - strcpy(id_ke,id); - strcat(id_ke,"_ke"); - - newarg = new char*[3]; - newarg[0] = id_ke; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "ke"; - modify->add_compute(3,newarg); - delete [] newarg; + id_ke = utils::strdup(std::string(id) + "_ke"); + modify->add_compute(fmt::format("{} all ke",id_temp)); // create a new compute pe style // id = fix-ID + pe - n = strlen(id) + 9; - id_pe = new char[n]; - strcpy(id_pe,id); - strcat(id_pe,"_pe"); - - newarg = new char*[3]; - newarg[0] = id_pe; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pe"; - modify->add_compute(3,newarg); - delete [] newarg; + id_pe = utils::strdup(std::string(id) + "_pe"); + modify->add_compute(fmt::format("{} all pe",id_temp)); int ifix = modify->find_fix(id_nh); if (ifix < 0) diff --git a/src/USER-MISC/fix_npt_cauchy.cpp b/src/USER-MISC/fix_npt_cauchy.cpp index 5d51114262..37d6e5286b 100644 --- a/src/USER-MISC/fix_npt_cauchy.cpp +++ b/src/USER-MISC/fix_npt_cauchy.cpp @@ -15,27 +15,28 @@ Contributing authors: ------------------------------------------------------------------------- */ -#include - -#include #include "fix_npt_cauchy.h" -#include "math_extra.h" + #include "atom.h" -#include "force.h" -#include "group.h" #include "comm.h" -#include "neighbor.h" -#include "irregular.h" -#include "modify.h" +#include "compute.h" +#include "domain.h" +#include "error.h" #include "fix_deform.h" #include "fix_store.h" -#include "compute.h" +#include "force.h" +#include "group.h" +#include "irregular.h" #include "kspace.h" -#include "update.h" -#include "respa.h" -#include "domain.h" +#include "math_extra.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -53,7 +54,8 @@ enum{ISO,ANISO,TRICLINIC}; FixNPTCauchy::FixNPTCauchy(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), - rfix(nullptr), id_dilate(nullptr), irregular(nullptr), id_temp(nullptr), id_press(nullptr), + rfix(nullptr), id_dilate(nullptr), irregular(nullptr), + id_temp(nullptr), id_press(nullptr), eta(nullptr), eta_dot(nullptr), eta_dotdot(nullptr), eta_mass(nullptr), etap(nullptr), etap_dot(nullptr), etap_dotdot(nullptr), etap_mass(nullptr), id_store(nullptr),init_store(nullptr) @@ -604,36 +606,16 @@ FixNPTCauchy::FixNPTCauchy(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_nph_asphere_omp.cpp b/src/USER-OMP/fix_nph_asphere_omp.cpp index 4f20d9657c..eeeb4ef2ea 100644 --- a/src/USER-OMP/fix_nph_asphere_omp.cpp +++ b/src/USER-OMP/fix_nph_asphere_omp.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nph_asphere_omp.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,35 +34,15 @@ FixNPHAsphereOMP::FixNPHAsphereOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/asphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/asphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_nph_omp.cpp b/src/USER-OMP/fix_nph_omp.cpp index 8c2f9ed3a3..733600b4bf 100644 --- a/src/USER-OMP/fix_nph_omp.cpp +++ b/src/USER-OMP/fix_nph_omp.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nph_omp.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,15 +34,15 @@ FixNPHOMP::FixNPHOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - id_press = utils::strdup(std::string(id)+"_press"); - modify->add_compute(std::string(id_press)+" all pressure "+id_temp); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_nph_sphere_omp.cpp b/src/USER-OMP/fix_nph_sphere_omp.cpp index 0e2a805dcf..35387b51f2 100644 --- a/src/USER-OMP/fix_nph_sphere_omp.cpp +++ b/src/USER-OMP/fix_nph_sphere_omp.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nph_sphere_omp.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,35 +34,15 @@ FixNPHSphereOMP::FixNPHSphereOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/sphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/sphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_npt_asphere_omp.cpp b/src/USER-OMP/fix_npt_asphere_omp.cpp index c05fca9043..e896db8712 100644 --- a/src/USER-OMP/fix_npt_asphere_omp.cpp +++ b/src/USER-OMP/fix_npt_asphere_omp.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_npt_asphere_omp.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,35 +34,15 @@ FixNPTAsphereOMP::FixNPTAsphereOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/asphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/asphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_npt_omp.cpp b/src/USER-OMP/fix_npt_omp.cpp index 4037dd928e..386be81acc 100644 --- a/src/USER-OMP/fix_npt_omp.cpp +++ b/src/USER-OMP/fix_npt_omp.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_npt_omp.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,15 +34,15 @@ FixNPTOMP::FixNPTOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - id_temp = utils::strdup(std::string(id)+"_temp"); - modify->add_compute(std::string(id_temp)+" all temp"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - id_press = utils::strdup(std::string(id)+"_press"); - modify->add_compute(std::string(id_press)+" all pressure "+id_temp); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_npt_sphere_omp.cpp b/src/USER-OMP/fix_npt_sphere_omp.cpp index 93b6cdda69..4e40fb63d5 100644 --- a/src/USER-OMP/fix_npt_sphere_omp.cpp +++ b/src/USER-OMP/fix_npt_sphere_omp.cpp @@ -11,10 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_npt_sphere_omp.h" -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -34,35 +34,15 @@ FixNPTSphereOMP::FixNPTSphereOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/sphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/sphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_nvt_asphere_omp.cpp b/src/USER-OMP/fix_nvt_asphere_omp.cpp index 353d839b4f..c8db9cc98d 100644 --- a/src/USER-OMP/fix_nvt_asphere_omp.cpp +++ b/src/USER-OMP/fix_nvt_asphere_omp.cpp @@ -33,17 +33,8 @@ FixNVTAsphereOMP::FixNVTAsphereOMP(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/asphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/asphere", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-OMP/fix_nvt_omp.cpp b/src/USER-OMP/fix_nvt_omp.cpp index 127876b4e8..240825b2c6 100644 --- a/src/USER-OMP/fix_nvt_omp.cpp +++ b/src/USER-OMP/fix_nvt_omp.cpp @@ -11,11 +11,13 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nvt_omp.h" + +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/USER-OMP/fix_nvt_sllod_omp.cpp b/src/USER-OMP/fix_nvt_sllod_omp.cpp index a665241efb..3193d58386 100644 --- a/src/USER-OMP/fix_nvt_sllod_omp.cpp +++ b/src/USER-OMP/fix_nvt_sllod_omp.cpp @@ -15,18 +15,21 @@ Contributing author: Axel Kohlmeyer (Temple U) ------------------------------------------------------------------------- */ -#include "omp_compat.h" #include "fix_nvt_sllod_omp.h" -#include -#include "math_extra.h" + #include "atom.h" -#include "group.h" -#include "modify.h" +#include "compute.h" +#include "domain.h" +#include "error.h" #include "fix.h" #include "fix_deform.h" -#include "compute.h" -#include "error.h" -#include "domain.h" +#include "group.h" +#include "math_extra.h" +#include "modify.h" + +#include + +#include "omp_compat.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -51,18 +54,9 @@ FixNVTSllodOMP::FixNVTSllodOMP(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/deform"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/deform", + id_temp,group->names[igroup])); tcomputeflag = 1; } @@ -82,7 +76,7 @@ void FixNVTSllodOMP::init() int i; for (i = 0; i < modify->nfix; i++) - if (strncmp(modify->fix[i]->style,"deform",6) == 0) { + if (utils::strmatch(modify->fix[i]->style,"^deform")) { if (((FixDeform *) modify->fix[i])->remapflag != Domain::V_REMAP) error->all(FLERR,"Using fix nvt/sllod/omp with inconsistent fix " "deform remap option"); diff --git a/src/USER-OMP/fix_nvt_sphere_omp.cpp b/src/USER-OMP/fix_nvt_sphere_omp.cpp index 680ddd7f17..d53d9ec32d 100644 --- a/src/USER-OMP/fix_nvt_sphere_omp.cpp +++ b/src/USER-OMP/fix_nvt_sphere_omp.cpp @@ -11,11 +11,11 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ -#include #include "fix_nvt_sphere_omp.h" + +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -33,17 +33,8 @@ FixNVTSphereOMP::FixNVTSphereOMP(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/sphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/sphere", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/USER-OMP/fix_rigid_nph_omp.cpp b/src/USER-OMP/fix_rigid_nph_omp.cpp index cb59ad0828..80bfbe8141 100644 --- a/src/USER-OMP/fix_rigid_nph_omp.cpp +++ b/src/USER-OMP/fix_rigid_nph_omp.cpp @@ -18,9 +18,9 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_nph_omp.h" -#include -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; @@ -57,34 +57,15 @@ FixRigidNPHOMP::FixRigidNPHOMP(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-OMP/fix_rigid_npt_omp.cpp b/src/USER-OMP/fix_rigid_npt_omp.cpp index f496dd0a11..f832dda618 100644 --- a/src/USER-OMP/fix_rigid_npt_omp.cpp +++ b/src/USER-OMP/fix_rigid_npt_omp.cpp @@ -18,9 +18,9 @@ ------------------------------------------------------------------------- */ #include "fix_rigid_npt_omp.h" -#include -#include "modify.h" + #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; @@ -67,36 +67,17 @@ FixRigidNPTOMP::FixRigidNPTOMP(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp // compute group = all since pressure is always global (group all) - // and thus its KE/temperature contribution should use group all + // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/USER-QTB/fix_qbmsst.cpp b/src/USER-QTB/fix_qbmsst.cpp index b221ecbca8..0b54811db0 100644 --- a/src/USER-QTB/fix_qbmsst.cpp +++ b/src/USER-QTB/fix_qbmsst.cpp @@ -18,9 +18,6 @@ #include "fix_qbmsst.h" -#include -#include - #include "atom.h" #include "force.h" #include "update.h" @@ -34,6 +31,9 @@ #include "kspace.h" #include "math_const.h" +#include +#include + using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; @@ -204,45 +204,23 @@ FixQBMSST::FixQBMSST(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) // id = fix-ID + temp // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = const_cast("all"); - newarg[2] = const_cast("temp"); - modify->add_compute(3,newarg); - delete [] newarg; + + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = const_cast("all"); - newarg[2] = const_cast("pressure"); - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pflag = 1; // create a new compute potential energy compute - n = strlen(id) + 3; - id_pe = new char[n]; - strcpy(id_pe,id); - strcat(id_pe,"_pe"); - newarg = new char*[3]; - newarg[0] = id_pe; - newarg[1] = (char*)"all"; - newarg[2] = (char*)"pe"; - modify->add_compute(3,newarg); - delete [] newarg; + + id_pe = utils::strdup(std::string(id) + "_pe"); + modify->add_compute(fmt::format("{} all pe",id_temp)); peflag = 1; // allocate qbmsst diff --git a/src/USER-UEF/fix_nh_uef.cpp b/src/USER-UEF/fix_nh_uef.cpp index b757900703..91125fd4ed 100644 --- a/src/USER-UEF/fix_nh_uef.cpp +++ b/src/USER-UEF/fix_nh_uef.cpp @@ -14,24 +14,26 @@ ------------------------------------------------------------------------- */ #include "fix_nh_uef.h" -#include -#include + #include "atom.h" -#include "force.h" -#include "comm.h" #include "citeme.h" -#include "irregular.h" -#include "modify.h" +#include "comm.h" #include "compute.h" -#include "update.h" -#include "domain.h" -#include "error.h" -#include "output.h" -#include "timer.h" -#include "neighbor.h" #include "compute_pressure_uef.h" #include "compute_temp_uef.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "irregular.h" +#include "modify.h" +#include "neighbor.h" +#include "output.h" +#include "timer.h" #include "uef_utils.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -179,29 +181,12 @@ FixNHUef::FixNHUef(LAMMPS *lmp, int narg, char **arg) : // Create temp and pressure computes for nh/uef - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/uef"; - modify->add_compute(3,newarg); - delete [] newarg; + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/uef",id_temp)); tcomputeflag = 1; - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure/uef"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure/uef {}",id_press, id_temp)); pcomputeflag = 1; nevery = 1; @@ -214,8 +199,7 @@ FixNHUef::FixNHUef(LAMMPS *lmp, int narg, char **arg) : FixNHUef::~FixNHUef() { delete uefbox; - if (pcomputeflag && !pstat_flag) - { + if (pcomputeflag && !pstat_flag) { modify->delete_compute(id_press); delete [] id_press; } diff --git a/src/VORONOI/compute_voronoi_atom.cpp b/src/VORONOI/compute_voronoi_atom.cpp index bcd9031b6e..d9cd746ca6 100644 --- a/src/VORONOI/compute_voronoi_atom.cpp +++ b/src/VORONOI/compute_voronoi_atom.cpp @@ -80,9 +80,7 @@ ComputeVoronoi::ComputeVoronoi(LAMMPS *lmp, int narg, char **arg) : else if (strcmp(arg[iarg], "radius") == 0) { if (iarg + 2 > narg || strstr(arg[iarg+1],"v_") != arg[iarg+1] ) error->all(FLERR,"Illegal compute voronoi/atom command"); - int n = strlen(&arg[iarg+1][2]) + 1; - radstr = new char[n]; - strcpy(radstr,&arg[iarg+1][2]); + radstr = utils::strdup(&arg[iarg+1][2]); iarg += 2; } else if (strcmp(arg[iarg], "surface") == 0) { diff --git a/src/fix_box_relax.cpp b/src/fix_box_relax.cpp index ef576e96f6..76bd8f05c2 100644 --- a/src/fix_box_relax.cpp +++ b/src/fix_box_relax.cpp @@ -16,20 +16,20 @@ ------------------------------------------------------------------------- */ #include "fix_box_relax.h" -#include -#include #include "atom.h" -#include "domain.h" -#include "update.h" #include "comm.h" +#include "compute.h" +#include "domain.h" +#include "error.h" #include "force.h" #include "kspace.h" -#include "modify.h" -#include "compute.h" -#include "error.h" #include "math_extra.h" +#include "modify.h" +#include "update.h" +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -319,24 +319,17 @@ FixBoxRelax::FixBoxRelax(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += " all temp"; - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tflag = 1; // create a new compute pressure style (virial only) // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - pcmd += " all pressure " + std::string(id_temp) + " virial"; - modify->add_compute(pcmd); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {} virial", + id_press, id_temp)); pflag = 1; dimension = domain->dimension; diff --git a/src/fix_nph.cpp b/src/fix_nph.cpp index 6002d2e40d..5b160689dd 100644 --- a/src/fix_nph.cpp +++ b/src/fix_nph.cpp @@ -12,10 +12,9 @@ ------------------------------------------------------------------------- */ #include "fix_nph.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -35,23 +34,15 @@ FixNPH::FixNPH(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += " all temp"; - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - pcmd += " all pressure " + std::string(id_temp); - modify->add_compute(pcmd); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/fix_nph_sphere.cpp b/src/fix_nph_sphere.cpp index 27197c48a7..20e072d5b5 100644 --- a/src/fix_nph_sphere.cpp +++ b/src/fix_nph_sphere.cpp @@ -12,10 +12,11 @@ ------------------------------------------------------------------------- */ #include "fix_nph_sphere.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -35,21 +36,15 @@ FixNPHSphere::FixNPHSphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - modify->add_compute(tcmd + " all temp/sphere"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/sphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/fix_npt.cpp b/src/fix_npt.cpp index 7ee346985d..78acf0cf7e 100644 --- a/src/fix_npt.cpp +++ b/src/fix_npt.cpp @@ -12,10 +12,9 @@ ------------------------------------------------------------------------- */ #include "fix_npt.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -35,23 +34,15 @@ FixNPT::FixNPT(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += " all temp"; - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - pcmd += " all pressure " + std::string(id_temp); - modify->add_compute(pcmd); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/fix_npt_sphere.cpp b/src/fix_npt_sphere.cpp index b806cf5362..a6dfeba425 100644 --- a/src/fix_npt_sphere.cpp +++ b/src/fix_npt_sphere.cpp @@ -12,10 +12,11 @@ ------------------------------------------------------------------------- */ #include "fix_npt_sphere.h" -#include -#include "modify.h" #include "error.h" +#include "modify.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -35,21 +36,15 @@ FixNPTSphere::FixNPTSphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - modify->add_compute(tcmd + " all temp/sphere"); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp/sphere",id_temp)); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pcomputeflag = 1; } diff --git a/src/fix_nve.cpp b/src/fix_nve.cpp index 23f69abc86..e14ff47e46 100644 --- a/src/fix_nve.cpp +++ b/src/fix_nve.cpp @@ -12,12 +12,12 @@ ------------------------------------------------------------------------- */ #include "fix_nve.h" -#include + #include "atom.h" -#include "force.h" -#include "update.h" -#include "respa.h" #include "error.h" +#include "force.h" +#include "respa.h" +#include "update.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -27,7 +27,7 @@ using namespace FixConst; FixNVE::FixNVE(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) { - if (strcmp(style,"nve/sphere") != 0 && narg < 3) + if (!utils::strmatch(style,"^nve/sphere") && narg < 3) error->all(FLERR,"Illegal fix nve command"); dynamic_group_allow = 1; @@ -53,7 +53,7 @@ void FixNVE::init() dtv = update->dt; dtf = 0.5 * update->dt * force->ftm2v; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) step_respa = ((Respa *) update->integrate)->step; } diff --git a/src/fix_nvt.cpp b/src/fix_nvt.cpp index ad69e6ee81..14251a269a 100644 --- a/src/fix_nvt.cpp +++ b/src/fix_nvt.cpp @@ -12,12 +12,10 @@ ------------------------------------------------------------------------- */ #include "fix_nvt.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" - using namespace LAMMPS_NS; using namespace FixConst; @@ -35,11 +33,7 @@ FixNVT::FixNVT(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += fmt::format(" {} temp",group->names[igroup]); - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/fix_nvt_sllod.cpp b/src/fix_nvt_sllod.cpp index 2257fa6c56..ba81adee0c 100644 --- a/src/fix_nvt_sllod.cpp +++ b/src/fix_nvt_sllod.cpp @@ -16,17 +16,18 @@ ------------------------------------------------------------------------- */ #include "fix_nvt_sllod.h" -#include -#include "math_extra.h" + #include "atom.h" +#include "compute.h" #include "domain.h" -#include "group.h" -#include "modify.h" +#include "error.h" #include "fix.h" #include "fix_deform.h" -#include "compute.h" -#include "error.h" +#include "group.h" +#include "math_extra.h" +#include "modify.h" +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -49,12 +50,9 @@ FixNVTSllod::FixNVTSllod(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - std::string cmd = id + std::string("_temp"); - id_temp = new char[cmd.size()+1]; - strcpy(id_temp,cmd.c_str()); - - cmd += fmt::format(" {} temp/deform",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/deform", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/fix_nvt_sphere.cpp b/src/fix_nvt_sphere.cpp index 1119d345bc..0733a27678 100644 --- a/src/fix_nvt_sphere.cpp +++ b/src/fix_nvt_sphere.cpp @@ -12,12 +12,10 @@ ------------------------------------------------------------------------- */ #include "fix_nvt_sphere.h" -#include +#include "error.h" #include "group.h" #include "modify.h" -#include "error.h" - using namespace LAMMPS_NS; using namespace FixConst; @@ -35,11 +33,8 @@ FixNVTSphere::FixNVTSphere(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - std::string cmd = id + std::string("_temp"); - id_temp = new char[cmd.size()+1]; - strcpy(id_temp,cmd.c_str()); - - cmd += fmt::format(" {} temp/sphere",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp/sphere", + id_temp,group->names[igroup])); tcomputeflag = 1; } diff --git a/src/fix_press_berendsen.cpp b/src/fix_press_berendsen.cpp index d929ca6f28..9cd9de9485 100644 --- a/src/fix_press_berendsen.cpp +++ b/src/fix_press_berendsen.cpp @@ -12,19 +12,20 @@ ------------------------------------------------------------------------- */ #include "fix_press_berendsen.h" -#include -#include #include "atom.h" -#include "force.h" #include "comm.h" -#include "modify.h" -#include "fix_deform.h" #include "compute.h" -#include "kspace.h" -#include "update.h" #include "domain.h" #include "error.h" +#include "fix_deform.h" +#include "force.h" +#include "kspace.h" +#include "modify.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -218,24 +219,16 @@ FixPressBerendsen::FixPressBerendsen(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - std::string tcmd = id + std::string("_temp"); - id_temp = new char[tcmd.size()+1]; - strcpy(id_temp,tcmd.c_str()); - - tcmd += " all temp"; - modify->add_compute(tcmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} all temp",id_temp)); tflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - std::string pcmd = id + std::string("_press"); - id_press = new char[pcmd.size()+1]; - strcpy(id_press,pcmd.c_str()); - - pcmd += " all pressure " + std::string(id_temp); - modify->add_compute(pcmd); + id_press = utils::strdup(std::string(id) + "_press"); + modify->add_compute(fmt::format("{} all pressure {}",id_press, id_temp)); pflag = 1; nrigid = 0; diff --git a/src/fix_temp_berendsen.cpp b/src/fix_temp_berendsen.cpp index 39b8a5fefd..38ce9de333 100644 --- a/src/fix_temp_berendsen.cpp +++ b/src/fix_temp_berendsen.cpp @@ -72,10 +72,8 @@ FixTempBerendsen::FixTempBerendsen(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp, compute group = fix group - std::string cmd = id + std::string("_temp"); - id_temp = utils::strdup(cmd); - cmd += fmt::format(" {} temp",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tflag = 1; energy = 0; diff --git a/src/fix_temp_csld.cpp b/src/fix_temp_csld.cpp index 787b4dd34e..bf3d0eb7f6 100644 --- a/src/fix_temp_csld.cpp +++ b/src/fix_temp_csld.cpp @@ -81,10 +81,8 @@ FixTempCSLD::FixTempCSLD(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp, compute group = fix group - std::string cmd = id + std::string("_temp"); - id_temp = utils::strdup(cmd); - cmd += fmt::format(" {} temp",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tflag = 1; vhold = nullptr; diff --git a/src/fix_temp_csvr.cpp b/src/fix_temp_csvr.cpp index 525cf5b74a..2d04243a11 100644 --- a/src/fix_temp_csvr.cpp +++ b/src/fix_temp_csvr.cpp @@ -81,10 +81,8 @@ FixTempCSVR::FixTempCSVR(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp, compute group = fix group - std::string cmd = id + std::string("_temp"); - id_temp = utils::strdup(cmd); - cmd += fmt::format(" {} temp",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tflag = 1; nmax = -1; diff --git a/src/fix_temp_rescale.cpp b/src/fix_temp_rescale.cpp index b57f6c238c..73c55f2793 100644 --- a/src/fix_temp_rescale.cpp +++ b/src/fix_temp_rescale.cpp @@ -68,10 +68,8 @@ FixTempRescale::FixTempRescale(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp // id = fix-ID + temp, compute group = fix group - std::string cmd = id + std::string("_temp"); - id_temp = utils::strdup(cmd); - cmd += fmt::format(" {} temp",group->names[igroup]); - modify->add_compute(cmd); + id_temp = utils::strdup(std::string(id) + "_temp"); + modify->add_compute(fmt::format("{} {} temp",id_temp,group->names[igroup])); tflag = 1; energy = 0.0; From e481eb115456f7332ec7e9dd19151f02e23af515 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 29 Mar 2021 07:29:14 -0400 Subject: [PATCH 174/257] simplify by using utils::strdup() fmt::format() and reorder includes --- src/USER-BOCS/fix_bocs.cpp | 8 ++---- src/USER-DPD/fix_eos_table_rx.cpp | 7 +++-- src/USER-DPD/fix_rx.cpp | 26 +++++++++---------- src/USER-DPD/pair_exp6_rx.cpp | 15 +++++------ src/USER-DPD/pair_multi_lucy.cpp | 22 +++++++--------- src/USER-DPD/pair_multi_lucy_rx.cpp | 26 +++++++++---------- src/USER-EFF/fix_temp_rescale_eff.cpp | 4 +-- src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp | 7 ++--- src/USER-MGPT/pair_mgpt.cpp | 16 +++++------- src/USER-MISC/compute_gyration_shape.cpp | 13 +++++----- .../compute_gyration_shape_chunk.cpp | 21 +++++++-------- src/USER-MISC/compute_hma.cpp | 24 +++-------------- src/USER-MISC/compute_pressure_grem.cpp | 8 +++--- 13 files changed, 80 insertions(+), 117 deletions(-) diff --git a/src/USER-BOCS/fix_bocs.cpp b/src/USER-BOCS/fix_bocs.cpp index 87d4653da5..60fb03cdf8 100644 --- a/src/USER-BOCS/fix_bocs.cpp +++ b/src/USER-BOCS/fix_bocs.cpp @@ -1525,9 +1525,7 @@ int FixBocs::modify_param(int narg, char **arg) tcomputeflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) @@ -1559,9 +1557,7 @@ int FixBocs::modify_param(int narg, char **arg) pcomputeflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/USER-DPD/fix_eos_table_rx.cpp b/src/USER-DPD/fix_eos_table_rx.cpp index 28cd4eb4c3..7b0bec93f2 100644 --- a/src/USER-DPD/fix_eos_table_rx.cpp +++ b/src/USER-DPD/fix_eos_table_rx.cpp @@ -17,16 +17,15 @@ #include "fix_eos_table_rx.h" - -#include -#include #include "atom.h" +#include "comm.h" #include "error.h" #include "force.h" #include "memory.h" -#include "comm.h" #include "modify.h" +#include +#include #define MAXLINE 1024 diff --git a/src/USER-DPD/fix_rx.cpp b/src/USER-DPD/fix_rx.cpp index 675c3d6dea..4f0f381e6d 100644 --- a/src/USER-DPD/fix_rx.cpp +++ b/src/USER-DPD/fix_rx.cpp @@ -13,28 +13,26 @@ #include "fix_rx.h" - -#include -#include -#include // DBL_EPSILON #include "atom.h" -#include "error.h" -#include "group.h" -#include "modify.h" -#include "force.h" -#include "memory.h" #include "comm.h" -#include "update.h" #include "domain.h" -#include "neighbor.h" +#include "error.h" +#include "force.h" +#include "group.h" +#include "math_special.h" +#include "memory.h" +#include "modify.h" #include "neigh_list.h" #include "neigh_request.h" -#include "math_special.h" +#include "neighbor.h" #include "pair_dpd_fdt_energy.h" +#include "update.h" - -#include // std::vector<> #include // std::max +#include // DBL_EPSILON +#include +#include +#include // std::vector<> using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/USER-DPD/pair_exp6_rx.cpp b/src/USER-DPD/pair_exp6_rx.cpp index 036d31060b..ba8d52776f 100644 --- a/src/USER-DPD/pair_exp6_rx.cpp +++ b/src/USER-DPD/pair_exp6_rx.cpp @@ -13,20 +13,19 @@ #include "pair_exp6_rx.h" -#include - -#include -#include #include "atom.h" #include "comm.h" +#include "error.h" +#include "fix.h" #include "force.h" -#include "neigh_list.h" #include "math_special.h" #include "memory.h" -#include "error.h" - #include "modify.h" -#include "fix.h" +#include "neigh_list.h" + +#include +#include +#include using namespace LAMMPS_NS; using namespace MathSpecial; diff --git a/src/USER-DPD/pair_multi_lucy.cpp b/src/USER-DPD/pair_multi_lucy.cpp index 70ea8b40ad..85cab8a37f 100644 --- a/src/USER-DPD/pair_multi_lucy.cpp +++ b/src/USER-DPD/pair_multi_lucy.cpp @@ -21,21 +21,19 @@ The Journal of Chemical Physics, 2016, 144, 104501. ------------------------------------------------------------------------------------------- */ +#include "pair_multi_lucy.h" + +#include "atom.h" +#include "citeme.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "math_const.h" +#include "memory.h" +#include "neigh_list.h" #include -#include "math_const.h" - #include -#include "pair_multi_lucy.h" -#include "atom.h" -#include "force.h" -#include "comm.h" -#include "neigh_list.h" -#include "memory.h" -#include "error.h" - -#include "citeme.h" - using namespace LAMMPS_NS; diff --git a/src/USER-DPD/pair_multi_lucy_rx.cpp b/src/USER-DPD/pair_multi_lucy_rx.cpp index c0f6af8a7e..5bea395725 100644 --- a/src/USER-DPD/pair_multi_lucy_rx.cpp +++ b/src/USER-DPD/pair_multi_lucy_rx.cpp @@ -21,23 +21,21 @@ The Journal of Chemical Physics, 2016, 144, 104501. ------------------------------------------------------------------------------------------- */ +#include "pair_multi_lucy_rx.h" + +#include "atom.h" +#include "citeme.h" +#include "comm.h" +#include "error.h" +#include "fix.h" +#include "force.h" +#include "math_const.h" +#include "memory.h" +#include "modify.h" +#include "neigh_list.h" #include -#include "math_const.h" - #include -#include "pair_multi_lucy_rx.h" -#include "atom.h" -#include "force.h" -#include "comm.h" -#include "neigh_list.h" -#include "memory.h" -#include "error.h" - -#include "citeme.h" -#include "modify.h" -#include "fix.h" - using namespace LAMMPS_NS; diff --git a/src/USER-EFF/fix_temp_rescale_eff.cpp b/src/USER-EFF/fix_temp_rescale_eff.cpp index 1ebed8b9ff..0d3bf6ed43 100644 --- a/src/USER-EFF/fix_temp_rescale_eff.cpp +++ b/src/USER-EFF/fix_temp_rescale_eff.cpp @@ -165,9 +165,7 @@ int FixTempRescaleEff::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) error->all(FLERR,"Could not find fix_modify temperature ID"); diff --git a/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp b/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp index a45d62a588..4b141a3bd1 100644 --- a/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp +++ b/src/USER-MANIFOLD/fix_nve_manifold_rattle.cpp @@ -31,10 +31,8 @@ ------------------------------------------------------------------------- */ - #include "fix_nve_manifold_rattle.h" -#include #include "atom.h" #include "force.h" #include "update.h" @@ -44,18 +42,17 @@ #include "citeme.h" #include "comm.h" +#include + #include "manifold_factory.h" #include "manifold.h" - using namespace LAMMPS_NS; using namespace FixConst; using namespace user_manifold; - enum { CONST, EQUAL }; // For treating the variables. - static const char* cite_fix_nve_manifold_rattle = "fix nve/manifold/rattle command:\n\n" "@article{paquay-2016,\n" diff --git a/src/USER-MGPT/pair_mgpt.cpp b/src/USER-MGPT/pair_mgpt.cpp index 75f870e1b2..7061d1f86b 100644 --- a/src/USER-MGPT/pair_mgpt.cpp +++ b/src/USER-MGPT/pair_mgpt.cpp @@ -23,20 +23,18 @@ #include "pair_mgpt.h" -#include - -#include -#include - #include "atom.h" -#include "force.h" #include "comm.h" -#include "neighbor.h" +#include "error.h" +#include "force.h" +#include "memory.h" #include "neigh_list.h" #include "neigh_request.h" -#include "memory.h" -#include "error.h" +#include "neighbor.h" +#include +#include +#include using namespace LAMMPS_NS; diff --git a/src/USER-MISC/compute_gyration_shape.cpp b/src/USER-MISC/compute_gyration_shape.cpp index daec7a6b4b..ac073d4cbc 100644 --- a/src/USER-MISC/compute_gyration_shape.cpp +++ b/src/USER-MISC/compute_gyration_shape.cpp @@ -15,17 +15,18 @@ * Contributing author: Evangelos Voyiatzis (Royal DSM) * ------------------------------------------------------------------------- */ - #include "compute_gyration_shape.h" -#include -#include + #include "error.h" -#include "math_extra.h" #include "math_eigen.h" +#include "math_extra.h" #include "math_special.h" #include "modify.h" #include "update.h" +#include +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ @@ -41,9 +42,7 @@ ComputeGyrationShape::ComputeGyrationShape(LAMMPS *lmp, int narg, char **arg) : extvector = 0; // ID of compute gyration - int n = strlen(arg[3]) + 1; - id_gyration = new char[n]; - strcpy(id_gyration,arg[3]); + id_gyration = utils::strdup(arg[3]); init(); diff --git a/src/USER-MISC/compute_gyration_shape_chunk.cpp b/src/USER-MISC/compute_gyration_shape_chunk.cpp index e0ab646ce2..e66173d704 100644 --- a/src/USER-MISC/compute_gyration_shape_chunk.cpp +++ b/src/USER-MISC/compute_gyration_shape_chunk.cpp @@ -15,17 +15,18 @@ * Contributing author: Evangelos Voyiatzis (Royal DSM) * ------------------------------------------------------------------------- */ - #include "compute_gyration_shape_chunk.h" + +#include "error.h" +#include "math_eigen.h" +#include "math_extra.h" +#include "math_special.h" +#include "memory.h" +#include "modify.h" +#include "update.h" + #include #include -#include "error.h" -#include "math_extra.h" -#include "math_eigen.h" -#include "math_special.h" -#include "modify.h" -#include "memory.h" -#include "update.h" using namespace LAMMPS_NS; @@ -37,9 +38,7 @@ ComputeGyrationShapeChunk::ComputeGyrationShapeChunk(LAMMPS *lmp, int narg, char if (narg != 4) error->all(FLERR,"Illegal compute gyration/shape/chunk command"); // ID of compute gyration - int n = strlen(arg[3]) + 1; - id_gyration_chunk = new char[n]; - strcpy(id_gyration_chunk,arg[3]); + id_gyration_chunk = utils::strdup(arg[3]); init(); diff --git a/src/USER-MISC/compute_hma.cpp b/src/USER-MISC/compute_hma.cpp index 8220abebc4..fbe8c67d39 100644 --- a/src/USER-MISC/compute_hma.cpp +++ b/src/USER-MISC/compute_hma.cpp @@ -78,11 +78,7 @@ ComputeHMA::ComputeHMA(LAMMPS *lmp, int narg, char **arg) : if (narg < 4) error->all(FLERR,"Illegal compute hma command"); if (igroup) error->all(FLERR,"Compute hma must use group all"); if (strcmp(arg[3],"NULL") == 0) {error->all(FLERR,"fix ID specifying the set temperature of canonical simulation is required");} - else { - int n = strlen(arg[3]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[3]); - } + else id_temp = utils::strdup(arg[3]); create_attribute = 1; extscalar = 1; @@ -92,23 +88,11 @@ ComputeHMA::ComputeHMA(LAMMPS *lmp, int narg, char **arg) : // our new fix's id (id_fix)= compute-ID + COMPUTE_STORE // our new fix's group = same as compute group - int n = strlen(id) + strlen("_COMPUTE_STORE") + 1; - id_fix = new char[n]; - strcpy(id_fix,id); - strcat(id_fix,"_COMPUTE_STORE"); - - char **newarg = new char*[6]; - newarg[0] = id_fix; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "peratom"; - newarg[4] = (char *) "1"; - newarg[5] = (char *) "3"; - modify->add_fix(6,newarg); + id_fix = utils::strdup(std::string(id)+"_COMPUTE_STORE"); + modify->add_fix(fmt::format("{} {} STORE peratom 1 3", + id_fix, group->names[igroup])); fix = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; - // calculate xu,yu,zu for fix store array // skip if reset from restart file diff --git a/src/USER-MISC/compute_pressure_grem.cpp b/src/USER-MISC/compute_pressure_grem.cpp index 6ba4462c29..98f699491f 100644 --- a/src/USER-MISC/compute_pressure_grem.cpp +++ b/src/USER-MISC/compute_pressure_grem.cpp @@ -12,7 +12,7 @@ ------------------------------------------------------------------------- */ #include "compute_pressure_grem.h" -#include + #include "update.h" #include "domain.h" #include "modify.h" @@ -21,6 +21,8 @@ #include "kspace.h" #include "error.h" +#include + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- @@ -30,9 +32,7 @@ using namespace LAMMPS_NS; ComputePressureGrem::ComputePressureGrem(LAMMPS *lmp, int narg, char **arg) : ComputePressure(lmp, narg-1, arg) { - int len = strlen(arg[narg-1])+1; - fix_grem = new char[len]; - strcpy(fix_grem,arg[narg-1]); + fix_grem = utils::strdup(arg[narg-1]); } /* ---------------------------------------------------------------------- */ From 806f4e73edf18719a18d9255ac8dbc97b647cd6b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 29 Mar 2021 07:32:43 -0400 Subject: [PATCH 175/257] make dihedral style table/cut a derived class from table and remove redundant code --- src/USER-MISC/dihedral_table.cpp | 67 +-- src/USER-MISC/dihedral_table.h | 8 +- src/USER-MISC/dihedral_table_cut.cpp | 842 ++------------------------- src/USER-MISC/dihedral_table_cut.h | 118 +--- 4 files changed, 62 insertions(+), 973 deletions(-) diff --git a/src/USER-MISC/dihedral_table.cpp b/src/USER-MISC/dihedral_table.cpp index a81037cad6..ffbc9aad31 100644 --- a/src/USER-MISC/dihedral_table.cpp +++ b/src/USER-MISC/dihedral_table.cpp @@ -464,7 +464,6 @@ DihedralTable::~DihedralTable() if (allocated) { memory->destroy(setflag); - //memory->destroy(phi0); <- equilibrium angles not supported memory->destroy(tabindex); } } @@ -718,49 +717,18 @@ void DihedralTable::compute(int eflag, int vflag) } } // void DihedralTable::compute() - - - - - - -// single() calculates the dihedral-angle energy of atoms i1, i2, i3, i4. -double DihedralTable::single(int type, int i1, int i2, int i3, int i4) -{ - double vb12[g_dim]; - double vb23[g_dim]; - double vb34[g_dim]; - double n123[g_dim]; - double n234[g_dim]; - - double **x = atom->x; - - double phi = Phi(x[i1], x[i2], x[i3], x[i4], domain, - vb12, vb23, vb34, n123, n234); - - double u=0.0; - u_lookup(type, phi, u); //Calculate the energy, and store it in "u" - - return u; -} - - /* ---------------------------------------------------------------------- */ - - void DihedralTable::allocate() { allocated = 1; int n = atom->ndihedraltypes; memory->create(tabindex,n+1,"dihedral:tabindex"); - //memory->create(phi0,n+1,"dihedral:phi0"); <-equilibrium angles not supported memory->create(setflag,n+1,"dihedral:setflag"); for (int i = 1; i <= n; i++) setflag[i] = 0; } - /* ---------------------------------------------------------------------- global settings ------------------------------------------------------------------------- */ @@ -791,16 +759,13 @@ void DihedralTable::settings(int narg, char **arg) tables = nullptr; } - - /* ---------------------------------------------------------------------- set coeffs for one type ------------------------------------------------------------------------- */ - void DihedralTable::coeff(int narg, char **arg) { - if (narg != 3) error->all(FLERR,"Illegal dihedral_coeff command"); + if (narg != 3) error->all(FLERR,"Incorrect args for dihedral coefficients"); if (!allocated) allocate(); int ilo,ihi; @@ -815,25 +780,22 @@ void DihedralTable::coeff(int narg, char **arg) if (me == 0) read_table(tb,arg[1],arg[2]); bcast_table(tb); - // --- check the angle data for range errors --- // --- and resolve issues with periodicity --- - if (tb->ninput < 2) { - error->one(FLERR,fmt::format("Invalid dihedral table length ({}).", - arg[2])); - } else if ((tb->ninput == 2) && (tabstyle == SPLINE)) { - error->one(FLERR,fmt::format("Invalid dihedral spline table length. " - "(Try linear)\n ({}).",arg[2])); - } + if (tb->ninput < 2) + error->all(FLERR,fmt::format("Invalid dihedral table length: {}",arg[2])); + else if ((tb->ninput == 2) && (tabstyle == SPLINE)) + error->all(FLERR,fmt::format("Invalid dihedral spline table length: {} " + "(Try linear)",arg[2])); // check for monotonicity for (int i=0; i < tb->ninput-1; i++) { if (tb->phifile[i] >= tb->phifile[i+1]) { auto err_msg = fmt::format("Dihedral table values are not increasing " - "({}, {}th entry)",arg[2],i+1); + "({}, entry {})",arg[2],i+1); if (i==0) - err_msg += std::string("\n(This is probably a mistake with your table format.)\n"); + err_msg += "\n(This is probably a mistake with your table format.)\n"; error->all(FLERR,err_msg); } } @@ -971,15 +933,12 @@ void DihedralTable::coeff(int narg, char **arg) } ntables++; - if (count == 0) - error->all(FLERR,"Illegal dihedral_coeff command"); - -} //DihedralTable::coeff() - + if (count == 0) error->all(FLERR,"Incorrect args for dihedral coefficients"); +} /* ---------------------------------------------------------------------- - proc 0 writes to restart file - ------------------------------------------------------------------------- */ + proc 0 writes out coeffs to restart file +------------------------------------------------------------------------- */ void DihedralTable::write_restart(FILE *fp) { @@ -1065,7 +1024,6 @@ void DihedralTable::read_table(Table *tb, char *file, char *keyword) error->one(FLERR,"Did not find keyword in table file"); } - // read args on 2nd line of section // allocate table arrays for file values @@ -1279,7 +1237,6 @@ void DihedralTable::compute_table(Table *tb) void DihedralTable::param_extract(Table *tb, char *line) { - //tb->theta0 = 180.0; <- equilibrium angles not supported tb->ninput = 0; tb->f_unspecified = false; //default tb->use_degrees = true; //default diff --git a/src/USER-MISC/dihedral_table.h b/src/USER-MISC/dihedral_table.h index a8d1f8f8bb..9d5b03f5cc 100644 --- a/src/USER-MISC/dihedral_table.h +++ b/src/USER-MISC/dihedral_table.h @@ -25,7 +25,6 @@ DihedralStyle(table,DihedralTable) #define LMP_DIHEDRAL_TABLE_H #include "dihedral.h" - namespace LAMMPS_NS { class DihedralTable : public Dihedral { @@ -34,7 +33,7 @@ class DihedralTable : public Dihedral { virtual ~DihedralTable(); virtual void compute(int, int); void settings(int, char **); - void coeff(int, char **); + virtual void coeff(int, char **); void write_restart(FILE *); void read_restart(FILE *); void write_restart_settings(FILE *); @@ -43,13 +42,11 @@ class DihedralTable : public Dihedral { protected: int tabstyle,tablength; - // double *phi0; <- equilibrium angles not supported std::string checkU_fname; std::string checkF_fname; struct Table { int ninput; - //double phi0; <-equilibrium angles not supported int f_unspecified; // boolean (but MPI does not like type "bool") int use_degrees; // boolean (but MPI does not like type "bool") double *phifile,*efile,*ffile; @@ -62,7 +59,7 @@ class DihedralTable : public Dihedral { Table *tables; int *tabindex; - void allocate(); + virtual void allocate(); void null_table(Table *); void free_table(Table *); void read_table(Table *, char *, char *); @@ -152,6 +149,5 @@ class DihedralTable : public Dihedral { } // namespace LAMMPS_NS - #endif //#ifndef LMP_DIHEDRAL_TABLE_H #endif //#ifdef DIHEDRAL_CLASS ... #else diff --git a/src/USER-MISC/dihedral_table_cut.cpp b/src/USER-MISC/dihedral_table_cut.cpp index ed7b3ac0d6..dc7a6f9685 100644 --- a/src/USER-MISC/dihedral_table_cut.cpp +++ b/src/USER-MISC/dihedral_table_cut.cpp @@ -18,28 +18,23 @@ #include "dihedral_table_cut.h" -#include +#include "atom.h" +#include "citeme.h" +#include "comm.h" +#include "error.h" +#include "force.h" +#include "math_const.h" +#include "memory.h" +#include "neighbor.h" +#include "update.h" + #include - #include - #include // IWYU pragma: keep #include // IWYU pragma: keep -#include "atom.h" -#include "neighbor.h" -#include "update.h" -#include "comm.h" -#include "force.h" -#include "citeme.h" -#include "math_const.h" -#include "memory.h" -#include "error.h" - - using namespace LAMMPS_NS; using namespace MathConst; -using namespace std; static const char cite_dihedral_tablecut[] = "dihedral_style table/cut command:\n\n" @@ -89,272 +84,6 @@ enum { //GSL status return codes. }; -static int solve_cyc_tridiag( const double diag[], size_t d_stride, - const double offdiag[], size_t o_stride, - const double b[], size_t b_stride, - double x[], size_t x_stride, - size_t N, bool warn) -{ - int status = GSL_SUCCESS; - double * delta = (double *) malloc (N * sizeof (double)); - double * gamma = (double *) malloc (N * sizeof (double)); - double * alpha = (double *) malloc (N * sizeof (double)); - double * c = (double *) malloc (N * sizeof (double)); - double * z = (double *) malloc (N * sizeof (double)); - - if (delta == 0 || gamma == 0 || alpha == 0 || c == 0 || z == 0) { - if (warn) - fprintf(stderr,"Internal Cyclic Spline Error: failed to allocate working space\n"); - - if (delta) free(delta); - if (gamma) free(gamma); - if (alpha) free(alpha); - if (c) free(c); - if (z) free(z); - return GSL_ENOMEM; - } - else - { - size_t i, j; - double sum = 0.0; - - /* factor */ - - if (N == 1) - { - x[0] = b[0] / diag[0]; - free(delta); - free(gamma); - free(alpha); - free(c); - free(z); - return GSL_SUCCESS; - } - - alpha[0] = diag[0]; - gamma[0] = offdiag[0] / alpha[0]; - delta[0] = offdiag[o_stride * (N-1)] / alpha[0]; - - if (alpha[0] == 0) { - status = GSL_EZERODIV; - } - - for (i = 1; i < N - 2; i++) - { - alpha[i] = diag[d_stride * i] - offdiag[o_stride * (i-1)] * gamma[i - 1]; - gamma[i] = offdiag[o_stride * i] / alpha[i]; - delta[i] = -delta[i - 1] * offdiag[o_stride * (i-1)] / alpha[i]; - if (alpha[i] == 0) { - status = GSL_EZERODIV; - } - } - - for (i = 0; i < N - 2; i++) - { - sum += alpha[i] * delta[i] * delta[i]; - } - - alpha[N - 2] = diag[d_stride * (N - 2)] - offdiag[o_stride * (N - 3)] * gamma[N - 3]; - - gamma[N - 2] = (offdiag[o_stride * (N - 2)] - offdiag[o_stride * (N - 3)] * delta[N - 3]) / alpha[N - 2]; - - alpha[N - 1] = diag[d_stride * (N - 1)] - sum - alpha[(N - 2)] * gamma[N - 2] * gamma[N - 2]; - - /* update */ - z[0] = b[0]; - for (i = 1; i < N - 1; i++) - { - z[i] = b[b_stride * i] - z[i - 1] * gamma[i - 1]; - } - sum = 0.0; - for (i = 0; i < N - 2; i++) - { - sum += delta[i] * z[i]; - } - z[N - 1] = b[b_stride * (N - 1)] - sum - gamma[N - 2] * z[N - 2]; - for (i = 0; i < N; i++) - { - c[i] = z[i] / alpha[i]; - } - - /* backsubstitution */ - x[x_stride * (N - 1)] = c[N - 1]; - x[x_stride * (N - 2)] = c[N - 2] - gamma[N - 2] * x[x_stride * (N - 1)]; - if (N >= 3) - { - for (i = N - 3, j = 0; j <= N - 3; j++, i--) - { - x[x_stride * i] = c[i] - gamma[i] * x[x_stride * (i + 1)] - delta[i] * x[x_stride * (N - 1)]; - } - } - } - - free (z); - free (c); - free (alpha); - free (gamma); - free (delta); - - if ((status == GSL_EZERODIV) && warn) - fprintf(stderr, "Internal Cyclic Spline Error: Matrix must be positive definite.\n"); - - return status; -} //solve_cyc_tridiag() - -/* ---------------------------------------------------------------------- - spline and splint routines modified from Numerical Recipes -------------------------------------------------------------------------- */ - -static int cyc_spline(double const *xa, - double const *ya, - int n, - double period, - double *y2a, bool warn) -{ - - double *diag = new double[n]; - double *offdiag = new double[n]; - double *rhs = new double[n]; - double xa_im1, xa_ip1; - - // In the cyclic case, there are n equations with n unknows. - // The for loop sets up the equations we need to solve. - // Later we invoke the GSL tridiagonal matrix solver to solve them. - - for (int i=0; i < n; i++) { - - // I have to lookup xa[i+1] and xa[i-1]. This gets tricky because of - // periodic boundary conditions. We handle that now. - int im1 = i-1; - if (im1<0) { - im1 += n; - xa_im1 = xa[im1] - period; - } - else - xa_im1 = xa[im1]; - - int ip1 = i+1; - if (ip1>=n) { - ip1 -= n; - xa_ip1 = xa[ip1] + period; - } - else - xa_ip1 = xa[ip1]; - - // Recall that we want to find the y2a[] parameters (there are n of them). - // To solve for them, we have a linear equation with n unknowns - // (in the cyclic case that is). For details, the non-cyclic case is - // explained in equation 3.3.7 in Numerical Recipes in C, p. 115. - diag[i] = (xa_ip1 - xa_im1) / 3.0; - offdiag[i] = (xa_ip1 - xa[i]) / 6.0; - rhs[i] = ((ya[ip1] - ya[i]) / (xa_ip1 - xa[i])) - - ((ya[i] - ya[im1]) / (xa[i] - xa_im1)); - } - - // Because this matrix is tridiagonal (and cyclic), we can use the following - // cheap method to invert it. - if (solve_cyc_tridiag(diag, 1, - offdiag, 1, - rhs, 1, - y2a, 1, - n, warn) != GSL_SUCCESS) { - if (warn) - fprintf(stderr,"Error in inverting matrix for splines.\n"); - - delete [] diag; - delete [] offdiag; - delete [] rhs; - return 1; - } - delete [] diag; - delete [] offdiag; - delete [] rhs; - return 0; -} // cyc_spline() - -/* ---------------------------------------------------------------------- */ - -// cyc_splint(): Evaluates a spline at position x, with n control -// points located at xa[], ya[], and with parameters y2a[] -// The xa[] must be monotonically increasing and their -// range should not exceed period (ie xa[n-1] < xa[0] + period). -// x must lie in the range: [(xa[n-1]-period), (xa[0]+period)] -// "period" is typically 2*PI. -static double cyc_splint(double const *xa, - double const *ya, - double const *y2a, - int n, - double period, - double x) -{ - int klo = -1; - int khi = n; - int k; - double xlo = xa[n-1] - period; - double xhi = xa[0] + period; - while (khi-klo > 1) { - k = (khi+klo) >> 1; //(k=(khi+klo)/2) - if (xa[k] > x) { - khi = k; - xhi = xa[k]; - } - else { - klo = k; - xlo = xa[k]; - } - } - - if (khi == n) khi = 0; - if (klo ==-1) klo = n-1; - - double h = xhi-xlo; - double a = (xhi-x) / h; - double b = (x-xlo) / h; - double y = a*ya[klo] + b*ya[khi] + - ((a*a*a-a)*y2a[klo] + (b*b*b-b)*y2a[khi]) * (h*h)/6.0; - - return y; - -} // cyc_splint() - - -static double cyc_lin(double const *xa, - double const *ya, - int n, - double period, - double x) -{ - int klo = -1; - int khi = n; - int k; - double xlo = xa[n-1] - period; - double xhi = xa[0] + period; - while (khi-klo > 1) { - k = (khi+klo) >> 1; //(k=(khi+klo)/2) - if (xa[k] > x) { - khi = k; - xhi = xa[k]; - } - else { - klo = k; - xlo = xa[k]; - } - } - - if (khi == n) khi = 0; - if (klo ==-1) klo = n-1; - - double h = xhi-xlo; - double a = (xhi-x) / h; - double b = (x-xlo) / h; - double y = a*ya[klo] + b*ya[khi]; - - return y; - -} // cyc_lin() - - - // cyc_splintD(): Evaluate the deriviative of a cyclic spline at position x, // with n control points at xa[], ya[], with parameters y2a[]. @@ -405,35 +134,26 @@ static double cyc_splintD(double const *xa, } // cyc_splintD() +// -------------------------------------------- +// ------- Calculate the dihedral angle ------- +// -------------------------------------------- +static const int g_dim=3; /* ---------------------------------------------------------------------- */ -DihedralTableCut::DihedralTableCut(LAMMPS *lmp) : Dihedral(lmp) +DihedralTableCut::DihedralTableCut(LAMMPS *lmp) : DihedralTable(lmp) { if (lmp->citeme) lmp->citeme->add(cite_dihedral_tablecut); - ntables = 0; - tables = nullptr; - checkU_fname = checkF_fname = nullptr; + aat_k = aat_theta0_1 = aat_theta0_2 = nullptr; } /* ---------------------------------------------------------------------- */ DihedralTableCut::~DihedralTableCut() { - if (allocated) { - memory->destroy(aat_k); - memory->destroy(aat_theta0_1); - memory->destroy(aat_theta0_2); - - for (int m = 0; m < ntables; m++) free_table(&tables[m]); - memory->sfree(tables); - memory->sfree(checkU_fname); - memory->sfree(checkF_fname); - - memory->destroy(setflag); - memory->destroy(tabindex); - - } + memory->destroy(aat_k); + memory->destroy(aat_theta0_1); + memory->destroy(aat_theta0_2); } /* ---------------------------------------------------------------------- */ @@ -702,7 +422,7 @@ void DihedralTableCut::compute(int eflag, int vflag) for (i = 0; i < 4; i++) for (j = 0; j < 3; j++) - fabcd[i][j] -= - gt*gtt*fpphi*dphidr[i][j] + fabcd[i][j] -= gt*gtt*fpphi*dphidr[i][j] - gt*gptt*fphi*dthetadr[1][i][j] + gpt*gtt*fphi*dthetadr[0][i][j]; // apply force to each of 4 atoms @@ -751,35 +471,7 @@ void DihedralTableCut::allocate() memory->create(tabindex,n+1,"dihedral:tabindex"); memory->create(setflag,n+1,"dihedral:setflag"); - - for (int i = 1; i <= n; i++) - setflag[i] = 0; -} - -void DihedralTableCut::settings(int narg, char **arg) -{ - if (narg != 2) error->all(FLERR,"Illegal dihedral_style command"); - - if (strcmp(arg[0],"linear") == 0) tabstyle = LINEAR; - else if (strcmp(arg[0],"spline") == 0) tabstyle = SPLINE; - else error->all(FLERR,"Unknown table style in dihedral style table_cut"); - - tablength = utils::inumeric(FLERR,arg[1],false,lmp); - if (tablength < 3) - error->all(FLERR,"Illegal number of dihedral table entries"); - // delete old tables, since cannot just change settings - - for (int m = 0; m < ntables; m++) free_table(&tables[m]); - memory->sfree(tables); - - if (allocated) { - memory->destroy(setflag); - memory->destroy(tabindex); - } - allocated = 0; - - ntables = 0; - tables = nullptr; + for (int i = 1; i <= n; i++) setflag[i] = 0; } /* ---------------------------------------------------------------------- @@ -790,9 +482,9 @@ void DihedralTableCut::settings(int narg, char **arg) void DihedralTableCut::coeff(int narg, char **arg) { - if (narg != 7) error->all(FLERR,"Incorrect args for dihedral coefficients"); if (!allocated) allocate(); + int ilo,ihi; utils::bounds(FLERR,arg[0],1,atom->ndihedraltypes,ilo,ihi,error); @@ -820,29 +512,19 @@ void DihedralTableCut::coeff(int narg, char **arg) // --- check the angle data for range errors --- // --- and resolve issues with periodicity --- - if (tb->ninput < 2) { - string err_msg; - err_msg = string("Invalid dihedral table length (") - + string(arg[5]) + string(")."); - error->one(FLERR,err_msg); - } - else if ((tb->ninput == 2) && (tabstyle == SPLINE)) { - string err_msg; - err_msg = string("Invalid dihedral spline table length. (Try linear)\n (") - + string(arg[5]) + string(")."); - error->one(FLERR,err_msg); - } + if (tb->ninput < 2) + error->all(FLERR,fmt::format("Invalid dihedral table length: {}",arg[5])); + else if ((tb->ninput == 2) && (tabstyle == SPLINE)) + error->all(FLERR,fmt::format("Invalid dihedral spline table length: {} " + "(Try linear)",arg[5])); // check for monotonicity for (int i=0; i < tb->ninput-1; i++) { if (tb->phifile[i] >= tb->phifile[i+1]) { - stringstream i_str; - i_str << i+1; - string err_msg = - string("Dihedral table values are not increasing (") + - string(arg[5]) + string(", ")+i_str.str()+string("th entry)"); + auto err_msg =fmt::format("Dihedral table values are not increasing " + "({}, entry {})",arg[5],i+1); if (i==0) - err_msg += string("\n(This is probably a mistake with your table format.)\n"); + err_msg += "\n(This is probably a mistake with your table format.)\n"; error->all(FLERR,err_msg); } } @@ -851,20 +533,13 @@ void DihedralTableCut::coeff(int narg, char **arg) double philo = tb->phifile[0]; double phihi = tb->phifile[tb->ninput-1]; if (tb->use_degrees) { - if ((phihi - philo) >= 360) { - string err_msg; - err_msg = string("Dihedral table angle range must be < 360 degrees (") - +string(arg[5]) + string(")."); - error->all(FLERR,err_msg); - } - } - else { - if ((phihi - philo) >= MY_2PI) { - string err_msg; - err_msg = string("Dihedral table angle range must be < 2*PI radians (") - + string(arg[5]) + string(")."); - error->all(FLERR,err_msg); - } + if ((phihi - philo) >= 360) + error->all(FLERR,fmt::format("Dihedral table angle range must be < 360 " + "degrees ({})",arg[5])); + } else { + if ((phihi - philo) >= MY_2PI) + error->all(FLERR,fmt::format("Dihedral table angle range must be < 2*PI " + "radians ({})",arg[5])); } // convert phi from degrees to radians @@ -932,10 +607,9 @@ void DihedralTableCut::coeff(int narg, char **arg) // Optional: allow the user to print out the interpolated spline tables if (me == 0) { - if (checkU_fname && (strlen(checkU_fname) != 0)) - { - ofstream checkU_file; - checkU_file.open(checkU_fname, ios::out); + if (!checkU_fname.empty()) { + std::ofstream checkU_file; + checkU_file.open(checkU_fname, std::ios::out); for (int i=0; i < tablength; i++) { double phi = i*MY_2PI/tablength; double u = tb->e[i]; @@ -945,12 +619,10 @@ void DihedralTableCut::coeff(int narg, char **arg) } checkU_file.close(); } - if (checkF_fname && (strlen(checkF_fname) != 0)) - { - ofstream checkF_file; - checkF_file.open(checkF_fname, ios::out); - for (int i=0; i < tablength; i++) - { + if (!checkF_fname.empty()) { + std::ofstream checkF_file; + checkF_file.open(checkF_fname, std::ios::out); + for (int i=0; i < tablength; i++) { double phi = i*MY_2PI/tablength; double f; if ((tabstyle == SPLINE) && (tb->f_unspecified)) { @@ -992,429 +664,3 @@ void DihedralTableCut::coeff(int narg, char **arg) if (count == 0) error->all(FLERR,"Incorrect args for dihedral coefficients"); } - -/* ---------------------------------------------------------------------- - proc 0 writes out coeffs to restart file -------------------------------------------------------------------------- */ - -void DihedralTableCut::write_restart(FILE *fp) -{ - write_restart_settings(fp); -} - -/* ---------------------------------------------------------------------- - proc 0 reads coeffs from restart file, bcasts them -------------------------------------------------------------------------- */ - -void DihedralTableCut::read_restart(FILE *fp) -{ - read_restart_settings(fp); - allocate(); -} - -/* ---------------------------------------------------------------------- - proc 0 writes out coeffs to restart file -------------------------------------------------------------------------- */ - -void DihedralTableCut::write_restart_settings(FILE *fp) -{ - fwrite(&tabstyle,sizeof(int),1,fp); - fwrite(&tablength,sizeof(int),1,fp); -} - -/* ---------------------------------------------------------------------- - proc 0 reads coeffs from restart file, bcasts them -------------------------------------------------------------------------- */ - -void DihedralTableCut::read_restart_settings(FILE *fp) -{ - if (comm->me == 0) { - utils::sfread(FLERR,&tabstyle,sizeof(int),1,fp,nullptr,error); - utils::sfread(FLERR,&tablength,sizeof(int),1,fp,nullptr,error); - } - - MPI_Bcast(&tabstyle,1,MPI_INT,0,world); - MPI_Bcast(&tablength,1,MPI_INT,0,world); -} - -/* ---------------------------------------------------------------------- */ - -void DihedralTableCut::null_table(Table *tb) -{ - tb->phifile = tb->efile = tb->ffile = nullptr; - tb->e2file = tb->f2file = nullptr; - tb->phi = tb->e = tb->de = nullptr; - tb->f = tb->df = tb->e2 = tb->f2 = nullptr; -} - -/* ---------------------------------------------------------------------- */ - -void DihedralTableCut::free_table(Table *tb) -{ - memory->destroy(tb->phifile); - memory->destroy(tb->efile); - memory->destroy(tb->ffile); - memory->destroy(tb->e2file); - memory->destroy(tb->f2file); - - memory->destroy(tb->phi); - memory->destroy(tb->e); - memory->destroy(tb->de); - memory->destroy(tb->f); - memory->destroy(tb->df); - memory->destroy(tb->e2); - memory->destroy(tb->f2); -} - -/* ---------------------------------------------------------------------- - read table file, only called by proc 0 -------------------------------------------------------------------------- */ - -static const int MAXLINE=2048; - -void DihedralTableCut::read_table(Table *tb, char *file, char *keyword) -{ - char line[MAXLINE]; - - // open file - - FILE *fp = utils::open_potential(file,lmp,nullptr); - if (fp == nullptr) { - string err_msg = string("Cannot open file ") + string(file); - error->one(FLERR,err_msg); - } - - // loop until section found with matching keyword - - while (1) { - if (fgets(line,MAXLINE,fp) == nullptr) { - string err_msg=string("Did not find keyword \"") - +string(keyword)+string("\" in dihedral table file."); - error->one(FLERR, err_msg); - } - if (strspn(line," \t\n\r") == strlen(line)) continue; // blank line - if (line[0] == '#') continue; // comment - char *word = strtok(line," \t\n\r"); - if (strcmp(word,keyword) == 0) break; // matching keyword - utils::sfgets(FLERR,line,MAXLINE,fp,file,error); // no match, skip section - param_extract(tb,line); - utils::sfgets(FLERR,line,MAXLINE,fp,file,error); - for (int i = 0; i < tb->ninput; i++) - utils::sfgets(FLERR,line,MAXLINE,fp,file,error); - } - - // read args on 2nd line of section - // allocate table arrays for file values - - utils::sfgets(FLERR,line,MAXLINE,fp,file,error); - param_extract(tb,line); - memory->create(tb->phifile,tb->ninput,"dihedral:phifile"); - memory->create(tb->efile,tb->ninput,"dihedral:efile"); - memory->create(tb->ffile,tb->ninput,"dihedral:ffile"); - - // read a,e,f table values from file - - int itmp; - for (int i = 0; i < tb->ninput; i++) { - // Read the next line. Make sure the file is long enough. - utils::sfgets(FLERR,line,MAXLINE,fp,file,error); - - // Skip blank lines and delete text following a '#' character - char *pe = strchr(line, '#'); - if (pe != nullptr) *pe = '\0'; //terminate string at '#' character - char *pc = line; - while ((*pc != '\0') && isspace(*pc)) - pc++; - if (*pc != '\0') { //If line is not a blank line - stringstream line_ss(line); - if (tb->f_unspecified) { - line_ss >> itmp; - line_ss >> tb->phifile[i]; - line_ss >> tb->efile[i]; - } else { - line_ss >> itmp; - line_ss >> tb->phifile[i]; - line_ss >> tb->efile[i]; - line_ss >> tb->ffile[i]; - } - if (! line_ss) { - stringstream err_msg; - err_msg << "Read error in table "<< keyword<<", near line "<f_unspecified) && (i==0)) - err_msg << "\n (This sometimes occurs if users forget to specify the \"NOF\" option.)\n"; - error->one(FLERR, err_msg.str().c_str()); - } - } else //if it is a blank line, then skip it. - i--; - } //for (int i = 0; (i < tb->ninput) && fp; i++) { - - fclose(fp); -} - -/* ---------------------------------------------------------------------- - build spline representation of e,f over entire range of read-in table - this function sets these values in e2file,f2file. - I also perform a crude check for force & energy consistency. -------------------------------------------------------------------------- */ - -void DihedralTableCut::spline_table(Table *tb) -{ - memory->create(tb->e2file,tb->ninput,"dihedral:e2file"); - memory->create(tb->f2file,tb->ninput,"dihedral:f2file"); - - if (cyc_spline(tb->phifile, tb->efile, tb->ninput, - MY_2PI,tb->e2file,comm->me == 0)) - error->one(FLERR,"Error computing dihedral spline tables"); - - if (! tb->f_unspecified) { - if (cyc_spline(tb->phifile, tb->ffile, tb->ninput, - MY_2PI, tb->f2file, comm->me == 0)) - error->one(FLERR,"Error computing dihedral spline tables"); - } - - // CHECK to help make sure the user calculated forces in a way - // which is grossly numerically consistent with the energy table. - if (! tb->f_unspecified) { - int num_disagreements = 0; - for (int i=0; ininput; i++) { - - // Calculate what the force should be at the control points - // by using linear interpolation of the derivatives of the energy: - - double phi_i = tb->phifile[i]; - - // First deal with periodicity - double phi_im1, phi_ip1; - int im1 = i-1; - if (im1 < 0) { - im1 += tb->ninput; - phi_im1 = tb->phifile[im1] - MY_2PI; - } - else - phi_im1 = tb->phifile[im1]; - int ip1 = i+1; - if (ip1 >= tb->ninput) { - ip1 -= tb->ninput; - phi_ip1 = tb->phifile[ip1] + MY_2PI; - } - else - phi_ip1 = tb->phifile[ip1]; - - // Now calculate the midpoints above and below phi_i = tb->phifile[i] - double phi_lo= 0.5*(phi_im1 + phi_i); //midpoint between phi_im1 and phi_i - double phi_hi= 0.5*(phi_i + phi_ip1); //midpoint between phi_i and phi_ip1 - - // Use a linear approximation to the derivative at these two midpoints - double dU_dphi_lo = - (tb->efile[i] - tb->efile[im1]) - / - (phi_i - phi_im1); - double dU_dphi_hi = - (tb->efile[ip1] - tb->efile[i]) - / - (phi_ip1 - phi_i); - - // Now calculate the derivative at position - // phi_i (=tb->phifile[i]) using linear interpolation - - double a = (phi_i - phi_lo) / (phi_hi - phi_lo); - double b = (phi_hi - phi_i) / (phi_hi - phi_lo); - double dU_dphi = a*dU_dphi_lo + b*dU_dphi_hi; - double f = -dU_dphi; - // Alternately, we could use spline interpolation instead: - // double f = - splintD(tb->phifile, tb->efile, tb->e2file, - // tb->ninput, MY_2PI, tb->phifile[i]); - // This is the way I originally did it, but I trust - // the ugly simple linear way above better. - // Recall this entire block of code doess not calculate - // anything important. It does not have to be perfect. - // We are only checking for stupid user errors here. - - if ((f != 0.0) && - (tb->ffile[i] != 0.0) && - ((f/tb->ffile[i] < 0.5) || (f/tb->ffile[i] > 2.0))) { - num_disagreements++; - } - } // for (int i=0; ininput; i++) - - if ((num_disagreements > tb->ninput/2) && (num_disagreements > 2)) { - string msg("Dihedral table has inconsistent forces and energies. (Try \"NOF\".)\n"); - error->all(FLERR,msg.c_str()); - } - - } // check for consistency if (! tb->f_unspecified) - -} // DihedralTable::spline_table() - - -/* ---------------------------------------------------------------------- - compute a,e,f vectors from splined values -------------------------------------------------------------------------- */ - -void DihedralTableCut::compute_table(Table *tb) -{ - //delta = table spacing in dihedral angle for tablength (cyclic) bins - tb->delta = MY_2PI / tablength; - tb->invdelta = 1.0/tb->delta; - tb->deltasq6 = tb->delta*tb->delta / 6.0; - - // N evenly spaced bins in dihedral angle from 0 to 2*PI - // phi,e,f = value at lower edge of bin - // de,df values = delta values of e,f (cyclic, in this case) - // phi,e,f,de,df are arrays containing "tablength" number of entries - - memory->create(tb->phi,tablength,"dihedral:phi"); - memory->create(tb->e,tablength,"dihedral:e"); - memory->create(tb->de,tablength,"dihedral:de"); - memory->create(tb->f,tablength,"dihedral:f"); - memory->create(tb->df,tablength,"dihedral:df"); - memory->create(tb->e2,tablength,"dihedral:e2"); - memory->create(tb->f2,tablength,"dihedral:f2"); - - if (tabstyle == SPLINE) { - // Use cubic spline interpolation to calculate the entries in the - // internal table. (This is true regardless...even if tabstyle!=SPLINE.) - for (int i = 0; i < tablength; i++) { - double phi = i*tb->delta; - tb->phi[i] = phi; - tb->e[i]= cyc_splint(tb->phifile,tb->efile,tb->e2file,tb->ninput,MY_2PI,phi); - if (! tb->f_unspecified) - tb->f[i] = cyc_splint(tb->phifile,tb->ffile,tb->f2file,tb->ninput,MY_2PI,phi); - } - } // if (tabstyle == SPLINE) - else if (tabstyle == LINEAR) { - if (! tb->f_unspecified) { - for (int i = 0; i < tablength; i++) { - double phi = i*tb->delta; - tb->phi[i] = phi; - tb->e[i]= cyc_lin(tb->phifile,tb->efile,tb->ninput,MY_2PI,phi); - tb->f[i]= cyc_lin(tb->phifile,tb->ffile,tb->ninput,MY_2PI,phi); - } - } - else { - for (int i = 0; i < tablength; i++) { - double phi = i*tb->delta; - tb->phi[i] = phi; - tb->e[i]= cyc_lin(tb->phifile,tb->efile,tb->ninput,MY_2PI,phi); - } - // In the linear case, if the user did not specify the forces, then we - // must generate the "f" array. Do this using linear interpolation - // of the e array (which itself was generated above) - for (int i = 0; i < tablength; i++) { - int im1 = i-1; if (im1 < 0) im1 += tablength; - int ip1 = i+1; if (ip1 >= tablength) ip1 -= tablength; - double dedx = (tb->e[ip1] - tb->e[im1]) / (2.0 * tb->delta); - // (This is the average of the linear slopes on either side of the node. - // Note that the nodes in the internal table are evenly spaced.) - tb->f[i] = -dedx; - } - } - - - // Fill the linear interpolation tables (de, df) - for (int i = 0; i < tablength; i++) { - int ip1 = i+1; if (ip1 >= tablength) ip1 -= tablength; - tb->de[i] = tb->e[ip1] - tb->e[i]; - tb->df[i] = tb->f[ip1] - tb->f[i]; - } - } // else if (tabstyle == LINEAR) - - - - cyc_spline(tb->phi, tb->e, tablength, MY_2PI, tb->e2, comm->me == 0); - if (! tb->f_unspecified) - cyc_spline(tb->phi, tb->f, tablength, MY_2PI, tb->f2, comm->me == 0); -} - - -/* ---------------------------------------------------------------------- - extract attributes from parameter line in table section - format of line: N value NOF DEGREES RADIANS - N is required, other params are optional -------------------------------------------------------------------------- */ - -void DihedralTableCut::param_extract(Table *tb, char *line) -{ - //tb->theta0 = 180.0; <- equilibrium angles not supported - tb->ninput = 0; - tb->f_unspecified = false; //default - tb->use_degrees = true; //default - - char *word = strtok(line," \t\n\r\f"); - while (word) { - if (strcmp(word,"N") == 0) { - word = strtok(nullptr," \t\n\r\f"); - tb->ninput = atoi(word); - } - else if (strcmp(word,"NOF") == 0) { - tb->f_unspecified = true; - } - else if ((strcmp(word,"DEGREES") == 0) || (strcmp(word,"degrees") == 0)) { - tb->use_degrees = true; - } - else if ((strcmp(word,"RADIANS") == 0) || (strcmp(word,"radians") == 0)) { - tb->use_degrees = false; - } - else if (strcmp(word,"CHECKU") == 0) { - word = strtok(nullptr," \t\n\r\f"); - memory->sfree(checkU_fname); - memory->create(checkU_fname,strlen(word)+1,"dihedral_table:checkU"); - strcpy(checkU_fname, word); - } - else if (strcmp(word,"CHECKF") == 0) { - word = strtok(nullptr," \t\n\r\f"); - memory->sfree(checkF_fname); - memory->create(checkF_fname,strlen(word)+1,"dihedral_table:checkF"); - strcpy(checkF_fname, word); - } - // COMMENTING OUT: equilibrium angles are not supported - //else if (strcmp(word,"EQ") == 0) { - // word = strtok(nullptr," \t\n\r\f"); - // tb->theta0 = atof(word); - //} - else { - string err_msg("Invalid keyword in dihedral angle table parameters"); - err_msg += string(" (") + string(word) + string(")"); - error->one(FLERR, err_msg); - } - word = strtok(nullptr," \t\n\r\f"); - } - - if (tb->ninput == 0) - error->one(FLERR,"Dihedral table parameters did not set N"); - -} // DihedralTable::param_extract() - - -/* ---------------------------------------------------------------------- - broadcast read-in table info from proc 0 to other procs - this function communicates these values in Table: - ninput,phifile,efile,ffile, - f_unspecified,use_degrees -------------------------------------------------------------------------- */ - -void DihedralTableCut::bcast_table(Table *tb) -{ - MPI_Bcast(&tb->ninput,1,MPI_INT,0,world); - - int me; - MPI_Comm_rank(world,&me); - if (me > 0) { - memory->create(tb->phifile,tb->ninput,"dihedral:phifile"); - memory->create(tb->efile,tb->ninput,"dihedral:efile"); - memory->create(tb->ffile,tb->ninput,"dihedral:ffile"); - } - - MPI_Bcast(tb->phifile,tb->ninput,MPI_DOUBLE,0,world); - MPI_Bcast(tb->efile,tb->ninput,MPI_DOUBLE,0,world); - MPI_Bcast(tb->ffile,tb->ninput,MPI_DOUBLE,0,world); - - MPI_Bcast(&tb->f_unspecified,1,MPI_INT,0,world); - MPI_Bcast(&tb->use_degrees,1,MPI_INT,0,world); - - // COMMENTING OUT: equilibrium angles are not supported - //MPI_Bcast(&tb->theta0,1,MPI_DOUBLE,0,world); -} - - diff --git a/src/USER-MISC/dihedral_table_cut.h b/src/USER-MISC/dihedral_table_cut.h index b07e925f08..b956069e14 100644 --- a/src/USER-MISC/dihedral_table_cut.h +++ b/src/USER-MISC/dihedral_table_cut.h @@ -20,131 +20,21 @@ DihedralStyle(table/cut,DihedralTableCut) #ifndef LMP_DIHEDRAL_TABLE_CUT_H #define LMP_DIHEDRAL_TABLE_CUT_H -#include "dihedral.h" +#include "dihedral_table.h" namespace LAMMPS_NS { -class DihedralTableCut : public Dihedral { +class DihedralTableCut : public DihedralTable { public: DihedralTableCut(class LAMMPS *); virtual ~DihedralTableCut(); virtual void compute(int, int); - void settings(int, char **); - void coeff(int, char **); - void write_restart(FILE *); - void read_restart(FILE *); - void write_restart_settings(FILE *); - void read_restart_settings(FILE *); + virtual void coeff(int, char **); protected: double *aat_k,*aat_theta0_1,*aat_theta0_2; - void allocate(); - - int tabstyle,tablength; - char *checkU_fname; - char *checkF_fname; - - struct Table { - int ninput; - int f_unspecified; // boolean (but MPI does not like type "bool") - int use_degrees; // boolean (but MPI does not like type "bool") - double *phifile,*efile,*ffile; - double *e2file,*f2file; - double delta,invdelta,deltasq6; - double *phi,*e,*de,*f,*df,*e2,*f2; - }; - - int ntables; - Table *tables; - int *tabindex; - - void null_table(Table *); - void free_table(Table *); - void read_table(Table *, char *, char *); - void bcast_table(Table *); - void spline_table(Table *); - void compute_table(Table *); - - void param_extract(Table *, char *); - - // -------------------------------------------- - // ------------ inline functions -------------- - // -------------------------------------------- - - // ----------------------------------------------------------- - // uf_lookup() - // quickly calculate the potential u and force f at angle x, - // using the internal tables tb->e and tb->f (evenly spaced) - // ----------------------------------------------------------- - enum{LINEAR,SPLINE}; - - inline void uf_lookup(int type, double x, double &u, double &f) - { - Table *tb = &tables[tabindex[type]]; - double x_over_delta = x*tb->invdelta; - int i = static_cast (x_over_delta); - double a; - double b = x_over_delta - i; - // Apply periodic boundary conditions to indices i and i+1 - if (i >= tablength) i -= tablength; - int ip1 = i+1; if (ip1 >= tablength) ip1 -= tablength; - - switch(tabstyle) { - case LINEAR: - u = tb->e[i] + b * tb->de[i]; - f = -(tb->f[i] + b * tb->df[i]); //<--works even if tb->f_unspecified==true - break; - case SPLINE: - a = 1.0 - b; - u = a * tb->e[i] + b * tb->e[ip1] + - ((a*a*a-a)*tb->e2[i] + (b*b*b-b)*tb->e2[ip1]) * - tb->deltasq6; - if (tb->f_unspecified) - //Formula below taken from equation3.3.5 of "numerical recipes in c" - //"f"=-derivative of e with respect to x (or "phi" in this case) - f = -((tb->e[i]-tb->e[ip1])*tb->invdelta + - ((3.0*a*a-1.0)*tb->e2[i]+(1.0-3.0*b*b)*tb->e2[ip1])*tb->delta/6.0); - else - f = -(a * tb->f[i] + b * tb->f[ip1] + - ((a*a*a-a)*tb->f2[i] + (b*b*b-b)*tb->f2[ip1]) * - tb->deltasq6); - break; - } // switch(tabstyle) - } // uf_lookup() - - - // ---------------------------------------------------------- - // u_lookup() - // quickly calculate the potential u at angle x using tb->e - //----------------------------------------------------------- - - inline void u_lookup(int type, double x, double &u) - { - Table *tb = &tables[tabindex[type]]; - int N = tablength; - - // i = static_cast ((x - tb->lo) * tb->invdelta); <-general version - double x_over_delta = x*tb->invdelta; - int i = static_cast (x_over_delta); - double b = x_over_delta - i; - - // Apply periodic boundary conditions to indices i and i+1 - if (i >= N) i -= N; - int ip1 = i+1; if (ip1 >= N) ip1 -= N; - - if (tabstyle == LINEAR) { - u = tb->e[i] + b * tb->de[i]; - } - else if (tabstyle == SPLINE) { - double a = 1.0 - b; - u = a * tb->e[i] + b * tb->e[ip1] + - ((a*a*a-a)*tb->e2[i] + (b*b*b-b)*tb->e2[ip1]) * - tb->deltasq6; - } - } // u_lookup() - - + virtual void allocate(); }; } From 1e3f1c584c569601efef6111babd3b3302dde656 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 29 Mar 2021 08:12:37 -0400 Subject: [PATCH 176/257] simplify by using utils::strdup() fmt::format() and reorder includes --- src/USER-MISC/fix_orient_eco.cpp | 4 +- src/USER-MISC/fix_pafi.cpp | 4 +- src/USER-MISC/fix_wall_region_ees.cpp | 5 +-- src/USER-MISC/temper_grem.cpp | 26 ++++++------ src/USER-MOLFILE/dump_molfile.cpp | 11 ++--- src/USER-PHONON/fix_phonon.cpp | 61 +++++++++++---------------- src/USER-PLUMED/fix_plumed.cpp | 27 +++++------- src/USER-PTM/compute_ptm_atom.cpp | 11 ++--- src/USER-QTB/fix_qbmsst.cpp | 20 ++++----- src/USER-QTB/fix_qtb.cpp | 24 +++++------ src/USER-QUIP/pair_quip.cpp | 37 +++++++--------- src/USER-REACTION/fix_bond_react.cpp | 48 +++++---------------- src/USER-REAXC/fix_qeq_reax.cpp | 28 ++++++------ src/USER-REAXC/fix_reaxc_species.cpp | 19 +++++---- src/USER-SCAFACOS/scafacos.cpp | 17 ++++---- src/USER-SMD/fix_smd_setvel.cpp | 16 ++----- src/USER-SMD/fix_smd_wall_surface.cpp | 38 +++-------------- src/USER-SMD/fix_smd_wall_surface.h | 1 - 18 files changed, 151 insertions(+), 246 deletions(-) diff --git a/src/USER-MISC/fix_orient_eco.cpp b/src/USER-MISC/fix_orient_eco.cpp index ce412e6fc9..3d6db4cd4f 100644 --- a/src/USER-MISC/fix_orient_eco.cpp +++ b/src/USER-MISC/fix_orient_eco.cpp @@ -87,9 +87,7 @@ FixOrientECO::FixOrientECO(LAMMPS *lmp, int narg, char **arg) : // read reference orientations from file // work on rank 0 only - int n = strlen(arg[6]) + 1; - dir_filename = new char[n]; - strcpy(dir_filename, arg[6]); + dir_filename = utils::strdup(arg[6]); if (me == 0) { char line[IMGMAX]; char *result; diff --git a/src/USER-MISC/fix_pafi.cpp b/src/USER-MISC/fix_pafi.cpp index ec0733657a..c2ad62d7d0 100644 --- a/src/USER-MISC/fix_pafi.cpp +++ b/src/USER-MISC/fix_pafi.cpp @@ -74,9 +74,7 @@ FixPAFI::FixPAFI(LAMMPS *lmp, int narg, char **arg) : com_flag = 1; time_integrate = 1; - int n = strlen(arg[3])+1; - computename = new char[n]; - strcpy(computename,&arg[3][0]); + computename = utils::strdup(&arg[3][0]); icompute = modify->find_compute(computename); if (icompute == -1) diff --git a/src/USER-MISC/fix_wall_region_ees.cpp b/src/USER-MISC/fix_wall_region_ees.cpp index 44067b0742..51e0af9dc4 100644 --- a/src/USER-MISC/fix_wall_region_ees.cpp +++ b/src/USER-MISC/fix_wall_region_ees.cpp @@ -52,10 +52,7 @@ FixWallRegionEES::FixWallRegionEES(LAMMPS *lmp, int narg, char **arg) : iregion = domain->find_region(arg[3]); if (iregion == -1) error->all(FLERR,"Region ID for fix wall/region/ees does not exist"); - int n = strlen(arg[3]) + 1; - idregion = new char[n]; - strcpy(idregion,arg[3]); - + idregion = utils::strdup(arg[3]); epsilon = utils::numeric(FLERR,arg[4],false,lmp); sigma = utils::numeric(FLERR,arg[5],false,lmp); cutoff = utils::numeric(FLERR,arg[6],false,lmp); diff --git a/src/USER-MISC/temper_grem.cpp b/src/USER-MISC/temper_grem.cpp index ee3c5ae5e4..3b987aaad2 100644 --- a/src/USER-MISC/temper_grem.cpp +++ b/src/USER-MISC/temper_grem.cpp @@ -16,21 +16,23 @@ ------------------------------------------------------------------------- */ #include "temper_grem.h" -#include -#include -#include "fix_grem.h" -#include "universe.h" + +#include "compute.h" #include "domain.h" -#include "update.h" +#include "error.h" +#include "finish.h" +#include "fix.h" +#include "fix_grem.h" +#include "force.h" #include "integrate.h" #include "modify.h" -#include "compute.h" -#include "force.h" -#include "fix.h" #include "random_park.h" -#include "finish.h" #include "timer.h" -#include "error.h" +#include "universe.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; @@ -90,9 +92,7 @@ void TemperGrem::command(int narg, char **arg) double pressref = 0; // Get and check for nh fix - int n = strlen(arg[4])+1; - id_nh = new char[n]; - strcpy(id_nh,arg[4]); + id_nh = utils::strdup(arg[4]); int ifix = modify->find_fix(id_nh); if (ifix < 0) error->all(FLERR,"Fix id for nvt or npt fix does not exist"); diff --git a/src/USER-MOLFILE/dump_molfile.cpp b/src/USER-MOLFILE/dump_molfile.cpp index 9de9a79e26..20790d4b32 100644 --- a/src/USER-MOLFILE/dump_molfile.cpp +++ b/src/USER-MOLFILE/dump_molfile.cpp @@ -17,15 +17,16 @@ #include "dump_molfile.h" -#include -#include -#include "domain.h" #include "atom.h" #include "comm.h" -#include "update.h" +#include "domain.h" +#include "error.h" #include "group.h" #include "memory.h" -#include "error.h" +#include "update.h" + +#include +#include #include "molfile_interface.h" diff --git a/src/USER-PHONON/fix_phonon.cpp b/src/USER-PHONON/fix_phonon.cpp index 30fb7baad5..222f3fa1d2 100644 --- a/src/USER-PHONON/fix_phonon.cpp +++ b/src/USER-PHONON/fix_phonon.cpp @@ -23,21 +23,22 @@ konglt@sjtu.edu.cn; konglt@gmail.com ------------------------------------------------------------------------- */ +#include "fix_phonon.h" + +#include "atom.h" +#include "citeme.h" +#include "compute.h" +#include "domain.h" +#include "error.h" +#include "fft3d_wrap.h" +#include "force.h" +#include "group.h" +#include "memory.h" +#include "modify.h" +#include "update.h" #include #include -#include "fix_phonon.h" -#include "fft3d_wrap.h" -#include "atom.h" -#include "compute.h" -#include "domain.h" -#include "force.h" -#include "group.h" -#include "modify.h" -#include "update.h" -#include "citeme.h" -#include "memory.h" -#include "error.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -77,15 +78,9 @@ FixPhonon::FixPhonon(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) waitsteps = utils::bnumeric(FLERR,arg[5],false,lmp); // Wait this many timesteps before actually measuring if (waitsteps < 0) error->all(FLERR,"Illegal fix phonon command: waitsteps < 0 !"); - int n = strlen(arg[6]) + 1; // map file - mapfile = new char[n]; - strcpy(mapfile, arg[6]); - - n = strlen(arg[7]) + 1; // prefix of output - prefix = new char[n]; - strcpy(prefix, arg[7]); - logfile = new char[n+4]; - sprintf(logfile,"%s.log",prefix); + mapfile = utils::strdup(arg[6]); + prefix = utils::strdup(arg[7]); + logfile = utils::strdup(std::string(prefix)+".log"); int sdim = sysdim = domain->dimension; int iarg = 8; @@ -184,11 +179,9 @@ FixPhonon::FixPhonon(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) // output some information on the system to log file if (me == 0) { flog = fopen(logfile, "w"); - if (flog == nullptr) { - char str[MAXLINE]; - sprintf(str,"Can not open output file %s",logfile); - error->one(FLERR,str); - } + if (flog == nullptr) + error->one(FLERR,fmt::format("Can not open output file {}: {}", + logfile,utils::getsyserror())); fprintf(flog,"############################################################\n"); fprintf(flog,"# group name of the atoms under study : %s\n", group->names[igroup]); fprintf(flog,"# total number of atoms in the group : %d\n", ngroup); @@ -440,9 +433,7 @@ int FixPhonon::modify_param(int narg, char **arg) if (strcmp(arg[0],"temp") == 0) { if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) error->all(FLERR,"Could not find fix_modify temp ID"); @@ -563,10 +554,9 @@ void FixPhonon::readmap() // read from map file for others char line[MAXLINE]; FILE *fp = fopen(mapfile, "r"); - if (fp == nullptr) { - sprintf(line,"Cannot open input map file %s", mapfile); - error->all(FLERR,line); - } + if (fp == nullptr) + error->all(FLERR,fmt::format("Cannot open input map file {}: {}", + mapfile, utils::getsyserror())); if (fgets(line,MAXLINE,fp) == nullptr) error->all(FLERR,"Error while reading header of mapping file!"); @@ -712,9 +702,8 @@ void FixPhonon::postprocess( ) // write binary file, in fact, it is the force constants matrix that is written // Enforcement of ASR and the conversion of dynamical matrix is done in the postprocessing code - char fname[MAXLINE]; - sprintf(fname,"%s.bin." BIGINT_FORMAT,prefix,update->ntimestep); - FILE *fp_bin = fopen(fname,"wb"); + auto fname = fmt::format("{}.bin.{}",prefix,update->ntimestep); + FILE *fp_bin = fopen(fname.c_str(),"wb"); fwrite(&sysdim, sizeof(int), 1, fp_bin); fwrite(&nx, sizeof(int), 1, fp_bin); diff --git a/src/USER-PLUMED/fix_plumed.cpp b/src/USER-PLUMED/fix_plumed.cpp index 1217237e19..8d3cdd5c34 100644 --- a/src/USER-PLUMED/fix_plumed.cpp +++ b/src/USER-PLUMED/fix_plumed.cpp @@ -16,25 +16,24 @@ Pablo Piaggi (EPFL) ------------------------------------------------------------------------- */ -#include - -#include +#include "fix_plumed.h" #include "atom.h" #include "comm.h" -#include "update.h" -#include "force.h" -#include "respa.h" +#include "compute.h" #include "domain.h" #include "error.h" +#include "force.h" #include "group.h" -#include "fix_plumed.h" -#include "universe.h" -#include "compute.h" #include "modify.h" #include "pair.h" - +#include "respa.h" #include "timer.h" +#include "universe.h" +#include "update.h" + +#include +#include #include "plumed/wrapper/Plumed.h" @@ -542,9 +541,7 @@ int FixPlumed::modify_param(int narg, char **arg) if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); modify->delete_compute(id_pe); delete[] id_pe; - int n = strlen(arg[1]) + 1; - id_pe = new char[n]; - strcpy(id_pe,arg[1]); + id_pe = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify potential energy ID"); @@ -561,9 +558,7 @@ int FixPlumed::modify_param(int narg, char **arg) if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); modify->delete_compute(id_press); delete[] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(arg[1]); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/USER-PTM/compute_ptm_atom.cpp b/src/USER-PTM/compute_ptm_atom.cpp index 376253dd84..0622b9dcc0 100644 --- a/src/USER-PTM/compute_ptm_atom.cpp +++ b/src/USER-PTM/compute_ptm_atom.cpp @@ -17,23 +17,24 @@ under ------------------------------------------------------------------------- */ #include "compute_ptm_atom.h" -#include -#include -#include -#include #include "atom.h" #include "citeme.h" #include "comm.h" #include "error.h" #include "force.h" +#include "group.h" #include "memory.h" #include "modify.h" #include "neigh_list.h" #include "neigh_request.h" #include "neighbor.h" #include "update.h" -#include "group.h" + +#include +#include +#include +#include #include "ptm_functions.h" diff --git a/src/USER-QTB/fix_qbmsst.cpp b/src/USER-QTB/fix_qbmsst.cpp index 0b54811db0..a9dfb83f06 100644 --- a/src/USER-QTB/fix_qbmsst.cpp +++ b/src/USER-QTB/fix_qbmsst.cpp @@ -19,17 +19,17 @@ #include "fix_qbmsst.h" #include "atom.h" -#include "force.h" -#include "update.h" -#include "modify.h" +#include "comm.h" #include "compute.h" #include "domain.h" -#include "comm.h" -#include "random_mars.h" -#include "memory.h" #include "error.h" +#include "force.h" #include "kspace.h" #include "math_const.h" +#include "memory.h" +#include "modify.h" +#include "random_mars.h" +#include "update.h" #include #include @@ -869,9 +869,7 @@ int FixQBMSST::modify_param(int narg, char **arg) tflag = 0; } delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) error->all(FLERR,"Could not find fix_modify temperature ID"); @@ -891,9 +889,7 @@ int FixQBMSST::modify_param(int narg, char **arg) pflag = 0; } delete [] id_press; - int n = strlen(arg[1]) + 1; - id_press = new char[n]; - strcpy(id_press,arg[1]); + id_press = utils::strdup(arg[1]); int icompute = modify->find_compute(id_press); if (icompute < 0) error->all(FLERR,"Could not find fix_modify pressure ID"); diff --git a/src/USER-QTB/fix_qtb.cpp b/src/USER-QTB/fix_qtb.cpp index 4c79fbeaae..e4e645a1bb 100644 --- a/src/USER-QTB/fix_qtb.cpp +++ b/src/USER-QTB/fix_qtb.cpp @@ -18,20 +18,20 @@ #include "fix_qtb.h" -#include -#include - #include "atom.h" -#include "force.h" -#include "update.h" -#include "modify.h" -#include "compute.h" -#include "respa.h" #include "comm.h" -#include "random_mars.h" +#include "compute.h" +#include "error.h" +#include "force.h" #include "math_const.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "random_mars.h" +#include "respa.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; @@ -345,9 +345,7 @@ int FixQTB::modify_param(int narg, char **arg) if (strcmp(arg[0],"temp") == 0) { if (narg < 2) error->all(FLERR,"Illegal fix_modify command"); delete [] id_temp; - int n = strlen(arg[1]) + 1; - id_temp = new char[n]; - strcpy(id_temp,arg[1]); + id_temp = utils::strdup(arg[1]); int icompute = modify->find_compute(id_temp); if (icompute < 0) error->all(FLERR,"Could not find fix_modify temperature ID"); diff --git a/src/USER-QUIP/pair_quip.cpp b/src/USER-QUIP/pair_quip.cpp index f850925764..2d338da158 100644 --- a/src/USER-QUIP/pair_quip.cpp +++ b/src/USER-QUIP/pair_quip.cpp @@ -16,21 +16,21 @@ Aidan Thompson (Sandia, athomps@sandia.gov) ------------------------------------------------------------------------- */ -#include -#include - -#include #include "pair_quip.h" + #include "atom.h" -#include "update.h" -#include "force.h" #include "comm.h" -#include "neighbor.h" +#include "domain.h" +#include "error.h" +#include "force.h" +#include "memory.h" #include "neigh_list.h" #include "neigh_request.h" -#include "memory.h" -#include "error.h" -#include "domain.h" +#include "neighbor.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; @@ -252,24 +252,17 @@ void PairQUIP::coeff(int narg, char **arg) if (!allocated) allocate(); int n = atom->ntypes; - if (narg != (4+n)) { - char str[1024]; - sprintf(str,"Number of arguments %d is not correct, it should be %d", narg, 4+n); - error->all(FLERR,str); - } + if (narg != (4+n)) + error->all(FLERR,fmt::format("Number of arguments {} is not correct, " + "it should be {}", narg, 4+n)); // ensure I,J args are * * if (strcmp(arg[0],"*") != 0 || strcmp(arg[1],"*") != 0) error->all(FLERR,"Incorrect args for pair coefficients"); - n_quip_file = strlen(arg[2]); - quip_file = new char[n_quip_file+1]; - strcpy(quip_file,arg[2]); - - n_quip_string = strlen(arg[3]); - quip_string = new char[n_quip_string+1]; - strcpy(quip_string,arg[3]); + quip_file = utils::strdup(arg[2]); + quip_string = utils::strdup(arg[3]); for (int i = 4; i < narg; i++) { if (strcmp(arg[i],"NULL") == 0) diff --git a/src/USER-REACTION/fix_bond_react.cpp b/src/USER-REACTION/fix_bond_react.cpp index 91354506d1..201949a874 100644 --- a/src/USER-REACTION/fix_bond_react.cpp +++ b/src/USER-REACTION/fix_bond_react.cpp @@ -169,9 +169,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[iarg+1],"yes") == 0) { if (iarg+4 > narg) error->all(FLERR,"Illegal fix bond/react command:" "'stabilization' keyword has too few arguments"); - int n = strlen(arg[iarg+2]) + 1; - exclude_group = new char[n]; - strcpy(exclude_group,arg[iarg+2]); + exclude_group = utils::strdup(arg[iarg+2]); stabilization_flag = 1; nve_limit_xmax = arg[iarg+3]; iarg += 4; @@ -273,9 +271,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : groupbits[rxn] = group->bitmask[groupid]; if (strncmp(arg[iarg],"v_",2) == 0) { - n = strlen(&arg[iarg][2]) + 1; - char *str = new char[n]; - strcpy(str,&arg[iarg][2]); + char *str = utils::strdup(&arg[iarg][2]); var_id[NEVERY][rxn] = input->variable->find(str); if (var_id[NEVERY][rxn] < 0) error->all(FLERR,"Bond/react: Variable name does not exist"); @@ -291,9 +287,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : iarg++; if (strncmp(arg[iarg],"v_",2) == 0) { - n = strlen(&arg[iarg][2]) + 1; - char *str = new char[n]; - strcpy(str,&arg[iarg][2]); + char *str = utils::strdup(&arg[iarg][2]); var_id[RMIN][rxn] = input->variable->find(str); if (var_id[RMIN][rxn] < 0) error->all(FLERR,"Bond/react: Variable name does not exist"); @@ -312,9 +306,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : iarg++; if (strncmp(arg[iarg],"v_",2) == 0) { - n = strlen(&arg[iarg][2]) + 1; - char *str = new char[n]; - strcpy(str,&arg[iarg][2]); + char *str = utils::strdup(&arg[iarg][2]); var_id[RMAX][rxn] = input->variable->find(str); if (var_id[RMAX][rxn] < 0) error->all(FLERR,"Bond/react: Variable name does not exist"); @@ -340,8 +332,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : "fix bond/react does not exist"); //read superimpose file - files[rxn] = new char[strlen(arg[iarg])+1]; - strcpy(files[rxn],arg[iarg]); + files[rxn] = utils::strdup(arg[iarg]); iarg++; while (iarg < narg && strcmp(arg[iarg],"react") != 0) { @@ -350,9 +341,7 @@ FixBondReact::FixBondReact(LAMMPS *lmp, int narg, char **arg) : "'prob' keyword has too few arguments"); // check if probability is a variable if (strncmp(arg[iarg+1],"v_",2) == 0) { - int n = strlen(&arg[iarg+1][2]) + 1; - char *str = new char[n]; - strcpy(str,&arg[iarg+1][2]); + char *str = utils::strdup(&arg[iarg+1][2]); var_id[PROB][rxn] = input->variable->find(str); if (var_id[PROB][rxn] < 0) error->all(FLERR,"Bond/react: Variable name does not exist"); @@ -727,21 +716,14 @@ void FixBondReact::post_constructor() fix3 = modify->fix[modify->nfix-1]; } - len = strlen("statted_tags") + 1; - statted_id = new char[len]; - strcpy(statted_id,"statted_tags"); + statted_id = utils::strdup("statted_tags"); // if static group exists, use as parent group // also, rename dynamic exclude_group by appending '_REACT' char *exclude_PARENT_group; - int n = strlen(exclude_group) + 1; - exclude_PARENT_group = new char[n]; - strcpy(exclude_PARENT_group,exclude_group); - n += strlen("_REACT"); + exclude_PARENT_group = utils::strdup(exclude_group); delete [] exclude_group; - exclude_group = new char[n]; - strcpy(exclude_group,exclude_PARENT_group); - strcat(exclude_group,"_REACT"); + exclude_group = utils::strdup(std::string(exclude_PARENT_group)+"_REACT"); group->find_or_create(exclude_group); if (groupid == -1) @@ -766,13 +748,8 @@ void FixBondReact::post_constructor() // sleeping code, for future capabilities custom_exclude_flag = 1; // first we have to find correct fix group reference - int n = strlen("GROUP_") + strlen(exclude_group) + 1; - char *fix_group = new char[n]; - strcpy(fix_group,"GROUP_"); - strcat(fix_group,exclude_group); - int ifix = modify->find_fix(fix_group); + int ifix = modify->find_fix(std::string("GROUP_")+exclude_group); Fix *fix = modify->fix[ifix]; - delete [] fix_group; // this returns names of corresponding property int unused; @@ -780,10 +757,7 @@ void FixBondReact::post_constructor() idprop = (char *) fix->extract("property",unused); if (idprop == nullptr) error->all(FLERR,"Exclude group must be a per-atom property group"); - - len = strlen(idprop) + 1; - statted_id = new char[len]; - strcpy(statted_id,idprop); + statted_id = utils::strdup(idprop); // initialize per-atom statted_tags to 1 // need to correct for smooth restarts diff --git a/src/USER-REAXC/fix_qeq_reax.cpp b/src/USER-REAXC/fix_qeq_reax.cpp index 355cbbb770..44088043f0 100644 --- a/src/USER-REAXC/fix_qeq_reax.cpp +++ b/src/USER-REAXC/fix_qeq_reax.cpp @@ -20,22 +20,24 @@ #include "fix_qeq_reax.h" -#include -#include -#include "pair_reaxc.h" #include "atom.h" +#include "citeme.h" #include "comm.h" -#include "neighbor.h" -#include "neigh_list.h" -#include "neigh_request.h" -#include "update.h" +#include "error.h" #include "force.h" #include "group.h" -#include "pair.h" -#include "respa.h" #include "memory.h" -#include "citeme.h" -#include "error.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "pair.h" +#include "pair_reaxc.h" +#include "respa.h" +#include "update.h" + +#include +#include + #include "reaxc_defs.h" #include "reaxc_types.h" @@ -70,9 +72,7 @@ FixQEqReax::FixQEqReax(LAMMPS *lmp, int narg, char **arg) : swa = utils::numeric(FLERR,arg[4],false,lmp); swb = utils::numeric(FLERR,arg[5],false,lmp); tolerance = utils::numeric(FLERR,arg[6],false,lmp); - int len = strlen(arg[7]) + 1; - pertype_option = new char[len]; - strcpy(pertype_option,arg[7]); + pertype_option = utils::strdup(arg[7]); // dual CG support only available for USER-OMP variant // check for compatibility is in Fix::post_constructor() diff --git a/src/USER-REAXC/fix_reaxc_species.cpp b/src/USER-REAXC/fix_reaxc_species.cpp index e90cde2529..81b1dafa61 100644 --- a/src/USER-REAXC/fix_reaxc_species.cpp +++ b/src/USER-REAXC/fix_reaxc_species.cpp @@ -18,20 +18,21 @@ #include "fix_reaxc_species.h" - -#include -#include "fix_ave_atom.h" #include "atom.h" -#include "domain.h" -#include "update.h" -#include "modify.h" -#include "neighbor.h" -#include "neigh_list.h" #include "comm.h" +#include "domain.h" +#include "error.h" +#include "fix_ave_atom.h" #include "force.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "neigh_list.h" +#include "neighbor.h" #include "pair_reaxc.h" +#include "update.h" + +#include + #include "reaxc_defs.h" using namespace LAMMPS_NS; diff --git a/src/USER-SCAFACOS/scafacos.cpp b/src/USER-SCAFACOS/scafacos.cpp index 0ce027ec1e..fa12cffe4c 100644 --- a/src/USER-SCAFACOS/scafacos.cpp +++ b/src/USER-SCAFACOS/scafacos.cpp @@ -15,21 +15,22 @@ Contributing author: Rene Halver (JSC) ------------------------------------------------------------------------- */ -#include -#include -#include #include "scafacos.h" + #include "atom.h" #include "comm.h" #include "domain.h" +#include "error.h" #include "force.h" #include "memory.h" -#include "error.h" + +#include +#include +#include +#include // ScaFaCoS library -#include -#include #include "fcs.h" using namespace LAMMPS_NS; @@ -54,9 +55,7 @@ void Scafacos::settings(int narg, char **arg) { if (narg != 2) error->all(FLERR,"Illegal scafacos command"); - int n = strlen(arg[0]) + 1; - method = new char[n]; - strcpy(method,arg[0]); + method = utils::strdup(arg[0]); tolerance = utils::numeric(FLERR,arg[1],false,lmp); // optional ScaFaCoS library setting defaults diff --git a/src/USER-SMD/fix_smd_setvel.cpp b/src/USER-SMD/fix_smd_setvel.cpp index f4c23e9f7a..471159ea53 100644 --- a/src/USER-SMD/fix_smd_setvel.cpp +++ b/src/USER-SMD/fix_smd_setvel.cpp @@ -60,9 +60,7 @@ FixSMDSetVel::FixSMDSetVel(LAMMPS *lmp, int narg, char **arg) : xstr = ystr = zstr = nullptr; if (strstr(arg[3], "v_") == arg[3]) { - int n = strlen(&arg[3][2]) + 1; - xstr = new char[n]; - strcpy(xstr, &arg[3][2]); + xstr = utils::strdup( &arg[3][2]); } else if (strcmp(arg[3], "NULL") == 0) { xstyle = NONE; } else { @@ -70,9 +68,7 @@ FixSMDSetVel::FixSMDSetVel(LAMMPS *lmp, int narg, char **arg) : xstyle = CONSTANT; } if (strstr(arg[4], "v_") == arg[4]) { - int n = strlen(&arg[4][2]) + 1; - ystr = new char[n]; - strcpy(ystr, &arg[4][2]); + ystr = utils::strdup( &arg[4][2]); } else if (strcmp(arg[4], "NULL") == 0) { ystyle = NONE; } else { @@ -80,9 +76,7 @@ FixSMDSetVel::FixSMDSetVel(LAMMPS *lmp, int narg, char **arg) : ystyle = CONSTANT; } if (strstr(arg[5], "v_") == arg[5]) { - int n = strlen(&arg[5][2]) + 1; - zstr = new char[n]; - strcpy(zstr, &arg[5][2]); + zstr = utils::strdup( &arg[5][2]); } else if (strcmp(arg[5], "NULL") == 0) { zstyle = NONE; } else { @@ -103,9 +97,7 @@ FixSMDSetVel::FixSMDSetVel(LAMMPS *lmp, int narg, char **arg) : iregion = domain->find_region(arg[iarg + 1]); if (iregion == -1) error->all(FLERR, "Region ID for fix setvelocity does not exist"); - int n = strlen(arg[iarg + 1]) + 1; - idregion = new char[n]; - strcpy(idregion, arg[iarg + 1]); + idregion = utils::strdup( arg[iarg + 1]); iarg += 2; } else error->all(FLERR, "Illegal fix setvelocity command"); diff --git a/src/USER-SMD/fix_smd_wall_surface.cpp b/src/USER-SMD/fix_smd_wall_surface.cpp index f37c9ec873..e9d32b5684 100644 --- a/src/USER-SMD/fix_smd_wall_surface.cpp +++ b/src/USER-SMD/fix_smd_wall_surface.cpp @@ -184,32 +184,6 @@ void FixSMDWallSurface::setup(int /*vflag*/) { read_triangles(0); } -/* ---------------------------------------------------------------------- - function to determine number of values in a text line - ------------------------------------------------------------------------- */ - -int FixSMDWallSurface::count_words(const char *line) { - int n = strlen(line) + 1; - char *copy; - memory->create(copy, n, "atom:copy"); - strcpy(copy, line); - - char *ptr; - if ((ptr = strchr(copy, '#'))) - *ptr = '\0'; - - if (strtok(copy, " \t\n\r\f") == nullptr) { - memory->destroy(copy); - return 0; - } - n = 1; - while (strtok(nullptr, " \t\n\r\f")) - n++; - - memory->destroy(copy); - return n; -} - /* ---------------------------------------------------------------------- size of atom nlocal's restart data ------------------------------------------------------------------------- */ @@ -265,7 +239,7 @@ void FixSMDWallSurface::read_triangles(int pass) { error->one(FLERR,"error reading number of triangle pairs"); } - nwords = count_words(line); + nwords = utils::count_words(line); if (nwords < 1) { error->one(FLERR,"first line of file is incorrect"); } @@ -290,7 +264,7 @@ void FixSMDWallSurface::read_triangles(int pass) { while (fgets(line, sizeof(line), fp)) { // read a line, should be the facet line // evaluate facet line - nwords = count_words(line); + nwords = utils::count_words(line); if (nwords != 5) { //sprintf(str, "found end solid line"); //error->message(FLERR, str); @@ -322,7 +296,7 @@ void FixSMDWallSurface::read_triangles(int pass) { error->one(FLERR, "error reading outer loop"); } - nwords = count_words(line); + nwords = utils::count_words(line); if (nwords != 2) { error->one(FLERR,"error reading outer loop"); } @@ -335,7 +309,7 @@ void FixSMDWallSurface::read_triangles(int pass) { error->one(FLERR,"error reading vertex line"); } - nwords = count_words(line); + nwords = utils::count_words(line); if (nwords != 4) { error->one(FLERR,"error reading vertex line"); } @@ -366,7 +340,7 @@ void FixSMDWallSurface::read_triangles(int pass) { error->one(FLERR, "error reading endloop"); } - nwords = count_words(line); + nwords = utils::count_words(line); if (nwords != 1) { error->one(FLERR,"error reading endloop"); } @@ -377,7 +351,7 @@ void FixSMDWallSurface::read_triangles(int pass) { error->one(FLERR,"error reading endfacet"); } - nwords = count_words(line); + nwords = utils::count_words(line); if (nwords != 1) { error->one(FLERR,"error reading endfacet"); } diff --git a/src/USER-SMD/fix_smd_wall_surface.h b/src/USER-SMD/fix_smd_wall_surface.h index 10f80c4ca8..3ff2b49737 100644 --- a/src/USER-SMD/fix_smd_wall_surface.h +++ b/src/USER-SMD/fix_smd_wall_surface.h @@ -34,7 +34,6 @@ public: void setup(int); void min_setup(int); - int count_words(const char *line); void read_triangles(int pass); private: From 9058216a5421b2a292711ce06e48360ef23832ed Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 29 Mar 2021 14:11:56 -0400 Subject: [PATCH 177/257] silence compiler warnings --- src/USER-COLVARS/ndx_group.cpp | 4 +--- src/USER-DPD/pair_exp6_rx.cpp | 1 - src/USER-MISC/dihedral_table_cut.cpp | 5 ----- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/USER-COLVARS/ndx_group.cpp b/src/USER-COLVARS/ndx_group.cpp index 184faa62cc..d8d5632b06 100644 --- a/src/USER-COLVARS/ndx_group.cpp +++ b/src/USER-COLVARS/ndx_group.cpp @@ -78,7 +78,6 @@ void Ndx2Group::command(int narg, char **arg) int len; bigint num; FILE *fp; - tagint *tagbuf; std::string name = "", next; if (narg < 1) error->all(FLERR,"Illegal ndx2group command"); @@ -191,11 +190,10 @@ void Ndx2Group::create(const std::string &name, const std::vector &tags) // map from global to local const int nlocal = atom->nlocal; int *flags = (int *)calloc(nlocal,sizeof(int)); - for (bigint i=0; i < tags.size(); ++i) { + for (bigint i=0; i < (int)tags.size(); ++i) { const int id = atom->map(tags[i]); if (id < nlocal && id >= 0) flags[id] = 1; } group->create(name,flags); free(flags); } - diff --git a/src/USER-DPD/pair_exp6_rx.cpp b/src/USER-DPD/pair_exp6_rx.cpp index ba8d52776f..396047fca9 100644 --- a/src/USER-DPD/pair_exp6_rx.cpp +++ b/src/USER-DPD/pair_exp6_rx.cpp @@ -587,7 +587,6 @@ void PairExp6rx::coeff(int narg, char **arg) if (!allocated) allocate(); int ilo,ihi,jlo,jhi; - int n; utils::bounds(FLERR,arg[0],1,atom->ntypes,ilo,ihi,error); utils::bounds(FLERR,arg[1],1,atom->ntypes,jlo,jhi,error); diff --git a/src/USER-MISC/dihedral_table_cut.cpp b/src/USER-MISC/dihedral_table_cut.cpp index dc7a6f9685..02e6d3e5da 100644 --- a/src/USER-MISC/dihedral_table_cut.cpp +++ b/src/USER-MISC/dihedral_table_cut.cpp @@ -134,11 +134,6 @@ static double cyc_splintD(double const *xa, } // cyc_splintD() -// -------------------------------------------- -// ------- Calculate the dihedral angle ------- -// -------------------------------------------- -static const int g_dim=3; - /* ---------------------------------------------------------------------- */ DihedralTableCut::DihedralTableCut(LAMMPS *lmp) : DihedralTable(lmp) From aaf9aa6d69b1ba06ff9df5a40c2384f79b8c32a5 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 29 Mar 2021 14:27:42 -0400 Subject: [PATCH 178/257] Refactoring of more tests --- unittest/commands/test_kim_commands.cpp | 183 +++++------ unittest/commands/test_lattice_region.cpp | 170 ++++------ unittest/commands/test_reset_ids.cpp | 149 ++++----- unittest/commands/test_variables.cpp | 153 ++++----- unittest/formats/compressed_dump_test.h | 16 +- unittest/formats/test_atom_styles.cpp | 299 +++++++++--------- unittest/formats/test_dump_atom.cpp | 36 +-- .../formats/test_dump_atom_compressed.cpp | 8 +- unittest/formats/test_dump_cfg.cpp | 8 +- unittest/formats/test_dump_cfg_compressed.cpp | 8 +- unittest/formats/test_dump_custom.cpp | 32 +- .../formats/test_dump_local_compressed.cpp | 12 +- unittest/formats/test_dump_xyz_compressed.cpp | 8 +- .../test_eim_potential_file_reader.cpp | 44 ++- unittest/formats/test_file_operations.cpp | 43 +-- unittest/formats/test_image_flags.cpp | 51 ++- unittest/formats/test_molecule_file.cpp | 47 +-- unittest/formats/test_pair_unit_convert.cpp | 186 ++++++----- unittest/testing/core.h | 21 +- 19 files changed, 627 insertions(+), 847 deletions(-) diff --git a/unittest/commands/test_kim_commands.cpp b/unittest/commands/test_kim_commands.cpp index 2d044b86eb..83e1e5b2d2 100644 --- a/unittest/commands/test_kim_commands.cpp +++ b/unittest/commands/test_kim_commands.cpp @@ -22,6 +22,7 @@ #include "variable.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -29,57 +30,23 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { using ::testing::MatchesRegex; using ::testing::StrEq; -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } -class KimCommandsTest : public ::testing::Test { +class KimCommandsTest : public LAMMPSTest { protected: - LAMMPS *lmp; Variable *variable; void SetUp() override { - const char *args[] = {"KimCommandsTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "KimCommandsTest"; + LAMMPSTest::SetUp(); variable = lmp->input->variable; } - - void TearDown() override - { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(KimCommandsTest, kim) @@ -115,9 +82,9 @@ TEST_F(KimCommandsTest, kim_init) // TEST_FAILURE(".*ERROR: KIM Model does not support the requested unit system.*", // command("kim init ex_model_Ar_P_Morse real");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim init LennardJones_Ar real"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); int ifix = lmp->modify->find_fix("KIM_MODEL_STORE"); ASSERT_GE(ifix, 0); @@ -129,81 +96,81 @@ TEST_F(KimCommandsTest, kim_interactions) TEST_FAILURE(".*ERROR: Illegal 'kim interactions' command.*", command("kim interactions");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim init LennardJones_Ar real"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Must use 'kim interactions' command " "after simulation box is defined.*", command("kim interactions Ar");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim init LennardJones_Ar real"); command("lattice fcc 4.4300"); command("region box block 0 10 0 10 0 10"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal 'kim interactions' command.*", command("kim interactions Ar Ar");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("lattice fcc 4.4300"); command("region box block 0 20 0 20 0 20"); command("create_box 4 box"); command("create_atoms 4 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal 'kim interactions' command.*", command("kim interactions Ar Ar");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("lattice fcc 4.4300"); command("region box block 0 10 0 10 0 10"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Must use 'kim init' before 'kim interactions'.*", command("kim interactions Ar");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init LennardJones_Ar real"); command("lattice fcc 4.4300"); command("region box block 0 10 0 10 0 10"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: fixed_types cannot be used with a KIM Portable Model.*", command("kim interactions fixed_types");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("pair_style kim LennardJones_Ar"); command("region box block 0 1 0 1 0 1"); command("create_box 4 box"); command("pair_coeff * * Ar Ar Ar Ar"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal"); command("lattice fcc 4.920"); command("region box block 0 10 0 10 0 10"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Species 'Ar' is not supported by this KIM Simulator Model.*", command("kim interactions Ar");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal"); command("lattice fcc 4.08"); @@ -211,13 +178,13 @@ TEST_F(KimCommandsTest, kim_interactions) command("create_box 1 box"); command("create_atoms 1 box"); command("kim interactions Au"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // ASSERT_EQ(lmp->output->var_kim_periodic, 1); // TEST_FAILURE(".*ERROR: Incompatible units for KIM Simulator Model.*", // command("kim interactions Au");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init LennardJones_Ar real"); command("lattice fcc 4.4300"); @@ -226,12 +193,12 @@ TEST_F(KimCommandsTest, kim_interactions) command("create_atoms 1 box"); command("kim interactions Ar"); command("mass 1 39.95"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); int ifix = lmp->modify->find_fix("KIM_MODEL_STORE"); ASSERT_GE(ifix, 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init LennardJones_Ar real"); command("lattice fcc 4.4300"); @@ -243,7 +210,7 @@ TEST_F(KimCommandsTest, kim_interactions) command("run 1"); command("kim interactions Ar"); command("run 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } TEST_F(KimCommandsTest, kim_param) @@ -255,18 +222,18 @@ TEST_F(KimCommandsTest, kim_param) "'kim param get/set' is mandatory.*", command("kim param unknown shift 1 shift");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu metal"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: 'kim param' can only be used with a KIM Portable Model.*", command("kim param get shift 1 shift");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal 'kim param get' command.\nTo get the new " "parameter values, pair style must be assigned.\nMust use 'kim" @@ -278,7 +245,7 @@ TEST_F(KimCommandsTest, kim_param) " interactions' or 'pair_style kim' before 'kim param set'.*", command("kim param set shift 1 2");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real"); command("lattice fcc 4.4300"); @@ -287,7 +254,7 @@ TEST_F(KimCommandsTest, kim_param) command("create_atoms 1 box"); command("kim interactions Ar"); command("mass 1 39.95"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal index '0' for " "'shift' parameter with the extent of '1'.*", @@ -312,9 +279,9 @@ TEST_F(KimCommandsTest, kim_param) "Model does not have the requested 'unknown' parameter.*", command("kim param get unknown 1 unknown");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param get shift 1 shift"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_FALSE(variable->find("shift") == -1); ASSERT_THAT(variable->retrieve("shift"), StrEq("1")); @@ -334,11 +301,11 @@ TEST_F(KimCommandsTest, kim_param) "Model does not have the requested '0.4989030' parameter.*", command("kim param set sigmas 1:1 0.5523570 0.4989030");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable new_shift equal 2"); command("kim param set shift 1 ${new_shift}"); command("kim param get shift 1 shift"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("shift"), StrEq("2")); @@ -363,51 +330,51 @@ TEST_F(KimCommandsTest, kim_param) "split' is mandatory.*", command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 cutoffs_3"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("cutoffs_1"), StrEq("2.20943")); ASSERT_THAT(variable->retrieve("cutoffs_2"), StrEq("2.10252")); ASSERT_THAT(variable->retrieve("cutoffs_3"), StrEq("5.666115")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param get cutoffs 1:3 cutoffs_1 cutoffs_2 cutoffs_3 explicit"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("cutoffs_1"), StrEq("2.20943")); ASSERT_THAT(variable->retrieve("cutoffs_2"), StrEq("2.10252")); ASSERT_THAT(variable->retrieve("cutoffs_3"), StrEq("5.666115")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param get cutoffs 1:3 cutoffs split"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("cutoffs_1"), StrEq("2.20943")); ASSERT_THAT(variable->retrieve("cutoffs_2"), StrEq("2.10252")); ASSERT_THAT(variable->retrieve("cutoffs_3"), StrEq("5.666115")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param get cutoffs 1:3 cutoffs list"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("cutoffs"), StrEq("2.20943 2.10252 5.666115")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param set cutoffs 1 2.21 cutoffs 2 2.11"); command("kim param get cutoffs 1:2 cutoffs list"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("cutoffs"), StrEq("2.21 2.11")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param set cutoffs 1:3 2.3 2.2 5.7"); command("kim param get cutoffs 1:3 cutoffs list"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("cutoffs"), StrEq("2.3 2.2 5.7")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("lattice fcc 4.4300"); @@ -417,19 +384,19 @@ TEST_F(KimCommandsTest, kim_param) command("mass 1 39.95"); command("pair_style kim LennardJones612_UniversalShifted__MO_959249795837_003"); command("pair_coeff * * Ar"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("kim param get shift 1 shift"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("shift"), StrEq("1")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable new_shift equal 2"); command("kim param set shift 1 ${new_shift}"); command("kim param get shift 1 shift"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("shift"), StrEq("2")); } @@ -467,13 +434,13 @@ TEST_F(KimCommandsTest, kim_property) command("kim property remove 1 key short-name");); TEST_FAILURE(".*ERROR: There is no property instance to dump the content.*", command("kim property dump results.edn");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init LennardJones612_UniversalShifted__MO_959249795837_003 real"); command("kim property create 1 cohesive-potential-energy-cubic-crystal"); command("kim property modify 1 key short-name source-value 1 fcc"); command("kim property destroy 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); #endif } @@ -608,16 +575,16 @@ TEST_F(KimCommandsTest, kim_query) command(squery);); #if defined(KIM_EXTRA_UNITTESTS) - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim query latconst_1 get_lattice_constant_cubic " "crystal=[fcc] species=[Al] units=[angstrom] " "model=[EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("4.032082033157349")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal"); command("kim query latconst_1 get_lattice_constant_cubic crystal=[fcc] species=[Al] " @@ -626,71 +593,71 @@ TEST_F(KimCommandsTest, kim_query) command("kim query latconst_2 get_lattice_constant_cubic crystal=[fcc] species=[Al] " "units=[angstrom] " "model=[LennardJones612_UniversalShifted__MO_959249795837_003]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("4.032082033157349")); ASSERT_THAT(variable->retrieve("latconst_2"), StrEq("3.328125931322575")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000 metal"); command("kim query latconst split get_lattice_constant_hexagonal crystal=[hcp] species=[Zr] " "units=[angstrom]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("3.234055244384789")); ASSERT_THAT(variable->retrieve("latconst_2"), StrEq("5.167650199630013")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim query latconst index get_lattice_constant_hexagonal " "crystal=[hcp] species=[Zr] units=[angstrom] " "model=[EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("latconst"), StrEq("3.234055244384789")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable latconst delete"); command("clear"); command("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000 metal"); command("kim query latconst list get_lattice_constant_hexagonal crystal=[hcp] species=[Zr] " "units=[angstrom]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("latconst"), StrEq("3.234055244384789 5.167650199630013")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal"); command("kim query alpha get_linear_thermal_expansion_coefficient_cubic " "crystal=[fcc] species=[Al] units=[1/K] temperature=[293.15] " "temperature_units=[K]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(variable->retrieve("alpha"), StrEq("1.654960564704273e-05")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim query model_list list get_available_models species=[Al]"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); std::string model_list = variable->retrieve("model_list"); auto n = model_list.find("EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005"); ASSERT_TRUE(n != std::string::npos); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim query model_name index get_available_models species=[Al]"); command("variable model_name delete"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("kim query model_name index get_available_models " @@ -708,7 +675,7 @@ TEST_F(KimCommandsTest, kim_query) command("kim query model_name index get_available_models " "species=[Al] potential_type=[\"eam\",meam]"); command("variable model_name delete"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); #endif } } // namespace LAMMPS_NS @@ -718,7 +685,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/commands/test_lattice_region.cpp b/unittest/commands/test_lattice_region.cpp index 2924c75d9f..eb6d577652 100644 --- a/unittest/commands/test_lattice_region.cpp +++ b/unittest/commands/test_lattice_region.cpp @@ -22,6 +22,7 @@ #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -32,12 +33,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { @@ -45,51 +40,22 @@ using ::testing::ExitedWithCode; using ::testing::MatchesRegex; using ::testing::StrEq; -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } -class LatticeRegionTest : public ::testing::Test { +class LatticeRegionTest : public LAMMPSTest { protected: - LAMMPS *lmp; - void SetUp() override { - const char *args[] = {"LatticeRegionTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - lmp->input->one("units metal"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "LatticeRegionTest"; + LAMMPSTest::SetUp(); + command("units metal"); } - - void TearDown() override - { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(LatticeRegionTest, lattice_none) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice none 2.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::NONE); ASSERT_EQ(lattice->xlattice, 2.0); @@ -103,10 +69,10 @@ TEST_F(LatticeRegionTest, lattice_none) TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice none 1.0 origin");); TEST_FAILURE(".*ERROR: Expected floating point.*", command("lattice none xxx");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units lj"); command("lattice none 1.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); lattice = lmp->domain->lattice; ASSERT_EQ(lattice->xlattice, 1.0); ASSERT_EQ(lattice->ylattice, 1.0); @@ -168,27 +134,27 @@ TEST_F(LatticeRegionTest, lattice_sc) TEST_FAILURE(".*ERROR: Lattice spacings are invalid.*", command("lattice sc 1.0 spacing 1.0 -0.1 1.0");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units lj"); command("lattice sc 2.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); lattice = lmp->domain->lattice; ASSERT_DOUBLE_EQ(lattice->xlattice, pow(0.5, 1.0 / 3.0)); ASSERT_DOUBLE_EQ(lattice->ylattice, pow(0.5, 1.0 / 3.0)); ASSERT_DOUBLE_EQ(lattice->zlattice, pow(0.5, 1.0 / 3.0)); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice sc 1.0");); } TEST_F(LatticeRegionTest, lattice_bcc) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice bcc 4.2 orient x 1 1 0 orient y -1 1 0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::BCC); ASSERT_DOUBLE_EQ(lattice->xlattice, sqrt(2.0) * 4.2); @@ -202,18 +168,18 @@ TEST_F(LatticeRegionTest, lattice_bcc) ASSERT_EQ(lattice->basis[1][1], 0.5); ASSERT_EQ(lattice->basis[1][2], 0.5); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice bcc 1.0");); } TEST_F(LatticeRegionTest, lattice_fcc) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 3.5 origin 0.5 0.5 0.5"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::FCC); ASSERT_DOUBLE_EQ(lattice->xlattice, 3.5); @@ -239,18 +205,18 @@ TEST_F(LatticeRegionTest, lattice_fcc) command("lattice fcc 1.0 a1 0.0 1.0 0.0");); TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice fcc 1.0 orient w 1 0 0");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice fcc 1.0");); } TEST_F(LatticeRegionTest, lattice_hcp) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice hcp 3.0 orient z 0 0 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::HCP); ASSERT_DOUBLE_EQ(lattice->xlattice, 3.0); @@ -283,18 +249,18 @@ TEST_F(LatticeRegionTest, lattice_hcp) command("lattice hcp 1.0 a2 0.0 1.0 0.0");); TEST_FAILURE(".*ERROR: Invalid option in lattice command for non-custom style.*", command("lattice hcp 1.0 a3 0.0 1.0 0.0");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice hcp 1.0");); } TEST_F(LatticeRegionTest, lattice_diamond) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice diamond 4.1 orient x 1 1 2 orient y -1 1 0 orient z -1 -1 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::DIAMOND); ASSERT_DOUBLE_EQ(lattice->xlattice, 6.6952719636073539); @@ -335,19 +301,19 @@ TEST_F(LatticeRegionTest, lattice_diamond) ASSERT_EQ(lattice->a3[1], 0.0); ASSERT_EQ(lattice->a3[2], 1.0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice diamond 1.0");); } TEST_F(LatticeRegionTest, lattice_sq) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); command("lattice sq 3.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::SQ); ASSERT_DOUBLE_EQ(lattice->xlattice, 3.0); @@ -361,19 +327,19 @@ TEST_F(LatticeRegionTest, lattice_sq) TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*", command("lattice sq 1.0 orient x 1 1 2 orient y -1 1 0 orient z -1 -1 1");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 3"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice sq 1.0");); } TEST_F(LatticeRegionTest, lattice_sq2) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); command("lattice sq2 2.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::SQ2); ASSERT_DOUBLE_EQ(lattice->xlattice, 2.0); @@ -387,19 +353,19 @@ TEST_F(LatticeRegionTest, lattice_sq2) ASSERT_EQ(lattice->basis[1][1], 0.5); ASSERT_EQ(lattice->basis[1][2], 0.0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 3"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice sq2 1.0");); } TEST_F(LatticeRegionTest, lattice_hex) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); command("lattice hex 2.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::HEX); ASSERT_DOUBLE_EQ(lattice->xlattice, 2.0); @@ -422,16 +388,16 @@ TEST_F(LatticeRegionTest, lattice_hex) ASSERT_EQ(lattice->a3[1], 0.0); ASSERT_EQ(lattice->a3[2], 1.0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 3"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Lattice style incompatible with simulation dimension.*", command("lattice hex 1.0");); } TEST_F(LatticeRegionTest, lattice_custom) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable a equal 4.34"); command("variable b equal $a*sqrt(3.0)"); command("variable c equal $a*sqrt(8.0/3.0)"); @@ -449,7 +415,7 @@ TEST_F(LatticeRegionTest, lattice_custom) "basis 0.5 0.5 0.625 " "basis $t 0.0 0.125 " "basis $f 0.5 0.125 "); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto lattice = lmp->domain->lattice; ASSERT_EQ(lattice->style, Lattice::CUSTOM); ASSERT_DOUBLE_EQ(lattice->xlattice, 4.34); @@ -495,9 +461,9 @@ TEST_F(LatticeRegionTest, lattice_custom) TEST_FAILURE(".*ERROR: Illegal lattice command.*", command("lattice custom 1.0 basis 0.0 1.0 0");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: No basis atoms in lattice.*", command("lattice custom 1.0");); TEST_FAILURE(".*ERROR: Lattice settings are not compatible with 2d simulation.*", command("lattice custom 1.0 origin 0.5 0.5 0.5 basis 0.0 0.0 0.0");); @@ -511,28 +477,28 @@ TEST_F(LatticeRegionTest, lattice_custom) TEST_F(LatticeRegionTest, region_fail) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice none 2.0"); command("region box block 0 1 0 1 0 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Create_atoms command before simulation box is defined.*", command("create_atoms 1 box");); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Cannot create atoms with undefined lattice.*", command("create_atoms 1 box");); } TEST_F(LatticeRegionTest, region_block_lattice) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice sc 1.5"); command("region box block 0 2 0 2 0 2 units lattice"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); auto x = lmp->atom->x; @@ -553,12 +519,12 @@ TEST_F(LatticeRegionTest, region_block_lattice) TEST_F(LatticeRegionTest, region_block_box) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice sc 1.5 origin 0.75 0.75 0.75"); command("region box block 0 2 0 2 0 2 units box"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); auto x = lmp->atom->x; @@ -570,84 +536,84 @@ TEST_F(LatticeRegionTest, region_block_box) TEST_F(LatticeRegionTest, region_cone) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 2.5 origin 0.5 0.5 0.5"); command("region box cone x 1.0 1.0 0.5 2.1 0.0 2.0"); command("create_box 1 box"); command("create_atoms 1 region box"); command("write_dump all atom init.lammpstrj"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 42); } TEST_F(LatticeRegionTest, region_cylinder) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 2.5 origin 0.5 0.5 0.5"); command("region box cylinder z 1.0 1.0 2.1 0.0 2.0 "); command("create_box 1 box"); command("create_atoms 1 region box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 114); } TEST_F(LatticeRegionTest, region_prism) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice bcc 2.5 origin 0.75 0.75 0.75"); command("region box prism 0 2 0 2 0 2 0.5 0.0 0.0"); command("create_box 1 box"); command("create_atoms 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 1); ASSERT_EQ(lmp->atom->natoms, 16); } TEST_F(LatticeRegionTest, region_sphere) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 2.5 origin 0.5 0.5 0.5"); command("region box sphere 1.0 1.0 1.0 1.1"); command("create_box 1 box"); command("create_atoms 1 region box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 14); } TEST_F(LatticeRegionTest, region_union) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 2.5 origin 0.5 0.5 0.5"); command("region part1 sphere 2.0 1.0 1.0 1.1"); command("region part2 block 0.0 2.0 0.0 2.0 0.0 2.0"); command("region box union 2 part1 part2"); command("create_box 1 box"); command("create_atoms 1 region box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 67); } TEST_F(LatticeRegionTest, region_intersect) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 2.5 origin 0.5 0.5 0.5"); command("region part1 sphere 2.0 1.0 1.0 1.8"); command("region part2 block 0.0 2.0 0.0 2.0 0.0 2.0"); command("region box intersect 2 part1 part2"); command("create_box 1 box"); command("create_atoms 1 region box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 21); } TEST_F(LatticeRegionTest, region_plane) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("lattice fcc 2.5 origin 0.5 0.5 0.5"); command("region box block 0.0 2.0 0.0 2.0 0.0 2.0"); command("region part1 plane 0.5 1.0 0.0 0.75 0.0 0.0"); @@ -656,7 +622,7 @@ TEST_F(LatticeRegionTest, region_plane) command("create_box 1 box"); command("create_atoms 1 region atoms"); command("write_dump all atom init.lammpstrj"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->domain->triclinic, 0); ASSERT_EQ(lmp->atom->natoms, 16); } @@ -668,7 +634,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/commands/test_reset_ids.cpp b/unittest/commands/test_reset_ids.cpp index 89e09b53a6..694fc9ac77 100644 --- a/unittest/commands/test_reset_ids.cpp +++ b/unittest/commands/test_reset_ids.cpp @@ -21,6 +21,7 @@ #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -28,12 +29,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { @@ -41,52 +36,23 @@ using ::testing::MatchesRegex; #define GETIDX(i) lmp->atom->map(i) -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } #define STRINGIFY(val) XSTR(val) #define XSTR(val) #val -class ResetIDsTest : public ::testing::Test { +class ResetIDsTest : public LAMMPSTest { protected: - LAMMPS *lmp; - void SetUp() override { - const char *args[] = {"ResetIDsTest", "-log", "none", "-nocite", "-echo", "screen"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - Info *info = new Info(lmp); + testbinary = "ResetIDsTest"; + LAMMPSTest::SetUp(); if (info->has_style("atom", "full")) { - lmp->input->one("variable input_dir index " STRINGIFY(TEST_INPUT_FOLDER)); - lmp->input->one("include ${input_dir}/in.fourmol"); + BEGIN_HIDE_OUTPUT(); + command("variable input_dir index " STRINGIFY(TEST_INPUT_FOLDER)); + command("include ${input_dir}/in.fourmol"); + END_HIDE_OUTPUT(); } - delete info; - if (!verbose) ::testing::internal::GetCapturedStdout(); } - - void TearDown() override - { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(ResetIDsTest, MolIDAll) @@ -126,9 +92,9 @@ TEST_F(ResetIDsTest, MolIDAll) // the original data file has two different molecule IDs // for two residues of the same molecule/fragment. - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_mol_ids all"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(molid[GETIDX(1)], 1); ASSERT_EQ(molid[GETIDX(2)], 1); @@ -168,12 +134,12 @@ TEST_F(ResetIDsTest, DeletePlusAtomID) auto molid = lmp->atom->molecule; // delete two water molecules - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group allwater molecule 3:6"); command("group twowater molecule 4:6:2"); command("delete_atoms group twowater compress no bond yes"); command("reset_mol_ids all"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->natoms, 23); ASSERT_EQ(lmp->atom->map_tag_max, 26); @@ -230,9 +196,9 @@ TEST_F(ResetIDsTest, DeletePlusAtomID) ASSERT_GE(GETIDX(25), 0); ASSERT_GE(GETIDX(26), 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->map_tag_max, 23); for (int i = 1; i <= 23; ++i) @@ -246,11 +212,11 @@ TEST_F(ResetIDsTest, PartialOffset) auto molid = lmp->atom->molecule; // delete two water molecules - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group allwater molecule 3:6"); command("group nowater subtract all allwater"); command("reset_mol_ids allwater offset 4"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->natoms, 29); ASSERT_EQ(lmp->atom->map_tag_max, 29); @@ -284,9 +250,9 @@ TEST_F(ResetIDsTest, PartialOffset) ASSERT_EQ(molid[GETIDX(28)], 8); ASSERT_EQ(molid[GETIDX(29)], 8); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_mol_ids nowater offset 0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(molid[GETIDX(1)], 1); ASSERT_EQ(molid[GETIDX(2)], 1); @@ -326,13 +292,13 @@ TEST_F(ResetIDsTest, DeleteAdd) auto molid = lmp->atom->molecule; // delete two water molecules - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group allwater molecule 3:6"); command("group twowater molecule 4:6:2"); command("group nowater subtract all allwater"); command("delete_atoms group twowater compress no bond yes mol yes"); command("reset_mol_ids allwater"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->natoms, 23); ASSERT_EQ(lmp->atom->map_tag_max, 26); @@ -389,17 +355,17 @@ TEST_F(ResetIDsTest, DeleteAdd) ASSERT_GE(GETIDX(25), 0); ASSERT_GE(GETIDX(26), 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids sort yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->map_tag_max, 23); for (int i = 1; i <= 23; ++i) ASSERT_GE(GETIDX(i), 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_mol_ids nowater offset 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(molid[GETIDX(1)], 2); ASSERT_EQ(molid[GETIDX(2)], 2); @@ -425,13 +391,13 @@ TEST_F(ResetIDsTest, DeleteAdd) ASSERT_EQ(molid[GETIDX(22)], 4); ASSERT_EQ(molid[GETIDX(23)], 4); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_atoms 1 single 0.0 0.0 0.0"); command("create_atoms 2 single 1.0 0.0 0.0"); command("create_atoms 3 single 2.0 0.0 0.0"); command("create_atoms 4 single 3.0 0.0 0.0"); command("reset_mol_ids all single yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->natoms, 27); ASSERT_EQ(lmp->atom->map_tag_max, 27); @@ -443,9 +409,9 @@ TEST_F(ResetIDsTest, DeleteAdd) ASSERT_EQ(molid[GETIDX(26)], 6); ASSERT_EQ(molid[GETIDX(27)], 7); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_mol_ids all single no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(molid[GETIDX(21)], 3); ASSERT_EQ(molid[GETIDX(22)], 3); @@ -455,9 +421,9 @@ TEST_F(ResetIDsTest, DeleteAdd) ASSERT_EQ(molid[GETIDX(26)], 0); ASSERT_EQ(molid[GETIDX(27)], 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_mol_ids all compress no single yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(molid[GETIDX(21)], 21); ASSERT_EQ(molid[GETIDX(22)], 21); @@ -473,12 +439,12 @@ TEST_F(ResetIDsTest, TopologyData) if (lmp->atom->natoms == 0) GTEST_SKIP(); // delete two water molecules - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group allwater molecule 3:6"); command("group twowater molecule 4:6:2"); command("group nowater subtract all allwater"); command("delete_atoms group twowater compress no bond yes mol yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->natoms, 23); ASSERT_EQ(lmp->atom->map_tag_max, 26); @@ -562,9 +528,9 @@ TEST_F(ResetIDsTest, TopologyData) ASSERT_EQ(angle_atom2[GETIDX(24)][0], 24); ASSERT_EQ(angle_atom3[GETIDX(24)][0], 26); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids sort yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); num_bond = lmp->atom->num_bond; num_angle = lmp->atom->num_angle; @@ -679,41 +645,40 @@ TEST_F(ResetIDsTest, DeathTests) command("reset_mol_ids all single xxx");); } -TEST(ResetMolIds, CMDFail) +class ResetMolIDsTest : public LAMMPSTest { +protected: + void SetUp() override + { + testbinary = "ResetIDsTest"; + LAMMPSTest::SetUp(); + } +}; + +TEST_F(ResetMolIDsTest, FailBeforeBox) { - LAMMPS *lmp; - const char *args[] = {"ResetIDsTest", "-log", "none", "-nocite", "-echo", "screen"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); - TEST_FAILURE(".*ERROR: Reset_mol_ids command before simulation box is.*", - lmp->input->one("reset_mol_ids all");); + command("reset_mol_ids all");); +} - auto command = [&](const std::string &line) { - lmp->input->one(line.c_str()); - }; - - if (!verbose) ::testing::internal::CaptureStdout(); +TEST_F(ResetMolIDsTest, FailMissingId) +{ + BEGIN_HIDE_OUTPUT(); command("atom_modify id no"); command("region box block 0 1 0 1 0 1"); command("create_box 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Cannot use reset_mol_ids unless.*", command("reset_mol_ids all");); +} - if (!verbose) ::testing::internal::CaptureStdout(); +TEST_F(ResetMolIDsTest, FailOnlyMolecular) +{ + BEGIN_HIDE_OUTPUT(); command("clear"); command("region box block 0 1 0 1 0 1"); command("create_box 1 box"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Can only use reset_mol_ids.*", command("reset_mol_ids all");); - - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); -}; +} } // namespace LAMMPS_NS @@ -722,7 +687,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 45183a2e54..d41ad52e57 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -24,6 +24,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -31,12 +32,6 @@ // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - using LAMMPS_NS::MathConst::MY_PI; using LAMMPS_NS::utils::split_words; @@ -45,39 +40,18 @@ using ::testing::ExitedWithCode; using ::testing::MatchesRegex; using ::testing::StrEq; -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - if (verbose) std::cout << mesg; \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - if (verbose) std::cout << mesg; \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } -class VariableTest : public ::testing::Test { +class VariableTest : public LAMMPSTest { protected: - LAMMPS *lmp; Group *group; Domain *domain; Variable *variable; void SetUp() override { - const char *args[] = {"VariableTest", "-log", "none", "-echo", "screen", - "-nocite", "-v", "num", "1"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "VariableTest"; + args = {"-log", "none", "-echo", "screen", "-nocite", "-v", "num", "1"}; + LAMMPSTest::SetUp(); group = lmp->group; domain = lmp->domain; variable = lmp->input->variable; @@ -85,19 +59,14 @@ protected: void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); - std::cout.flush(); + LAMMPSTest::TearDown(); unlink("test_variable.file"); unlink("test_variable.atomfile"); } - void command(const std::string &cmd) { lmp->input->one(cmd); } - void atomic_system() { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units real"); command("lattice sc 1.0 origin 0.125 0.125 0.125"); command("region box block -2 2 -2 2 -2 2"); @@ -109,23 +78,23 @@ protected: command("region top block INF INF -2.0 -1.0 INF INF"); command("set region left type 2"); command("set region right type 3"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void molecular_system() { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("fix props all property/atom mol rmass q"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); atomic_system(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable molid atom floor(id/4)+1"); command("variable charge atom 2.0*sin(PI/32*id)"); command("set atom * mol v_molid"); command("set atom * charge v_charge"); command("set type 1 mass 0.5"); command("set type 2*4 mass 2.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void file_vars() @@ -152,7 +121,7 @@ TEST_F(VariableTest, CreateDelete) { file_vars(); ASSERT_EQ(variable->nvar, 1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable one index 1 2 3 4"); command("variable two equal 1"); command("variable two equal 2"); @@ -173,11 +142,11 @@ TEST_F(VariableTest, CreateDelete) command("variable ten2 uloop 4"); command("variable ten3 uloop 4 pad"); command("variable dummy index 0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(variable->nvar, 17); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable dummy delete"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(variable->nvar, 16); ASSERT_THAT(variable->retrieve("three"), StrEq("three")); variable->set_string("three", "four"); @@ -235,7 +204,7 @@ TEST_F(VariableTest, AtomicSystem) atomic_system(); file_vars(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable one index 1 2 3 4"); command("variable id atom type"); command("variable id atom id"); @@ -262,7 +231,7 @@ TEST_F(VariableTest, AtomicSystem) command("variable rgsum equal sum(v_rg)"); command("variable loop equal v_loop+1"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(variable->atomstyle(variable->find("one")), 0); ASSERT_EQ(variable->atomstyle(variable->find("id")), 1); @@ -294,7 +263,7 @@ TEST_F(VariableTest, AtomicSystem) TEST_F(VariableTest, Expressions) { atomic_system(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable one index 1"); command("variable two equal 2"); command("variable three equal v_one+v_two"); @@ -321,7 +290,7 @@ TEST_F(VariableTest, Expressions) command("variable err2 equal v_one%v_ten7"); command("variable err3 equal v_ten7^-v_one"); variable->set("dummy index 1 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); int ivar = variable->find("one"); ASSERT_FALSE(variable->equalstyle(ivar)); @@ -364,7 +333,7 @@ TEST_F(VariableTest, Functions) atomic_system(); file_vars(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable one index 1"); command("variable two equal random(1,2,643532)"); command("variable three equal atan2(v_one,1)"); @@ -377,7 +346,7 @@ TEST_F(VariableTest, Functions) command("variable ten equal floor(1.85)+ceil(1.85)"); command("variable ten1 equal tan(v_eight/2.0)"); command("variable ten2 equal asin(-1.0)+acos(0.0)"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_GT(variable->compute_equal(variable->find("two")), 0.99); ASSERT_LT(variable->compute_equal(variable->find("two")), 2.01); @@ -396,74 +365,64 @@ TEST_F(VariableTest, Functions) TEST_F(VariableTest, IfCommand) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable one index 1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if 1>0 then 'print \"bingo!\"'"); - auto text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + auto text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if 1>2 then 'print \"bingo!\"' else 'print \"nope?\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*nope\?.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if (1<=0) then 'print \"bingo!\"' else 'print \"nope?\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*nope\?.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if (-1.0e-1<0.0E+0)|^(1<0) then 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if (${one}==1.0)&&(2>=1) then 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if !((${one}!=1.0)||(2|^1)) then 'print \"missed\"' else 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if (1>=2)&&(0&&1) then 'print \"missed\"' else 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if !1 then 'print \"missed\"' else 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if !(a==b) then 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if x==x|^1==0 then 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("if x!=x|^a!=b then 'print \"bingo!\"'"); - text = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << text; + text = END_CAPTURE_OUTPUT(); + ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", @@ -492,34 +451,34 @@ TEST_F(VariableTest, NextCommand) { file_vars(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("variable one index 1 2"); command("variable two equal 2"); command("variable three file test_variable.file"); command("variable four loop 2 4"); command("variable five index 1 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_DOUBLE_EQ(variable->compute_equal("v_one"), 1); ASSERT_THAT(variable->retrieve("three"), StrEq("one")); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("next one"); command("next three"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_DOUBLE_EQ(variable->compute_equal("v_one"), 2); ASSERT_THAT(variable->retrieve("three"), StrEq("two")); ASSERT_GE(variable->find("one"), 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("next one"); command("next three"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // index style variable is deleted if no more next element ASSERT_EQ(variable->find("one"), -1); ASSERT_GE(variable->find("three"), 0); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("next three"); command("next three"); command("next three"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // file style variable is deleted if no more next element ASSERT_EQ(variable->find("three"), -1); @@ -536,7 +495,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/formats/compressed_dump_test.h b/unittest/formats/compressed_dump_test.h index c8afb2aac3..6bc26e123d 100644 --- a/unittest/formats/compressed_dump_test.h +++ b/unittest/formats/compressed_dump_test.h @@ -45,14 +45,14 @@ public: void enable_triclinic() { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); if (!dump_modify_options.empty()) { @@ -60,7 +60,7 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, @@ -76,7 +76,7 @@ public: std::string text_modify_options, std::string compressed_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, text_options)); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, compressed_options)); @@ -89,17 +89,17 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } std::string convert_compressed_to_text(std::string compressed_file) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string cmdline = fmt::format("{} -d -c {} > {}", COMPRESS_BINARY, compressed_file, converted_file); system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); return converted_file; } }; diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index b787076495..67ee9742e5 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -24,6 +24,7 @@ #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -98,38 +99,28 @@ const double EPSILON = 5.0e-14; namespace LAMMPS_NS { using ::testing::Eq; -class AtomStyleTest : public ::testing::Test { +class AtomStyleTest : public LAMMPSTest { protected: - LAMMPS *lmp; - void SetUp() override { - const char *args[] = {"SimpleCommandsTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "AtomStyleTest"; + LAMMPSTest::SetUp(); ASSERT_NE(lmp, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units real"); command("dimension 3"); command("pair_style zero 4.0"); command("region box block -4 4 -4 4 -4 4"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); + LAMMPSTest::TearDown(); remove("test_atom_styles.data"); remove("input_atom_styles.data"); remove("test_atom_styles.restart"); } - - void command(const std::string cmd) { lmp->input->one(cmd); } }; // default class Atom state @@ -503,17 +494,17 @@ TEST_F(AtomStyleTest, atomic_after_charge) expected.has_v = true; expected.has_f = true; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style charge"); command("atom_style atomic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_ATOM_STATE_EQ(lmp->atom, expected); } TEST_F(AtomStyleTest, atomic) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_modify map hash"); command("create_box 2 box"); command("create_atoms 1 single -2.0 2.0 0.1"); @@ -523,7 +514,7 @@ TEST_F(AtomStyleTest, atomic) command("mass 1 4.0"); command("mass 2 2.4"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -541,7 +532,7 @@ TEST_F(AtomStyleTest, atomic) ASSERT_EQ(lmp->atom->map_style, Atom::MAP_HASH); ASSERT_EQ(lmp->atom->map_user, 2); ASSERT_EQ(lmp->atom->map_tag_max, 4); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("write_data test_atom_styles.data nocoeff"); command("clear"); @@ -550,7 +541,7 @@ TEST_F(AtomStyleTest, atomic) command("atom_modify map array"); command("units real"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -598,14 +589,14 @@ TEST_F(AtomStyleTest, atomic) ASSERT_EQ(lmp->atom->map_tag_max, 4); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); command("write_restart test_atom_styles.restart"); command("clear"); command("read_restart test_atom_styles.restart"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 2); @@ -639,16 +630,16 @@ TEST_F(AtomStyleTest, atomic) ASSERT_EQ(lmp->atom->map_style, Atom::MAP_ARRAY); ASSERT_EQ(lmp->atom->map_user, 1); ASSERT_EQ(lmp->atom->map_tag_max, 3); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->map_tag_max, 2); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("comm_style tiled"); command("change_box all triclinic"); command("replicate 2 2 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->map_tag_max, 16); x = lmp->atom->x; tag = lmp->atom->tag; @@ -704,9 +695,9 @@ TEST_F(AtomStyleTest, atomic) TEST_F(AtomStyleTest, charge) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style charge"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "charge"; @@ -721,7 +712,7 @@ TEST_F(AtomStyleTest, charge) expected.q_flag = 1; ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 2 box"); command("create_atoms 1 single -2.0 2.0 0.1"); command("create_atoms 1 single -2.0 -2.0 -0.1"); @@ -734,7 +725,7 @@ TEST_F(AtomStyleTest, charge) command("set atom 3 charge -1.0"); command("set atom 4 charge 1.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("charge")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -747,7 +738,7 @@ TEST_F(AtomStyleTest, charge) ASSERT_NE(lmp->atom->mass, nullptr); ASSERT_NE(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("write_data test_atom_styles.data nocoeff"); command("clear"); @@ -756,7 +747,7 @@ TEST_F(AtomStyleTest, charge) command("units real"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("charge")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -810,7 +801,7 @@ TEST_F(AtomStyleTest, charge) ASSERT_EQ(lmp->atom->mass_setflag[1], 1); ASSERT_EQ(lmp->atom->mass_setflag[2], 1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -818,7 +809,7 @@ TEST_F(AtomStyleTest, charge) command("clear"); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); command("read_restart test_atom_styles.restart"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("charge")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 2); @@ -854,11 +845,11 @@ TEST_F(AtomStyleTest, charge) ASSERT_EQ(lmp->atom->mass_setflag[1], 1); ASSERT_EQ(lmp->atom->mass_setflag[2], 1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); command("change_box all triclinic"); command("replicate 2 2 2 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->map_tag_max, 16); q = lmp->atom->q; EXPECT_NEAR(q[GETIDX(1)], -0.5, EPSILON); @@ -881,9 +872,9 @@ TEST_F(AtomStyleTest, charge) TEST_F(AtomStyleTest, sphere) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style sphere"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "sphere"; @@ -903,7 +894,7 @@ TEST_F(AtomStyleTest, sphere) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 2 box"); command("create_atoms 1 single -2.0 2.0 0.1"); command("create_atoms 1 single -2.0 -2.0 -0.1"); @@ -918,7 +909,7 @@ TEST_F(AtomStyleTest, sphere) command("set atom 3 omega -1.0 0.0 0.0"); command("set atom 4 omega 0.0 1.0 0.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("sphere")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -932,7 +923,7 @@ TEST_F(AtomStyleTest, sphere) ASSERT_EQ(lmp->atom->mass, nullptr); ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("write_data test_atom_styles.data nocoeff"); command("clear"); @@ -941,7 +932,7 @@ TEST_F(AtomStyleTest, sphere) command("units real"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("sphere")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -1005,7 +996,7 @@ TEST_F(AtomStyleTest, sphere) EXPECT_NEAR(omega[GETIDX(4)][1], 1.0, EPSILON); EXPECT_NEAR(omega[GETIDX(4)][2], 0.0, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -1015,7 +1006,7 @@ TEST_F(AtomStyleTest, sphere) command("read_restart test_atom_styles.restart"); command("replicate 1 1 2"); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("sphere")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -1052,9 +1043,9 @@ TEST_F(AtomStyleTest, ellipsoid) { if (!LAMMPS::is_installed_pkg("ASPHERE")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style ellipsoid"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "ellipsoid"; @@ -1073,7 +1064,7 @@ TEST_F(AtomStyleTest, ellipsoid) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 3 box"); command("create_atoms 1 single -2.0 2.0 0.1"); command("create_atoms 1 single -2.0 -2.0 -0.1"); @@ -1091,7 +1082,7 @@ TEST_F(AtomStyleTest, ellipsoid) command("set atom 3 quat 1.0 0.0 1.0 30.0"); command("set atom 4 quat 1.0 1.0 1.0 60.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("ellipsoid")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -1119,7 +1110,7 @@ TEST_F(AtomStyleTest, ellipsoid) ASSERT_NE(lmp->atom->ellipsoid, nullptr); ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("atom_style ellipsoid"); @@ -1128,7 +1119,7 @@ TEST_F(AtomStyleTest, ellipsoid) command("atom_modify map array"); command("read_data test_atom_styles.data"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("ellipsoid")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -1238,7 +1229,7 @@ TEST_F(AtomStyleTest, ellipsoid) EXPECT_NEAR(bonus[3].quat[2], sqrt(5.0 / 30.0), EPSILON); EXPECT_NEAR(bonus[3].quat[3], sqrt(5.0 / 30.0), EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group two id 2:4:2"); command("delete_atoms group two compress no"); command("write_restart test_atom_styles.restart"); @@ -1246,7 +1237,7 @@ TEST_F(AtomStyleTest, ellipsoid) command("read_restart test_atom_styles.restart"); command("comm_style tiled"); command("replicate 1 1 2 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("ellipsoid")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 8); @@ -1319,9 +1310,9 @@ TEST_F(AtomStyleTest, ellipsoid) EXPECT_NEAR(bonus[3].quat[2], 0.0, EPSILON); EXPECT_NEAR(bonus[3].quat[3], 0.25056280708573159, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->nellipsoids, 4); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -1389,10 +1380,10 @@ TEST_F(AtomStyleTest, line) { if (!LAMMPS::is_installed_pkg("ASPHERE")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dimension 2"); command("atom_style line"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "line"; @@ -1414,7 +1405,7 @@ TEST_F(AtomStyleTest, line) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 3 box"); command("create_atoms 1 single -2.0 2.0 0.0"); command("create_atoms 1 single -2.0 -2.0 0.0"); @@ -1432,7 +1423,7 @@ TEST_F(AtomStyleTest, line) command("set atom 3 theta 30.0"); command("set atom 4 theta 60.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("line")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -1448,7 +1439,7 @@ TEST_F(AtomStyleTest, line) ASSERT_NE(lmp->atom->rmass, nullptr); ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("dimension 2"); @@ -1457,7 +1448,7 @@ TEST_F(AtomStyleTest, line) command("units real"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("line")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -1547,7 +1538,7 @@ TEST_F(AtomStyleTest, line) EXPECT_NEAR(bonus[3].length, 3.0, EPSILON); EXPECT_NEAR(bonus[3].theta, MathConst::MY_PI / 3.0, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -1557,7 +1548,7 @@ TEST_F(AtomStyleTest, line) command("comm_style tiled"); command("change_box all triclinic"); command("replicate 1 2 1 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("line")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 8); @@ -1610,9 +1601,9 @@ TEST_F(AtomStyleTest, line) EXPECT_NEAR(bonus[3].length, 3.0, EPSILON); EXPECT_NEAR(bonus[3].theta, MathConst::MY_PI / 6.0, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->nlines, 4); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -1660,9 +1651,9 @@ TEST_F(AtomStyleTest, tri) { if (!LAMMPS::is_installed_pkg("ASPHERE")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style tri"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "tri"; @@ -1685,7 +1676,7 @@ TEST_F(AtomStyleTest, tri) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 3 box"); command("create_atoms 1 single -2.0 2.0 0.1"); command("create_atoms 1 single -2.0 -2.0 -0.1"); @@ -1703,7 +1694,7 @@ TEST_F(AtomStyleTest, tri) command("set atom 3 quat 1.0 0.0 1.0 30.0"); command("set atom 4 quat 1.0 1.0 1.0 60.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("tri")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -1731,7 +1722,7 @@ TEST_F(AtomStyleTest, tri) ASSERT_NE(lmp->atom->tri, nullptr); ASSERT_EQ(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("atom_style tri"); @@ -1740,7 +1731,7 @@ TEST_F(AtomStyleTest, tri) command("atom_modify map array"); command("read_data test_atom_styles.data"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("tri")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -1893,7 +1884,7 @@ TEST_F(AtomStyleTest, tri) EXPECT_NEAR(bonus[3].c3[1], 0.64304946932374796, EPSILON); EXPECT_NEAR(bonus[3].c3[2], -0.32808266428854477, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group two id 2:4:2"); command("delete_atoms group two compress no"); command("write_restart test_atom_styles.restart"); @@ -1901,7 +1892,7 @@ TEST_F(AtomStyleTest, tri) command("read_restart test_atom_styles.restart"); command("change_box all triclinic"); command("replicate 1 1 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("tri")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 8); @@ -2019,9 +2010,9 @@ TEST_F(AtomStyleTest, tri) EXPECT_NEAR(bonus[3].c3[1], 0.85047049833171351, EPSILON); EXPECT_NEAR(bonus[3].c3[2], -0.15731490073748589, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->ntris, 4); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -2064,9 +2055,9 @@ TEST_F(AtomStyleTest, body_nparticle) { if (!LAMMPS::is_installed_pkg("BODY")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style body nparticle 2 4"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "body"; @@ -2129,7 +2120,7 @@ TEST_F(AtomStyleTest, body_nparticle) FILE *fp = fopen("input_atom_styles.data", "w"); fputs(data_file, fp); fclose(fp); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_modify map array"); command("read_data input_atom_styles.data"); command("create_atoms 3 single 2.0 2.0 -2.1"); @@ -2140,7 +2131,7 @@ TEST_F(AtomStyleTest, body_nparticle) command("set atom 3 quat 1.0 0.0 1.0 30.0"); command("set atom 4 quat 1.0 1.0 1.0 60.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("body")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -2306,7 +2297,7 @@ TEST_F(AtomStyleTest, body_nparticle) ASSERT_NE(bonus[2].dvalue, nullptr); ASSERT_NE(bonus[3].dvalue, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("atom_style body nparticle 2 4"); @@ -2315,7 +2306,7 @@ TEST_F(AtomStyleTest, body_nparticle) command("atom_modify map array"); command("read_data test_atom_styles.data"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("body")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -2479,7 +2470,7 @@ TEST_F(AtomStyleTest, body_nparticle) ASSERT_NE(bonus[2].dvalue, nullptr); ASSERT_NE(bonus[3].dvalue, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group two id 2:4:2"); command("delete_atoms group two compress no"); command("write_restart test_atom_styles.restart"); @@ -2487,7 +2478,7 @@ TEST_F(AtomStyleTest, body_nparticle) command("read_restart test_atom_styles.restart"); command("comm_style tiled"); command("replicate 1 1 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("body")); avec = (AtomVecBody *)lmp->atom->avec; ASSERT_THAT(std::string(avec->bptr->style), Eq("nparticle")); @@ -2594,9 +2585,9 @@ TEST_F(AtomStyleTest, body_nparticle) ASSERT_NE(bonus[2].dvalue, nullptr); ASSERT_NE(bonus[3].dvalue, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->nbodies, 4); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -2632,11 +2623,11 @@ TEST_F(AtomStyleTest, template) { if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP(); create_molecule_files(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); command("atom_style template twomols"); command("newton on"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "template"; @@ -2658,7 +2649,7 @@ TEST_F(AtomStyleTest, template) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 4 box bond/types 2 angle/types 2 "); command("create_atoms 0 single -2.0 2.0 0.1 mol twomols 65234"); command("create_atoms 0 single -2.0 -2.0 -0.1 mol twomols 62346"); @@ -2676,7 +2667,7 @@ TEST_F(AtomStyleTest, template) command("angle_style zero"); command("angle_coeff * 109.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 12); @@ -2706,7 +2697,7 @@ TEST_F(AtomStyleTest, template) ASSERT_NE(lmp->atom->mass, nullptr); ASSERT_NE(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data"); command("clear"); command("units real"); @@ -2718,7 +2709,7 @@ TEST_F(AtomStyleTest, template) command("angle_style zero"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -2780,7 +2771,7 @@ TEST_F(AtomStyleTest, template) ASSERT_EQ(molatom[GETIDX(11)], -1); ASSERT_EQ(molatom[GETIDX(12)], -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); @@ -2790,7 +2781,7 @@ TEST_F(AtomStyleTest, template) command("angle_style zero"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -2902,7 +2893,7 @@ TEST_F(AtomStyleTest, template) ASSERT_EQ(type[GETIDX(11)], 3); ASSERT_EQ(type[GETIDX(12)], 4); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group two id 7:10"); command("delete_atoms group two compress no"); command("write_restart test_atom_styles.restart"); @@ -2910,7 +2901,7 @@ TEST_F(AtomStyleTest, template) command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); command("read_restart test_atom_styles.restart"); command("replicate 1 1 2 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("template")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 16); @@ -2980,9 +2971,9 @@ TEST_F(AtomStyleTest, template) ASSERT_EQ(molatom[GETIDX(23)], -1); ASSERT_EQ(molatom[GETIDX(24)], -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 16); @@ -3028,11 +3019,11 @@ TEST_F(AtomStyleTest, template_charge) { if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP(); create_molecule_files(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); command("atom_style hybrid template twomols charge"); command("newton on"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "hybrid"; @@ -3063,7 +3054,7 @@ TEST_F(AtomStyleTest, template_charge) ASSERT_NE(hybrid->styles[0], nullptr); ASSERT_NE(hybrid->styles[1], nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 4 box bond/types 2 angle/types 2 "); command("create_atoms 0 single -2.0 2.0 0.1 mol twomols 65234"); command("create_atoms 0 single -2.0 -2.0 -0.1 mol twomols 62346"); @@ -3084,7 +3075,7 @@ TEST_F(AtomStyleTest, template_charge) command("angle_style zero"); command("angle_coeff * 109.0"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_NE(lmp->atom->avec, nullptr); hybrid = (AtomVecHybrid *)lmp->atom->avec; ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); @@ -3122,7 +3113,7 @@ TEST_F(AtomStyleTest, template_charge) ASSERT_NE(lmp->atom->mass, nullptr); ASSERT_NE(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data"); command("clear"); command("units real"); @@ -3134,7 +3125,7 @@ TEST_F(AtomStyleTest, template_charge) command("angle_style zero"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -3196,7 +3187,7 @@ TEST_F(AtomStyleTest, template_charge) ASSERT_EQ(molatom[GETIDX(11)], -1); ASSERT_EQ(molatom[GETIDX(12)], -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); @@ -3206,7 +3197,7 @@ TEST_F(AtomStyleTest, template_charge) command("angle_style zero"); command("atom_modify map array"); command("read_data test_atom_styles.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -3331,7 +3322,7 @@ TEST_F(AtomStyleTest, template_charge) ASSERT_EQ(type[GETIDX(11)], 3); ASSERT_EQ(type[GETIDX(12)], 4); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("group two id 7:10"); command("delete_atoms group two compress no"); command("write_restart test_atom_styles.restart"); @@ -3339,7 +3330,7 @@ TEST_F(AtomStyleTest, template_charge) command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); command("read_restart test_atom_styles.restart"); command("replicate 1 1 2 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 16); @@ -3409,9 +3400,9 @@ TEST_F(AtomStyleTest, template_charge) ASSERT_EQ(molatom[GETIDX(23)], -1); ASSERT_EQ(molatom[GETIDX(24)], -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 16); @@ -3457,10 +3448,10 @@ TEST_F(AtomStyleTest, bond) { if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style bond"); command("newton on"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "bond"; @@ -3480,7 +3471,7 @@ TEST_F(AtomStyleTest, bond) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 3 box bond/types 2 " "extra/bond/per/atom 2 extra/special/per/atom 4"); command("create_atoms 1 single -2.0 2.0 0.1"); @@ -3500,7 +3491,7 @@ TEST_F(AtomStyleTest, bond) command("create_bonds single/bond 2 3 5"); command("create_bonds single/bond 2 3 6"); command("create_bonds single/bond 2 5 6"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("bond")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -3533,7 +3524,7 @@ TEST_F(AtomStyleTest, bond) lmp->atom->bond_type[GETIDX(1)][0] *= -1; lmp->atom->bond_type[GETIDX(5)][0] *= -1; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("units real"); @@ -3545,7 +3536,7 @@ TEST_F(AtomStyleTest, bond) command("read_data test_atom_styles.data"); command("pair_coeff * *"); command("bond_coeff * 4.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("bond")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -3594,7 +3585,7 @@ TEST_F(AtomStyleTest, bond) ASSERT_EQ(bond_atom[GETIDX(6)][0], 3); ASSERT_EQ(bond_atom[GETIDX(6)][1], 5); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("atom_style bond"); @@ -3604,7 +3595,7 @@ TEST_F(AtomStyleTest, bond) command("read_data test_atom_styles.data"); command("pair_coeff * *"); command("bond_coeff * 4.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("bond")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -3692,7 +3683,7 @@ TEST_F(AtomStyleTest, bond) lmp->atom->bond_type[GETIDX(1)][0] *= -1; lmp->atom->bond_type[GETIDX(5)][0] *= -1; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -3700,7 +3691,7 @@ TEST_F(AtomStyleTest, bond) command("clear"); command("read_restart test_atom_styles.restart"); command("replicate 1 1 2 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("bond")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 8); @@ -3754,10 +3745,10 @@ TEST_F(AtomStyleTest, bond) ASSERT_EQ(bond_type[GETIDX(9)][1], 2); ASSERT_EQ(bond_type[GETIDX(11)][0], 2); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("delete_bonds all bond 2"); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -3805,10 +3796,10 @@ TEST_F(AtomStyleTest, angle) { if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style angle"); command("newton on"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "angle"; @@ -3829,7 +3820,7 @@ TEST_F(AtomStyleTest, angle) ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 3 box bond/types 2 angle/types 2 " "extra/bond/per/atom 2 extra/angle/per/atom 1 " "extra/special/per/atom 4"); @@ -3854,7 +3845,7 @@ TEST_F(AtomStyleTest, angle) command("create_bonds single/bond 2 5 6"); command("create_bonds single/angle 1 1 3 5"); command("create_bonds single/angle 2 3 5 6"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("angle")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -3889,7 +3880,7 @@ TEST_F(AtomStyleTest, angle) lmp->atom->angle_type[GETIDX(3)][0] *= -1; lmp->atom->angle_type[GETIDX(5)][0] *= -1; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("units real"); @@ -3903,7 +3894,7 @@ TEST_F(AtomStyleTest, angle) command("pair_coeff * *"); command("bond_coeff * 4.0"); command("angle_coeff * 90.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("angle")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -3987,7 +3978,7 @@ TEST_F(AtomStyleTest, angle) ASSERT_EQ(angle_atom2[GETIDX(6)][0], 5); ASSERT_EQ(angle_atom3[GETIDX(6)][0], 6); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("atom_style angle"); @@ -3997,7 +3988,7 @@ TEST_F(AtomStyleTest, angle) command("read_data test_atom_styles.data"); command("pair_coeff * *"); command("bond_coeff * 4.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("angle")); ASSERT_NE(lmp->atom->avec, nullptr); @@ -4086,7 +4077,7 @@ TEST_F(AtomStyleTest, angle) ASSERT_EQ(angle_type[GETIDX(3)][0], 1); ASSERT_EQ(angle_type[GETIDX(5)][0], 2); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -4094,7 +4085,7 @@ TEST_F(AtomStyleTest, angle) command("clear"); command("read_restart test_atom_styles.restart"); command("replicate 1 1 2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("angle")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 8); @@ -4131,10 +4122,10 @@ TEST_F(AtomStyleTest, angle) ASSERT_EQ(angle_type[GETIDX(9)][0], 1); ASSERT_EQ(angle_type[GETIDX(11)][0], 2); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("delete_bonds all angle 2"); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -4166,9 +4157,9 @@ TEST_F(AtomStyleTest, full_ellipsoid) if (!LAMMPS::is_installed_pkg("ASPHERE")) GTEST_SKIP(); if (!LAMMPS::is_installed_pkg("MOLECULE")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_style hybrid full ellipsoid"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "hybrid"; @@ -4204,7 +4195,7 @@ TEST_F(AtomStyleTest, full_ellipsoid) ASSERT_NE(hybrid->styles[0], nullptr); ASSERT_NE(hybrid->styles[1], nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 3 box bond/types 2 " "extra/bond/per/atom 2 extra/special/per/atom 4"); command("create_atoms 1 single -2.0 2.0 0.1"); @@ -4239,7 +4230,7 @@ TEST_F(AtomStyleTest, full_ellipsoid) command("create_bonds single/bond 2 3 5"); command("create_bonds single/bond 2 3 6"); command("create_bonds single/bond 2 5 6"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 6); @@ -4269,7 +4260,7 @@ TEST_F(AtomStyleTest, full_ellipsoid) ASSERT_NE(lmp->atom->ellipsoid, nullptr); ASSERT_NE(lmp->atom->mass_setflag, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("write_data test_atom_styles.data nocoeff"); command("clear"); command("units real"); @@ -4280,7 +4271,7 @@ TEST_F(AtomStyleTest, full_ellipsoid) command("read_data test_atom_styles.data"); command("pair_coeff * *"); command("bond_coeff * 4.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); ASSERT_NE(lmp->atom->avec, nullptr); hybrid = (AtomVecHybrid *)lmp->atom->avec; @@ -4405,7 +4396,7 @@ TEST_F(AtomStyleTest, full_ellipsoid) EXPECT_NEAR(bonus[3].quat[2], sqrt(5.0 / 30.0), EPSILON); EXPECT_NEAR(bonus[3].quat[3], sqrt(5.0 / 30.0), EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -4413,7 +4404,7 @@ TEST_F(AtomStyleTest, full_ellipsoid) command("clear"); command("read_restart test_atom_styles.restart"); command("replicate 1 1 2 bbox"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("hybrid")); hybrid = (AtomVecHybrid *)lmp->atom->avec; ASSERT_EQ(hybrid->nstyles, 2); @@ -4492,9 +4483,9 @@ TEST_F(AtomStyleTest, full_ellipsoid) EXPECT_NEAR(bonus[3].quat[2], 0.0, EPSILON); EXPECT_NEAR(bonus[3].quat[3], 0.25056280708573159, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->nellipsoids, 4); ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->map_tag_max, 8); @@ -4561,10 +4552,10 @@ TEST_F(AtomStyleTest, full_ellipsoid) TEST_F(AtomStyleTest, property_atom) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("atom_modify map array"); command("fix Properties all property/atom i_one d_two mol d_three q rmass ghost yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); AtomState expected; expected.atom_style = "atomic"; @@ -4596,7 +4587,7 @@ TEST_F(AtomStyleTest, property_atom) expected.nextra_border_max = 1; ASSERT_ATOM_STATE_EQ(lmp->atom, expected); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("create_box 2 box"); command("create_atoms 1 single -2.0 2.0 0.1"); command("create_atoms 1 single -2.0 -2.0 -0.1"); @@ -4623,7 +4614,7 @@ TEST_F(AtomStyleTest, property_atom) command("set atom 3 d_three 0.5"); command("set atom 4 d_three 2.0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); expected.natoms = 4; expected.nlocal = 4; expected.map_tag_max = 4; @@ -4637,7 +4628,7 @@ TEST_F(AtomStyleTest, property_atom) ASSERT_NE(lmp->atom->nmax, -1); ASSERT_NE(lmp->atom->rmass, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("write_data test_atom_styles.data nocoeff"); command("clear"); @@ -4648,7 +4639,7 @@ TEST_F(AtomStyleTest, property_atom) command("fix props all property/atom i_one d_two mol d_three q rmass ghost yes"); command("read_data test_atom_styles.data fix props NULL Properties"); command("pair_coeff * *"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); ASSERT_NE(lmp->atom->avec, nullptr); ASSERT_EQ(lmp->atom->natoms, 4); @@ -4726,7 +4717,7 @@ TEST_F(AtomStyleTest, property_atom) EXPECT_NEAR(three[GETIDX(3)], 0.5, EPSILON); EXPECT_NEAR(three[GETIDX(4)], 2.0, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("pair_coeff * *"); command("group two id 2:4:2"); command("delete_atoms group two compress no"); @@ -4735,7 +4726,7 @@ TEST_F(AtomStyleTest, property_atom) ASSERT_THAT(std::string(lmp->atom->atom_style), Eq("atomic")); command("read_restart test_atom_styles.restart"); command("fix props all property/atom i_one d_two mol d_three q rmass ghost yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); expected.natoms = 2; expected.nlocal = 2; expected.nghost = 0; @@ -4773,10 +4764,10 @@ TEST_F(AtomStyleTest, property_atom) EXPECT_NEAR(three[GETIDX(1)], -2.5, EPSILON); EXPECT_NEAR(three[GETIDX(3)], 0.5, EPSILON); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("reset_atom_ids"); command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->atom->map_tag_max, 2); q = lmp->atom->q; EXPECT_NEAR(q[GETIDX(1)], -0.5, EPSILON); diff --git a/unittest/formats/test_dump_atom.cpp b/unittest/formats/test_dump_atom.cpp index 39cefdccea..46c6b7dfa7 100644 --- a/unittest/formats/test_dump_atom.cpp +++ b/unittest/formats/test_dump_atom.cpp @@ -32,14 +32,14 @@ class DumpAtomTest : public MeltTest { public: void enable_triclinic() { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); if (!dump_modify_options.empty()) { @@ -47,13 +47,13 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void generate_text_and_binary_dump(std::string text_file, std::string binary_file, std::string dump_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); command(fmt::format("dump id1 all {} 1 {}", dump_style, binary_file)); @@ -63,15 +63,15 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } std::string convert_binary_to_text(std::string binary_file) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file); system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); return fmt::format("{}.txt", binary_file); } }; @@ -504,27 +504,27 @@ TEST_F(DumpAtomTest, per_processor_multi_file_run1) TEST_F(DumpAtomTest, dump_modify_scale_invalid) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dump id all atom 1 dump.txt"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id scale true");); } TEST_F(DumpAtomTest, dump_modify_image_invalid) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dump id all atom 1 dump.txt"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id image true");); } TEST_F(DumpAtomTest, dump_modify_invalid) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("dump id all atom 1 dump.txt"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id true");); } @@ -534,12 +534,12 @@ TEST_F(DumpAtomTest, write_dump) auto reference = "dump_ref_run0.melt"; auto dump_file = "write_dump_atom_run0.melt"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all atom 1 {}", reference)); command("dump_modify id scale no units yes"); command("run 0"); command("write_dump all atom write_dump_atom_run*.melt modify scale no units yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_FILE_EXISTS(reference); ASSERT_FILE_EXISTS(dump_file); @@ -556,12 +556,12 @@ TEST_F(DumpAtomTest, binary_write_dump) auto reference = "dump_run0.melt.bin"; auto dump_file = "write_dump_atom_run0_p0.melt.bin"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all atom 1 {}", reference)); command("dump_modify id scale no units yes"); command("run 0"); command("write_dump all atom write_dump_atom_run*_p%.melt.bin modify scale no units yes"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); ASSERT_FILE_EXISTS(reference); ASSERT_FILE_EXISTS(dump_file); diff --git a/unittest/formats/test_dump_atom_compressed.cpp b/unittest/formats/test_dump_atom_compressed.cpp index ed591184c3..5a519e06a1 100644 --- a/unittest/formats/test_dump_atom_compressed.cpp +++ b/unittest/formats/test_dump_atom_compressed.cpp @@ -340,9 +340,9 @@ TEST_F(DumpAtomCompressTest, compressed_modify_bad_param) { if (compression_style != "atom/gz") GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt"))); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -353,9 +353,9 @@ TEST_F(DumpAtomCompressTest, compressed_modify_multi_bad_param) { if (compression_style != "atom/gz") GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt"))); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); diff --git a/unittest/formats/test_dump_cfg.cpp b/unittest/formats/test_dump_cfg.cpp index 327a9caca7..b8f879de6f 100644 --- a/unittest/formats/test_dump_cfg.cpp +++ b/unittest/formats/test_dump_cfg.cpp @@ -30,7 +30,7 @@ public: void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); if (!dump_modify_options.empty()) { @@ -38,7 +38,7 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } }; @@ -54,9 +54,9 @@ TEST_F(DumpCfgTest, require_multifile) auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz xu yu zu xsu ysu zsu vx vy vz fx fy fz"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all cfg 1 {} {}", dump_file, fields)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*Dump cfg requires one snapshot per file.*", command("run 0");); } diff --git a/unittest/formats/test_dump_cfg_compressed.cpp b/unittest/formats/test_dump_cfg_compressed.cpp index 834a71db70..20f902091b 100644 --- a/unittest/formats/test_dump_cfg_compressed.cpp +++ b/unittest/formats/test_dump_cfg_compressed.cpp @@ -230,9 +230,9 @@ TEST_F(DumpCfgCompressTest, compressed_modify_bad_param) if (compression_style != "cfg/gz") GTEST_SKIP(); auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.cfg"), fields)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -244,9 +244,9 @@ TEST_F(DumpCfgCompressTest, compressed_modify_multi_bad_param) if (compression_style != "cfg/gz") GTEST_SKIP(); auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.cfg"), fields)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); diff --git a/unittest/formats/test_dump_custom.cpp b/unittest/formats/test_dump_custom.cpp index f2d7935426..b90d77e966 100644 --- a/unittest/formats/test_dump_custom.cpp +++ b/unittest/formats/test_dump_custom.cpp @@ -30,15 +30,15 @@ class DumpCustomTest : public MeltTest { public: void enable_triclinic() { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); if (!dump_modify_options.empty()) { @@ -46,14 +46,14 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void generate_text_and_binary_dump(std::string text_file, std::string binary_file, std::string fields, std::string dump_modify_options, int ntimesteps) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); command(fmt::format("dump id1 all {} 1 {} {}", dump_style, binary_file, fields)); @@ -63,15 +63,15 @@ public: } command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } std::string convert_binary_to_text(std::string binary_file) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file); system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); return fmt::format("{}.txt", binary_file); } }; @@ -113,9 +113,9 @@ TEST_F(DumpCustomTest, thresh_run0) TEST_F(DumpCustomTest, compute_run0) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("compute comp all property/atom x y z"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto dump_file = "dump_custom_compute_run0.melt"; auto fields = "id type x y z c_comp[1] c_comp[2] c_comp[3]"; @@ -134,9 +134,9 @@ TEST_F(DumpCustomTest, compute_run0) TEST_F(DumpCustomTest, fix_run0) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("fix numdiff all numdiff 1 0.0001"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto dump_file = "dump_custom_compute_run0.melt"; auto fields = "id x y z f_numdiff[1] f_numdiff[2] f_numdiff[3]"; @@ -155,10 +155,10 @@ TEST_F(DumpCustomTest, fix_run0) TEST_F(DumpCustomTest, custom_run0) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("fix prop all property/atom i_flag1 d_flag2"); command("compute 1 all property/atom i_flag1 d_flag2"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto dump_file = "dump_custom_custom_run0.melt"; auto fields = "id x y z i_flag1 d_flag2"; @@ -242,10 +242,10 @@ TEST_F(DumpCustomTest, binary_triclinic_run1) TEST_F(DumpCustomTest, with_variable_run1) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("compute 1 all property/atom proc"); command("variable p atom (c_1%10)+1"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto dump_file = "dump_custom_with_variable_run1.melt"; auto fields = "id type x y z v_p"; diff --git a/unittest/formats/test_dump_local_compressed.cpp b/unittest/formats/test_dump_local_compressed.cpp index 20f90984a1..95656071fc 100644 --- a/unittest/formats/test_dump_local_compressed.cpp +++ b/unittest/formats/test_dump_local_compressed.cpp @@ -31,9 +31,9 @@ public: void SetUp() override { CompressedDumpTest::SetUp(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("compute comp all pair/local dist eng"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } }; @@ -205,9 +205,9 @@ TEST_F(DumpLocalCompressTest, compressed_modify_bad_param) auto fields = "index c_comp[1]"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.local"), fields)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -220,9 +220,9 @@ TEST_F(DumpLocalCompressTest, compressed_modify_multi_bad_param) auto fields = "index c_comp[1]"; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.local"), fields)); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); diff --git a/unittest/formats/test_dump_xyz_compressed.cpp b/unittest/formats/test_dump_xyz_compressed.cpp index f80201872c..dad7911b4c 100644 --- a/unittest/formats/test_dump_xyz_compressed.cpp +++ b/unittest/formats/test_dump_xyz_compressed.cpp @@ -191,9 +191,9 @@ TEST_F(DumpXYZCompressTest, compressed_modify_bad_param) { if (compression_style != "xyz/gz") GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.xyz"))); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 compression_level 12"); @@ -204,9 +204,9 @@ TEST_F(DumpXYZCompressTest, compressed_modify_multi_bad_param) { if (compression_style != "xyz/gz") GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.xyz"))); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", command("dump_modify id1 pad 3 compression_level 12"); diff --git a/unittest/formats/test_eim_potential_file_reader.cpp b/unittest/formats/test_eim_potential_file_reader.cpp index 9992fb8662..26f2795a85 100644 --- a/unittest/formats/test_eim_potential_file_reader.cpp +++ b/unittest/formats/test_eim_potential_file_reader.cpp @@ -18,6 +18,7 @@ #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -28,28 +29,23 @@ using utils::split_words; // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -class EIMPotentialFileReaderTest : public ::testing::Test { +class EIMPotentialFileReaderTest : public LAMMPSTest { protected: - LAMMPS *lmp; PairEIM::Setfl setfl; static const int nelements = 9; void SetUp() override { - const char *args[] = { - "PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - lmp->input->one("units metal"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "EIMPotentialFileReaderTest"; + LAMMPSTest::SetUp(); ASSERT_NE(lmp, nullptr); + + BEGIN_HIDE_OUTPUT(); + command("units metal"); + END_HIDE_OUTPUT(); // check if the prerequisite eim pair style is available - Info *info = new Info(lmp); ASSERT_TRUE(info->has_style("pair", "eim")); - delete info; int npair = nelements * (nelements + 1) / 2; setfl.ielement = new int[nelements]; @@ -99,17 +95,15 @@ protected: delete[] setfl.rs; delete[] setfl.tp; - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); + LAMMPSTest::TearDown(); } }; TEST_F(EIMPotentialFileReaderTest, global_line) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); EIMPotentialFileReader reader(lmp, "ffield.eim"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); reader.get_global(&setfl); ASSERT_DOUBLE_EQ(setfl.division, 2.0); @@ -119,9 +113,9 @@ TEST_F(EIMPotentialFileReaderTest, global_line) TEST_F(EIMPotentialFileReaderTest, element_line_sequential) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); EIMPotentialFileReader reader(lmp, "ffield.eim"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); reader.get_element(&setfl, 0, "Li"); ASSERT_EQ(setfl.ielement[0], 3); @@ -144,9 +138,9 @@ TEST_F(EIMPotentialFileReaderTest, element_line_sequential) TEST_F(EIMPotentialFileReaderTest, element_line_random) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); EIMPotentialFileReader reader(lmp, "ffield.eim"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); reader.get_element(&setfl, 0, "Id"); ASSERT_EQ(setfl.ielement[0], 53); @@ -160,9 +154,9 @@ TEST_F(EIMPotentialFileReaderTest, element_line_random) TEST_F(EIMPotentialFileReaderTest, pair_line) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); EIMPotentialFileReader reader(lmp, "ffield.eim"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); reader.get_pair(&setfl, 0, "Li", "Li"); ASSERT_DOUBLE_EQ(setfl.rcutphiA[0], 6.0490e+00); @@ -183,9 +177,9 @@ TEST_F(EIMPotentialFileReaderTest, pair_line) TEST_F(EIMPotentialFileReaderTest, pair_identical) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); EIMPotentialFileReader reader(lmp, "ffield.eim"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); reader.get_pair(&setfl, 0, "Li", "Na"); reader.get_pair(&setfl, 1, "Na", "Li"); diff --git a/unittest/formats/test_file_operations.cpp b/unittest/formats/test_file_operations.cpp index cf85d810df..80082bc53c 100644 --- a/unittest/formats/test_file_operations.cpp +++ b/unittest/formats/test_file_operations.cpp @@ -17,6 +17,7 @@ #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -31,43 +32,17 @@ using utils::sfgets; using utils::sfread; using utils::split_words; -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } - // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -class FileOperationsTest : public ::testing::Test { +class FileOperationsTest : public LAMMPSTest { protected: - LAMMPS *lmp; - void SetUp() override { - const char *args[] = {"FileOperationsTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "FileOperationsTest"; + LAMMPSTest::SetUp(); ASSERT_NE(lmp, nullptr); + FILE *fp = fopen("safe_file_read_test.txt", "wb"); ASSERT_NE(fp, nullptr); fputs("one line\n", fp); @@ -79,13 +54,9 @@ protected: void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); + LAMMPSTest::TearDown(); remove("safe_file_read_test.txt"); } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; #define MAX_BUF_SIZE 128 @@ -179,7 +150,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/formats/test_image_flags.cpp b/unittest/formats/test_image_flags.cpp index 6b3a333328..63d85789e6 100644 --- a/unittest/formats/test_image_flags.cpp +++ b/unittest/formats/test_image_flags.cpp @@ -15,6 +15,7 @@ #include "input.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -28,20 +29,14 @@ using LAMMPS_NS::utils::split_words; namespace LAMMPS_NS { using ::testing::Eq; -class ImageFlagsTest : public ::testing::Test { +class ImageFlagsTest : public LAMMPSTest { protected: - LAMMPS *lmp; - void SetUp() override { - const char *args[] = {"ImageFlagsTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "ImageFlagsTest"; + LAMMPSTest::SetUp(); ASSERT_NE(lmp, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units real"); command("dimension 3"); command("region box block -2 2 -2 2 -2 2"); @@ -54,18 +49,14 @@ protected: command("set atom 1 image -1 2 3"); command("set atom 2 image -2 1 -1"); command("write_data test_image_flags.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); + LAMMPSTest::TearDown(); remove("test_image_flags.data"); } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(ImageFlagsTest, change_box) @@ -87,9 +78,9 @@ TEST_F(ImageFlagsTest, change_box) ASSERT_EQ(imy, 1); ASSERT_EQ(imz, -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("change_box all boundary f p p"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); image = lmp->atom->image; imx = (image[0] & IMGMASK) - IMGMAX; @@ -108,9 +99,9 @@ TEST_F(ImageFlagsTest, change_box) ASSERT_EQ(imy, 1); ASSERT_EQ(imz, -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("change_box all boundary f s p"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); image = lmp->atom->image; imx = (image[0] & IMGMASK) - IMGMAX; @@ -129,9 +120,9 @@ TEST_F(ImageFlagsTest, change_box) ASSERT_EQ(imy, 0); ASSERT_EQ(imz, -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("change_box all boundary p p m"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); image = lmp->atom->image; imx = (image[0] & IMGMASK) - IMGMAX; @@ -153,14 +144,14 @@ TEST_F(ImageFlagsTest, change_box) TEST_F(ImageFlagsTest, read_data) { - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("dimension 3"); command("boundary p p p"); command("pair_style zero 2.0"); command("read_data test_image_flags.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); auto image = lmp->atom->image; int imx = (image[0] & IMGMASK) - IMGMAX; @@ -179,14 +170,14 @@ TEST_F(ImageFlagsTest, read_data) ASSERT_EQ(imy, 1); ASSERT_EQ(imz, -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("dimension 3"); command("boundary f p p"); command("pair_style zero 2.0"); command("read_data test_image_flags.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); image = lmp->atom->image; imx = (image[0] & IMGMASK) - IMGMAX; @@ -205,14 +196,14 @@ TEST_F(ImageFlagsTest, read_data) ASSERT_EQ(imy, 1); ASSERT_EQ(imz, -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("dimension 3"); command("boundary p s p"); command("pair_style zero 2.0"); command("read_data test_image_flags.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); image = lmp->atom->image; imx = (image[0] & IMGMASK) - IMGMAX; @@ -231,14 +222,14 @@ TEST_F(ImageFlagsTest, read_data) ASSERT_EQ(imy, 0); ASSERT_EQ(imz, -1); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("dimension 3"); command("boundary p p m"); command("pair_style zero 2.0"); command("read_data test_image_flags.data"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); image = lmp->atom->image; imx = (image[0] & IMGMASK) - IMGMAX; diff --git a/unittest/formats/test_molecule_file.cpp b/unittest/formats/test_molecule_file.cpp index 204a1bd061..4bcf375dff 100644 --- a/unittest/formats/test_molecule_file.cpp +++ b/unittest/formats/test_molecule_file.cpp @@ -19,6 +19,7 @@ #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -33,26 +34,6 @@ using utils::split_words; #define test_name test_info_->name() -#if defined(OMPI_MAJOR_VERSION) -const bool have_openmpi = true; -#else -const bool have_openmpi = false; -#endif - -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } else { \ - if (!have_openmpi) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, MatchesRegex(errmsg)); \ - } \ - } static void create_molecule_files() { @@ -96,27 +77,21 @@ static void create_molecule_files() // whether to print verbose output (i.e. not capturing LAMMPS screen output). bool verbose = false; -class MoleculeFileTest : public ::testing::Test { +class MoleculeFileTest : public LAMMPSTest { protected: - LAMMPS *lmp; - void SetUp() override { - const char *args[] = {"MoleculeFileTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - create_molecule_files(); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "MoleculeFileTest"; + LAMMPSTest::SetUp(); ASSERT_NE(lmp, nullptr); + BEGIN_HIDE_OUTPUT(); + create_molecule_files(); + END_HIDE_OUTPUT(); } void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); + LAMMPSTest::TearDown(); remove("h2o.mol"); remove("co2.mol"); } @@ -128,11 +103,9 @@ protected: fputs(content.c_str(), fp); fclose(fp); - lmp->input->one(fmt::format("molecule {} {} {}", name, file, args)); + command(fmt::format("molecule {} {} {}", name, file, args)); remove(file.c_str()); } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(MoleculeFileTest, nofile) @@ -292,7 +265,7 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (have_openmpi && !LAMMPS_NS::Info::has_exceptions()) + if (Info::get_mpi_vendor() == "Open MPI" && !LAMMPS_NS::Info::has_exceptions()) std::cout << "Warning: using OpenMPI without exceptions. " "Death tests will be skipped\n"; diff --git a/unittest/formats/test_pair_unit_convert.cpp b/unittest/formats/test_pair_unit_convert.cpp index f0c2f0d031..bdd66f67a6 100644 --- a/unittest/formats/test_pair_unit_convert.cpp +++ b/unittest/formats/test_pair_unit_convert.cpp @@ -20,6 +20,7 @@ #include "thermo.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "../testing/core.h" #include #include @@ -42,23 +43,17 @@ const double p_convert = 1.01325; // of data in update.cpp. could be 1.0e-12 const double rel_error = 5.0e-7; -class PairUnitConvertTest : public ::testing::Test { +class PairUnitConvertTest : public LAMMPSTest { protected: - LAMMPS *lmp; - Info *info; double fold[4][3]; void SetUp() override { - const char *args[] = {"PairUnitConvertTest", "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); - if (!verbose) ::testing::internal::GetCapturedStdout(); + testbinary = "PairUnitConvertTest"; + LAMMPSTest::SetUp(); ASSERT_NE(lmp, nullptr); - if (!verbose) ::testing::internal::CaptureStdout(); - info = new Info(lmp); + + BEGIN_HIDE_OUTPUT(); command("units metal"); command("dimension 3"); command("region box block -4 4 -4 4 -4 4"); @@ -72,19 +67,14 @@ protected: command("mass * 1.0"); command("write_data test_pair_unit_convert.data nocoeff"); command("clear"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); } void TearDown() override { - if (!verbose) ::testing::internal::CaptureStdout(); - delete info; - delete lmp; - if (!verbose) ::testing::internal::GetCapturedStdout(); + LAMMPSTest::TearDown(); remove("test_pair_unit_convert.data"); } - - void command(const std::string &cmd) { lmp->input->one(cmd); } }; TEST_F(PairUnitConvertTest, zero) @@ -92,13 +82,13 @@ TEST_F(PairUnitConvertTest, zero) // check if the prerequisite pair style is available if (!info->has_style("pair", "zero")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style zero 6.0"); command("pair_coeff * *"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -109,14 +99,14 @@ TEST_F(PairUnitConvertTest, zero) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style zero 6.0"); command("pair_coeff * *"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -135,7 +125,7 @@ TEST_F(PairUnitConvertTest, lj_cut) // check if the prerequisite pair style is available if (!info->has_style("pair", "lj/cut")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style lj/cut 6.0"); @@ -145,7 +135,7 @@ TEST_F(PairUnitConvertTest, lj_cut) command("pair_write 1 2 1000 r 0.1 6.0 test.table.metal lj_1_2"); command("pair_write 2 2 1000 r 0.1 6.0 test.table.metal lj_2_2"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -156,7 +146,7 @@ TEST_F(PairUnitConvertTest, lj_cut) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); @@ -167,7 +157,7 @@ TEST_F(PairUnitConvertTest, lj_cut) command("pair_write 1 2 1000 r 0.1 6.0 test.table.real lj_1_2"); command("pair_write 2 2 1000 r 0.1 6.0 test.table.real lj_2_2"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -186,13 +176,13 @@ TEST_F(PairUnitConvertTest, eam) // check if the prerequisite pair style is available if (!info->has_style("pair", "eam")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style eam"); command("pair_coeff * * Cu_u3.eam"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -203,14 +193,14 @@ TEST_F(PairUnitConvertTest, eam) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style eam"); command("pair_coeff * * Cu_u3.eam"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -229,13 +219,13 @@ TEST_F(PairUnitConvertTest, eam_alloy) // check if the prerequisite pair style is available if (!info->has_style("pair", "eam/alloy")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style eam/alloy"); command("pair_coeff * * AlCu.eam.alloy Al Cu"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -246,14 +236,14 @@ TEST_F(PairUnitConvertTest, eam_alloy) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style eam/alloy"); command("pair_coeff * * AlCu.eam.alloy Al Cu"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -272,13 +262,13 @@ TEST_F(PairUnitConvertTest, eam_fs) // check if the prerequisite pair style is available if (!info->has_style("pair", "eam/fs")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style eam/fs"); command("pair_coeff * * FeP_mm.eam.fs Fe P"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -289,14 +279,14 @@ TEST_F(PairUnitConvertTest, eam_fs) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style eam/fs"); command("pair_coeff * * FeP_mm.eam.fs Fe P"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -315,13 +305,13 @@ TEST_F(PairUnitConvertTest, eam_cd) // check if the prerequisite pair style is available if (!info->has_style("pair", "eam/cd")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style eam/cd"); command("pair_coeff * * FeCr.cdeam Cr Fe"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -332,14 +322,14 @@ TEST_F(PairUnitConvertTest, eam_cd) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style eam/cd"); command("pair_coeff * * FeCr.cdeam Cr Fe"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -358,13 +348,13 @@ TEST_F(PairUnitConvertTest, eim) // check if the prerequisite pair style is available if (!info->has_style("pair", "eim")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style eim"); command("pair_coeff * * Na Cl ffield.eim Na Cl"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -375,14 +365,14 @@ TEST_F(PairUnitConvertTest, eim) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style eim"); command("pair_coeff * * Na Cl ffield.eim Na Cl"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -401,13 +391,13 @@ TEST_F(PairUnitConvertTest, gw) // check if the prerequisite pair style is available if (!info->has_style("pair", "gw")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style gw"); command("pair_coeff * * SiC.gw Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -418,14 +408,14 @@ TEST_F(PairUnitConvertTest, gw) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style gw"); command("pair_coeff * * SiC.gw Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -444,13 +434,13 @@ TEST_F(PairUnitConvertTest, gw_zbl) // check if the prerequisite pair style is available if (!info->has_style("pair", "gw/zbl")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style gw/zbl"); command("pair_coeff * * SiC.gw.zbl Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -461,14 +451,14 @@ TEST_F(PairUnitConvertTest, gw_zbl) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style gw/zbl"); command("pair_coeff * * SiC.gw.zbl Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -487,13 +477,13 @@ TEST_F(PairUnitConvertTest, nb3b_harmonic) // check if the prerequisite pair style is available if (!info->has_style("pair", "nb3b/harmonic")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style nb3b/harmonic"); command("pair_coeff * * MOH.nb3b.harmonic M O"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -504,14 +494,14 @@ TEST_F(PairUnitConvertTest, nb3b_harmonic) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style nb3b/harmonic"); command("pair_coeff * * MOH.nb3b.harmonic M O"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -530,13 +520,13 @@ TEST_F(PairUnitConvertTest, sw) // check if the prerequisite pair style is available if (!info->has_style("pair", "sw")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style sw"); command("pair_coeff * * GaN.sw Ga N"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -547,14 +537,14 @@ TEST_F(PairUnitConvertTest, sw) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style sw"); command("pair_coeff * * GaN.sw Ga N"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -573,7 +563,7 @@ TEST_F(PairUnitConvertTest, table_metal2real) // check if the prerequisite pair style is available if (!info->has_style("pair", "table")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style table linear 1000"); @@ -581,7 +571,7 @@ TEST_F(PairUnitConvertTest, table_metal2real) command("pair_coeff 1 2 test.table.metal lj_1_2"); command("pair_coeff 2 2 test.table.metal lj_2_2"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -592,7 +582,7 @@ TEST_F(PairUnitConvertTest, table_metal2real) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); @@ -601,7 +591,7 @@ TEST_F(PairUnitConvertTest, table_metal2real) command("pair_coeff 1 2 test.table.metal lj_1_2"); command("pair_coeff 2 2 test.table.metal lj_2_2"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -620,7 +610,7 @@ TEST_F(PairUnitConvertTest, table_real2metal) // check if the prerequisite pair style is available if (!info->has_style("pair", "table")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style table linear 1000"); @@ -628,7 +618,7 @@ TEST_F(PairUnitConvertTest, table_real2metal) command("pair_coeff 1 2 test.table.real lj_1_2"); command("pair_coeff 2 2 test.table.real lj_2_2"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -639,7 +629,7 @@ TEST_F(PairUnitConvertTest, table_real2metal) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units metal"); command("read_data test_pair_unit_convert.data"); @@ -648,7 +638,7 @@ TEST_F(PairUnitConvertTest, table_real2metal) command("pair_coeff 1 2 test.table.real lj_1_2"); command("pair_coeff 2 2 test.table.real lj_2_2"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -667,13 +657,13 @@ TEST_F(PairUnitConvertTest, tersoff) // check if the prerequisite pair style is available if (!info->has_style("pair", "tersoff")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff"); command("pair_coeff * * SiC.tersoff Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -684,14 +674,14 @@ TEST_F(PairUnitConvertTest, tersoff) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff"); command("pair_coeff * * SiC.tersoff Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -710,13 +700,13 @@ TEST_F(PairUnitConvertTest, tersoff_mod) // check if the prerequisite pair style is available if (!info->has_style("pair", "tersoff/mod")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/mod"); command("pair_coeff * * Si.tersoff.mod Si Si"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -727,14 +717,14 @@ TEST_F(PairUnitConvertTest, tersoff_mod) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/mod"); command("pair_coeff * * Si.tersoff.mod Si Si"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -753,13 +743,13 @@ TEST_F(PairUnitConvertTest, tersoff_mod_c) // check if the prerequisite pair style is available if (!info->has_style("pair", "tersoff/mod/c")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/mod/c"); command("pair_coeff * * Si.tersoff.modc Si Si"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -770,14 +760,14 @@ TEST_F(PairUnitConvertTest, tersoff_mod_c) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/mod/c"); command("pair_coeff * * Si.tersoff.modc Si Si"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -796,13 +786,13 @@ TEST_F(PairUnitConvertTest, tersoff_table) // check if the prerequisite pair style is available if (!info->has_style("pair", "tersoff/table")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/table"); command("pair_coeff * * SiC.tersoff Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -813,14 +803,14 @@ TEST_F(PairUnitConvertTest, tersoff_table) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/table"); command("pair_coeff * * SiC.tersoff Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -839,13 +829,13 @@ TEST_F(PairUnitConvertTest, tersoff_zbl) // check if the prerequisite pair style is available if (!info->has_style("pair", "tersoff/zbl")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/zbl"); command("pair_coeff * * SiC.tersoff.zbl Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -856,14 +846,14 @@ TEST_F(PairUnitConvertTest, tersoff_zbl) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/zbl"); command("pair_coeff * * SiC.tersoff.zbl Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -882,14 +872,14 @@ TEST_F(PairUnitConvertTest, tersoff_zbl_omp) // check if the prerequisite pair style is available if (!info->has_style("pair", "tersoff/zbl/omp")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("package omp 4"); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style tersoff/zbl/omp"); command("pair_coeff * * SiC.tersoff.zbl Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -900,7 +890,7 @@ TEST_F(PairUnitConvertTest, tersoff_zbl_omp) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("package omp 4"); command("units real"); @@ -908,7 +898,7 @@ TEST_F(PairUnitConvertTest, tersoff_zbl_omp) command("pair_style tersoff/zbl/omp"); command("pair_coeff * * SiC.tersoff.zbl Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); @@ -927,13 +917,13 @@ TEST_F(PairUnitConvertTest, vashishta) // check if the prerequisite pair style is available if (!info->has_style("pair", "vashishta")) GTEST_SKIP(); - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("units metal"); command("read_data test_pair_unit_convert.data"); command("pair_style vashishta"); command("pair_coeff * * SiC.vashishta Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); // copy pressure, energy, and force from first step double pold; @@ -944,14 +934,14 @@ TEST_F(PairUnitConvertTest, vashishta) for (int j = 0; j < 3; ++j) fold[i][j] = f[i][j]; - if (!verbose) ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("clear"); command("units real"); command("read_data test_pair_unit_convert.data"); command("pair_style vashishta"); command("pair_coeff * * SiC.vashishta Si C"); command("run 0 post no"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + END_HIDE_OUTPUT(); double pnew; lmp->output->thermo->evaluate_keyword("press", &pnew); diff --git a/unittest/testing/core.h b/unittest/testing/core.h index 01c5872579..deab845573 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -22,6 +22,8 @@ #include "exceptions.h" #include +#include +#include using namespace LAMMPS_NS; @@ -103,20 +105,31 @@ public: } protected: - const char *testbinary = "LAMMPSTest"; + std::string testbinary = "LAMMPSTest"; + std::vector args = {"-log", "none", "-echo", "screen", "-nocite"}; LAMMPS *lmp; Info *info; void SetUp() override { - const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args) / sizeof(char *); + int argc = args.size() + 1; + char ** argv = new char*[argc]; + argv[0] = utils::strdup(testbinary); + for(int i = 1; i < argc; i++) { + argv[i] = utils::strdup(args[i-1]); + } + HIDE_OUTPUT([&] { lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); info = new Info(lmp); }); InitSystem(); + + for(int i = 0; i < argc; i++) { + delete [] argv[i]; + argv[i] = nullptr; + } + delete [] argv; } virtual void InitSystem() {} From 6f986eee4eb5ef72c46fb1d8a0c0dc00f6918712 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 29 Mar 2021 15:01:29 -0400 Subject: [PATCH 179/257] Add missing changes --- unittest/commands/test_lattice_region.cpp | 10 +++----- unittest/formats/test_file_operations.cpp | 8 +++--- unittest/formats/test_molecule_file.cpp | 30 +++++++++-------------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/unittest/commands/test_lattice_region.cpp b/unittest/commands/test_lattice_region.cpp index eb6d577652..ae38f3a7f5 100644 --- a/unittest/commands/test_lattice_region.cpp +++ b/unittest/commands/test_lattice_region.cpp @@ -81,10 +81,9 @@ TEST_F(LatticeRegionTest, lattice_none) TEST_F(LatticeRegionTest, lattice_sc) { - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("lattice sc 1.0 spacing 1.5 2.0 3.0"); - auto output = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << output; + auto output = END_CAPTURE_OUTPUT(); ASSERT_THAT(output, MatchesRegex(".*Lattice spacing in x,y,z = 1.50* 2.0* 3.0*.*")); auto lattice = lmp->domain->lattice; @@ -92,10 +91,9 @@ TEST_F(LatticeRegionTest, lattice_sc) ASSERT_EQ(lattice->ylattice, 2.0); ASSERT_EQ(lattice->zlattice, 3.0); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("lattice sc 2.0"); - output = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << output; + output = END_CAPTURE_OUTPUT(); ASSERT_THAT(output, MatchesRegex(".*Lattice spacing in x,y,z = 2.0* 2.0* 2.0*.*")); lattice = lmp->domain->lattice; diff --git a/unittest/formats/test_file_operations.cpp b/unittest/formats/test_file_operations.cpp index 80082bc53c..700990fb72 100644 --- a/unittest/formats/test_file_operations.cpp +++ b/unittest/formats/test_file_operations.cpp @@ -127,15 +127,15 @@ TEST_F(FileOperationsTest, safe_fread) TEST_F(FileOperationsTest, logmesg) { char buf[8]; - ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); command("echo none"); - ::testing::internal::GetCapturedStdout(); - ::testing::internal::CaptureStdout(); + END_HIDE_OUTPUT(); + BEGIN_CAPTURE_OUTPUT(); utils::logmesg(lmp, "one\n"); command("log test_logmesg.log"); utils::logmesg(lmp, "two\n"); command("log none"); - std::string out = ::testing::internal::GetCapturedStdout(); + std::string out = END_CAPTURE_OUTPUT(); memset(buf, 0, 8); FILE *fp = fopen("test_logmesg.log", "r"); fread(buf, 1, 8, fp); diff --git a/unittest/formats/test_molecule_file.cpp b/unittest/formats/test_molecule_file.cpp index 4bcf375dff..9928ec4b7c 100644 --- a/unittest/formats/test_molecule_file.cpp +++ b/unittest/formats/test_molecule_file.cpp @@ -174,32 +174,29 @@ TEST_F(MoleculeFileTest, nospecial) TEST_F(MoleculeFileTest, minimal) { - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); run_mol_cmd(test_name, "", "Comment\n1 atoms\n\n Coords\n\n 1 0.0 0.0 0.0\n"); - auto output = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << output; + auto output = END_CAPTURE_OUTPUT(); ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*1 molecules.*1 atoms.*0 bonds.*")); } TEST_F(MoleculeFileTest, twomols) { - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); run_mol_cmd(test_name, "", "Comment\n2 atoms\n\n" " Coords\n\n 1 0.0 0.0 0.0\n 2 0.0 0.0 1.0\n" " Molecules\n\n 1 1\n 2 2\n\n Types\n\n 1 1\n 2 2\n\n"); - auto output = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << output; + auto output = END_CAPTURE_OUTPUT(); ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*2 molecules.*2 atoms " "with max type 2.*0 bonds.*")); } TEST_F(MoleculeFileTest, twofiles) { - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); - auto output = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << output; + auto output = END_CAPTURE_OUTPUT(); ASSERT_THAT(output, MatchesRegex(".*Read molecule template twomols:.*1 molecules.*3 atoms " "with max type 2.*2 bonds with max type 1.*" "1 angles with max type 1.*0 dihedrals.*" @@ -210,7 +207,7 @@ TEST_F(MoleculeFileTest, twofiles) TEST_F(MoleculeFileTest, bonds) { - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("atom_style bond"); command("region box block 0 1 0 1 0 1"); command("create_box 2 box bond/types 2 extra/bond/per/atom 2 " @@ -232,19 +229,17 @@ TEST_F(MoleculeFileTest, bonds) " Bonds\n\n" " 1 1 1 2\n" " 2 2 1 3\n\n"); - auto output = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << output; + auto output = END_CAPTURE_OUTPUT(); ASSERT_THAT(output, MatchesRegex(".*Read molecule template.*1 molecules.*4 atoms.*type.*2.*" "2 bonds.*type.*2.*0 angles.*")); - ::testing::internal::CaptureStdout(); + BEGIN_CAPTURE_OUTPUT(); command("mass * 2.0"); command("create_atoms 0 single 0.5 0.5 0.5 mol bonds 67235"); - output = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << output; + output = END_CAPTURE_OUTPUT(); ASSERT_THAT(output, MatchesRegex(".*Created 4 atoms.*")); - ::testing::internal::CaptureStdout(); + BEGIN_HIDE_OUTPUT(); Molecule *mol = lmp->atom->molecules[0]; ASSERT_EQ(mol->natoms, 4); ASSERT_EQ(lmp->atom->natoms, 4); @@ -256,8 +251,7 @@ TEST_F(MoleculeFileTest, bonds) EXPECT_DOUBLE_EQ(mol->com[2], 0.5); EXPECT_DOUBLE_EQ(mol->maxextent, sqrt(2)); EXPECT_EQ(mol->comatom, 1); - output = ::testing::internal::GetCapturedStdout(); - if (verbose) std::cout << output; + END_HIDE_OUTPUT(); } int main(int argc, char **argv) From 2b11848fcca79cfc1ef1ffdbbb1e34f4d4833004 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 29 Mar 2021 15:26:57 -0400 Subject: [PATCH 180/257] bugfix from dan bolintineanu for issue reported on lammps-users by Deng Pan --- src/GRANULAR/pair_granular.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GRANULAR/pair_granular.cpp b/src/GRANULAR/pair_granular.cpp index cc210138eb..bcf262aa2c 100644 --- a/src/GRANULAR/pair_granular.cpp +++ b/src/GRANULAR/pair_granular.cpp @@ -446,9 +446,9 @@ void PairGranular::compute(int eflag, int vflag) if (tangential_model[itype][jtype] == TANGENTIAL_MINDLIN_FORCE || tangential_model[itype][jtype] == TANGENTIAL_MINDLIN_RESCALE_FORCE) - frameupdate = fabs(rsht) < EPSILON*Fscrit; + frameupdate = fabs(rsht) > EPSILON*Fscrit; else - frameupdate = fabs(rsht)*k_tangential < EPSILON*Fscrit; + frameupdate = fabs(rsht)*k_tangential > EPSILON*Fscrit; if (frameupdate) { shrmag = sqrt(history[0]*history[0] + history[1]*history[1] + history[2]*history[2]); @@ -568,7 +568,7 @@ void PairGranular::compute(int eflag, int vflag) if (historyupdate) { rolldotn = history[rhist0]*nx + history[rhist1]*ny + history[rhist2]*nz; - frameupdate = fabs(rolldotn)*k_roll < EPSILON*Frcrit; + frameupdate = fabs(rolldotn)*k_roll > EPSILON*Frcrit; if (frameupdate) { // rotate into tangential plane rollmag = sqrt(history[rhist0]*history[rhist0] + history[rhist1]*history[rhist1] + From 20e6174e59fab97366f89f9ea8a7280e5299027a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 29 Mar 2021 21:11:07 -0400 Subject: [PATCH 181/257] cannot use tokenizer for parse_args() as the search for commata must be away of parenthesis --- src/variable.cpp | 36 +++++++++++++++++++++------- src/variable.h | 3 ++- unittest/commands/test_variables.cpp | 7 ++++-- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/variable.cpp b/src/variable.cpp index 76a4b84f89..3bf88db55e 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -4690,23 +4690,43 @@ void Variable::atom_vector(char *word, Tree **tree, max allowed # of args = MAXFUNCARG ------------------------------------------------------------------------- */ -int Variable::parse_args(const std::string &str, char **args) +int Variable::parse_args(char *str, char **args) { + char *ptrnext; int narg = 0; - args[0] = nullptr; + char *ptr = str; - Tokenizer values(str,","); - - while (values.has_next() && narg < MAXFUNCARG) { - args[narg] = utils::strdup(values.next()); + while (ptr && narg < MAXFUNCARG) { + ptrnext = find_next_comma(ptr); + if (ptrnext) *ptrnext = '\0'; + args[narg] = utils::strdup(ptr); narg++; + ptr = ptrnext; + if (ptr) ptr++; } - if (values.has_next()) - error->all(FLERR,"Too many args in variable function"); + if (ptr) error->all(FLERR,"Too many args in variable function"); return narg; } +/* ---------------------------------------------------------------------- + find next comma in str + skip commas inside one or more nested parenthesis + only return ptr to comma at level 0, else nullptr if not found +------------------------------------------------------------------------- */ + +char *Variable::find_next_comma(char *str) +{ + int level = 0; + for (char *p = str; *p; ++p) { + if ('(' == *p) level++; + else if (')' == *p) level--; + else if (',' == *p && !level) return p; + } + return nullptr; +} + + /* ---------------------------------------------------------------------- helper routine for printing variable name with error message ------------------------------------------------------------------------- */ diff --git a/src/variable.h b/src/variable.h index a43e7f3ad7..da759ecf6a 100644 --- a/src/variable.h +++ b/src/variable.h @@ -126,7 +126,8 @@ class Variable : protected Pointers { Tree **, Tree **, int &, double *, int &); int is_atom_vector(char *); void atom_vector(char *, Tree **, Tree **, int &); - int parse_args(const std::string &, char **); + int parse_args(char *, char **); + char *find_next_comma(char *); void print_var_error(const std::string &, int, const std::string &, int, int global=1); void print_tree(Tree *, int); diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index d41ad52e57..eb533aee86 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -334,8 +334,9 @@ TEST_F(VariableTest, Functions) file_vars(); BEGIN_HIDE_OUTPUT(); + command("variable seed index 643532"); command("variable one index 1"); - command("variable two equal random(1,2,643532)"); + command("variable two equal random(1,2,v_seed)"); command("variable three equal atan2(v_one,1)"); command("variable four equal atan2()"); command("variable five equal sqrt(v_one+v_one)"); @@ -346,6 +347,7 @@ TEST_F(VariableTest, Functions) command("variable ten equal floor(1.85)+ceil(1.85)"); command("variable ten1 equal tan(v_eight/2.0)"); command("variable ten2 equal asin(-1.0)+acos(0.0)"); + command("variable ten3 equal floor(100*random(0.2,0.8,v_seed)+1)"); END_HIDE_OUTPUT(); ASSERT_GT(variable->compute_equal(variable->find("two")), 0.99); @@ -357,7 +359,8 @@ TEST_F(VariableTest, Functions) ASSERT_DOUBLE_EQ(variable->compute_equal(variable->find("nine")), 1); ASSERT_DOUBLE_EQ(variable->compute_equal(variable->find("ten")), 3); ASSERT_FLOAT_EQ(variable->compute_equal(variable->find("ten1")), 1); - ASSERT_DOUBLE_EQ(variable->compute_equal(variable->find("ten2")), 0); + ASSERT_GT(variable->compute_equal(variable->find("ten3")), 19); + ASSERT_LT(variable->compute_equal(variable->find("ten3")), 81); TEST_FAILURE(".*ERROR: Variable four: Invalid syntax in variable formula.*", command("print \"${four}\"");); From 41de02ee9dd48569456532bf875344d1846a6b60 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 29 Mar 2021 23:44:38 -0400 Subject: [PATCH 182/257] update granular howto --- doc/src/Howto_granular.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/src/Howto_granular.rst b/doc/src/Howto_granular.rst index c696d44249..70c2b2fbb7 100644 --- a/doc/src/Howto_granular.rst +++ b/doc/src/Howto_granular.rst @@ -18,12 +18,13 @@ This compute calculates rotational kinetic energy which can be :doc:`output with thermodynamic info `. -Use one of these 3 pair potentials, which compute forces and torques +Use one of these 4 pair potentials, which compute forces and torques between interacting pairs of particles: -* :doc:`pair_style ` gran/history -* :doc:`pair_style ` gran/no_history -* :doc:`pair_style ` gran/hertzian +* :doc:`pair_style gran/history ` +* :doc:`pair_style gran/no_history ` +* :doc:`pair_style gran/hertzian ` +* :doc:`pair_style granular ` These commands implement fix options specific to granular systems: @@ -31,6 +32,7 @@ These commands implement fix options specific to granular systems: * :doc:`fix pour ` * :doc:`fix viscous ` * :doc:`fix wall/gran ` +* :doc:`fix wall/gran/region ` The fix style *freeze* zeroes both the force and torque of frozen atoms, and should be used for granular system instead of the fix style From ea105a3c9a15d4958a46b079416d6dd10ca18407 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Mar 2021 07:36:22 -0400 Subject: [PATCH 183/257] fix typo --- doc/src/pair_dpd.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/pair_dpd.rst b/doc/src/pair_dpd.rst index d1d84407c4..62cf94786d 100644 --- a/doc/src/pair_dpd.rst +++ b/doc/src/pair_dpd.rst @@ -150,7 +150,7 @@ shifted to be 0.0 at the cutoff distance Rc. The :doc:`pair_modify ` table option is not relevant for these pair styles. -These pair style do not support the :doc:`pair_modify ` +These pair styles do not support the :doc:`pair_modify ` tail option for adding long-range tail corrections to energy and pressure. From 304156138347f16f77fcc15908ba9a9112cb822f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Mar 2021 07:36:53 -0400 Subject: [PATCH 184/257] add proper r-RESPA support for fix cmap --- doc/src/fix_cmap.rst | 5 +++++ src/MOLECULE/fix_cmap.cpp | 17 ++++++++++++----- src/MOLECULE/fix_cmap.h | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/doc/src/fix_cmap.rst b/doc/src/fix_cmap.rst index 892fd4ab41..e6e8d0c627 100644 --- a/doc/src/fix_cmap.rst +++ b/doc/src/fix_cmap.rst @@ -127,6 +127,11 @@ the :doc:`run ` command. The forces due to this fix are imposed during an energy minimization, invoked by the :doc:`minimize ` command. +The :doc:`fix_modify ` *respa* option is supported by this +fix. This allows to set at which level of the :doc:`r-RESPA +` integrator the fix is adding its forces. Default is the +outermost level. + .. note:: If you want the potential energy associated with the CMAP terms diff --git a/src/MOLECULE/fix_cmap.cpp b/src/MOLECULE/fix_cmap.cpp index 6da259f6ca..1b58037eb7 100644 --- a/src/MOLECULE/fix_cmap.cpp +++ b/src/MOLECULE/fix_cmap.cpp @@ -81,6 +81,8 @@ FixCMAP::FixCMAP(LAMMPS *lmp, int narg, char **arg) : extvector = 1; wd_header = 1; wd_section = 1; + respa_level_support = 1; + ilevel_respa = 0; MPI_Comm_rank(world,&me); MPI_Comm_size(world,&nprocs); @@ -182,6 +184,11 @@ void FixCMAP::init() // define newton_bond here in case restart file was read (not data file) newton_bond = force->newton_bond; + + if (utils::strmatch(update->integrate_style,"^respa")) { + ilevel_respa = ((Respa *) update->integrate)->nlevels-1; + if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); + } } /* --------------------------------------------------------------------- */ @@ -190,12 +197,12 @@ void FixCMAP::setup(int vflag) { pre_neighbor(); - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { - ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1); - post_force_respa(vflag,nlevels_respa-1,0); - ((Respa *) update->integrate)->copy_f_flevel(nlevels_respa-1); + ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); + post_force_respa(vflag,ilevel_respa,0); + ((Respa *) update->integrate)->copy_f_flevel(ilevel_respa); } } @@ -596,7 +603,7 @@ void FixCMAP::post_force(int vflag) void FixCMAP::post_force_respa(int vflag, int ilevel, int /*iloop*/) { - if (ilevel == nlevels_respa-1) post_force(vflag); + if (ilevel == ilevel_respa) post_force(vflag); } /* ---------------------------------------------------------------------- */ diff --git a/src/MOLECULE/fix_cmap.h b/src/MOLECULE/fix_cmap.h index 39d10bd77b..cd0c01a921 100644 --- a/src/MOLECULE/fix_cmap.h +++ b/src/MOLECULE/fix_cmap.h @@ -67,7 +67,7 @@ class FixCMAP : public Fix { private: int nprocs,me; int newton_bond,eflag_caller; - int ctype,nlevels_respa; + int ctype,ilevel_respa; int ncrosstermtypes,crossterm_per_atom,maxcrossterm; int ncrosstermlist; bigint ncmap; From 40f1a74a7f39f0a281652ed611d3ecc3fc95ec9e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Mar 2021 07:37:39 -0400 Subject: [PATCH 185/257] use more precise detection of verlet and respa run styles --- src/fix_addforce.cpp | 4 ++-- src/fix_recenter.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fix_addforce.cpp b/src/fix_addforce.cpp index 07031a40a4..a9f6248995 100644 --- a/src/fix_addforce.cpp +++ b/src/fix_addforce.cpp @@ -193,7 +193,7 @@ void FixAddForce::init() update->whichflag == 2 && estyle == NONE) error->all(FLERR,"Must use variable energy with fix addforce"); - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -203,7 +203,7 @@ void FixAddForce::init() void FixAddForce::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/fix_recenter.cpp b/src/fix_recenter.cpp index 1db74981b6..f5e4513d74 100644 --- a/src/fix_recenter.cpp +++ b/src/fix_recenter.cpp @@ -144,7 +144,7 @@ void FixRecenter::init() zinit = xcm[2]; } - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } From bfca619957830e7a8168753c7ae778e5e3e947f8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Mar 2021 07:49:15 -0400 Subject: [PATCH 186/257] fix typos --- doc/src/pair_fep_soft.rst | 2 +- doc/src/pair_gayberne.rst | 2 +- doc/src/pair_vashishta.rst | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/src/pair_fep_soft.rst b/doc/src/pair_fep_soft.rst index 109ddfdf21..1bb50fad1f 100644 --- a/doc/src/pair_fep_soft.rst +++ b/doc/src/pair_fep_soft.rst @@ -363,7 +363,7 @@ Mixing, shift, table, tail correction, restart, rRESPA info The different versions of the *lj/cut/soft* pair styles support mixing. For atom type pairs I,J and I != J, the :math:`\epsilon` and :math:`\sigma` -coefficients and cutoff distance for these pair style can be mixed. The default +coefficients and cutoff distance for these pair styles can be mixed. The default mix value is *geometric* for 12-6 styles. The mixing rule for epsilon and sigma for *lj/class2/soft* 9-6 potentials is to diff --git a/doc/src/pair_gayberne.rst b/doc/src/pair_gayberne.rst index 19597b9018..448f3a26de 100644 --- a/doc/src/pair_gayberne.rst +++ b/doc/src/pair_gayberne.rst @@ -188,7 +188,7 @@ Restrictions The *gayberne* style is part of the ASPHERE package. It is only enabled if LAMMPS was built with that package. See the :doc:`Build package ` doc page for more info. -These pair style require that atoms store torque and a quaternion to +These pair styles require that atoms store torque and a quaternion to represent their orientation, as defined by the :doc:`atom_style `. It also require they store a per-type :doc:`shape `. The particles cannot store a per-particle diff --git a/doc/src/pair_vashishta.rst b/doc/src/pair_vashishta.rst index aef401ec7c..9edb77ecbe 100644 --- a/doc/src/pair_vashishta.rst +++ b/doc/src/pair_vashishta.rst @@ -217,7 +217,7 @@ This pair style can only be used via the *pair* keyword of the Restrictions """""""""""" -These pair style are part of the MANYBODY package. They is only +These pair styles are part of the MANYBODY package. They are only enabled if LAMMPS was built with that package. See the :doc:`Build package ` doc page for more info. These pair styles requires the :doc:`newton ` setting to be "on" From 57ad6d50f45ed5974d8cecf1ca0ed08ced0975b3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Mar 2021 10:35:04 -0400 Subject: [PATCH 187/257] silence compiler warnings --- src/KOKKOS/atom_vec_hybrid_kokkos.cpp | 1 - src/USER-REACTION/fix_bond_react.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp index 907d1d555f..c962ed0c71 100644 --- a/src/KOKKOS/atom_vec_hybrid_kokkos.cpp +++ b/src/KOKKOS/atom_vec_hybrid_kokkos.cpp @@ -1171,7 +1171,6 @@ void AtomVecHybridKokkos::build_styles() allstyles = new char*[nallstyles]; - int n; nallstyles = 0; #define ATOM_CLASS #define AtomStyle(key,Class) \ diff --git a/src/USER-REACTION/fix_bond_react.cpp b/src/USER-REACTION/fix_bond_react.cpp index 17754c8297..2b88a8a264 100644 --- a/src/USER-REACTION/fix_bond_react.cpp +++ b/src/USER-REACTION/fix_bond_react.cpp @@ -682,7 +682,6 @@ it will have the name 'i_limit_tags' and will be intitialized to 0 (not in group void FixBondReact::post_constructor() { - int len; // let's add the limit_tags per-atom property fix std::string cmd = std::string("bond_react_props_internal"); id_fix2 = new char[cmd.size()+1]; From 71dbf43e090a6c6e93126efa4a4e293f29fae9df Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Mar 2021 11:10:59 -0400 Subject: [PATCH 188/257] error our when Fix:set_molecule() is called with unsupported fixes also add example input for using fix rigid/small with fix deposit --- .../deposit/in.deposit.molecule.rigid-small | 56 +++++ examples/deposit/in.deposit.molecule.shake | 4 +- ...10Mar21.deposit.molecule.rigid-small.g++.1 | 218 ++++++++++++++++++ ...10Mar21.deposit.molecule.rigid-small.g++.4 | 218 ++++++++++++++++++ src/RIGID/fix_rigid_nh_small.cpp | 13 ++ src/RIGID/fix_rigid_nh_small.h | 1 + src/RIGID/fix_rigid_small.h | 2 +- src/fix.cpp | 6 + src/fix.h | 2 +- 9 files changed, 516 insertions(+), 4 deletions(-) create mode 100644 examples/deposit/in.deposit.molecule.rigid-small create mode 100644 examples/deposit/log.10Mar21.deposit.molecule.rigid-small.g++.1 create mode 100644 examples/deposit/log.10Mar21.deposit.molecule.rigid-small.g++.4 diff --git a/examples/deposit/in.deposit.molecule.rigid-small b/examples/deposit/in.deposit.molecule.rigid-small new file mode 100644 index 0000000000..2e6a84e54b --- /dev/null +++ b/examples/deposit/in.deposit.molecule.rigid-small @@ -0,0 +1,56 @@ +# sample surface deposition script for molecules + +units lj +atom_style bond +boundary p p f + +lattice fcc 1.0 +region box block 0 5 0 5 0 10 +create_box 3 box bond/types 1 extra/bond/per/atom 1 + +region substrate block INF INF INF INF INF 3 +create_atoms 1 region substrate + +pair_style lj/cut 2.5 +pair_coeff * * 1.0 1.0 +pair_coeff 1 2 1.0 1.0 5.0 +mass * 1.0 + +bond_style harmonic +bond_coeff 1 5.0 1.0 + +neigh_modify delay 0 + +molecule dimer molecule.dimer +region slab block 0 5 0 5 8 9 + +group addatoms empty +region mobile block 0 5 0 5 2 INF +group mobile region mobile + +compute add addatoms temp +compute_modify add dynamic/dof yes extra/dof 0 + +fix 1 addatoms rigid/small molecule mol dimer +fix 2 mobile langevin 0.1 0.1 0.1 587283 +fix 3 mobile nve + +fix 4 addatoms deposit 100 0 100 12345 region slab near 1.0 & + mol dimer vz -1.0 -1.0 rigid 1 +fix 5 addatoms wall/reflect zhi EDGE + +thermo_style custom step atoms temp epair etotal press +thermo 100 +thermo_modify temp add lost/bond ignore lost warn + +#dump 1 all atom 50 dump.deposit.atom + +#dump 2 all image 50 image.*.jpg type type & +# axes yes 0.8 0.02 view 80 -30 +#dump_modify 2 pad 5 + +#dump 3 all movie 50 tmp.mpg type type & +# axes yes 0.8 0.02 view 80 -30 +#dump_modify 3 pad 5 + +run 10000 diff --git a/examples/deposit/in.deposit.molecule.shake b/examples/deposit/in.deposit.molecule.shake index 7bd701c924..30c6bd7a53 100644 --- a/examples/deposit/in.deposit.molecule.shake +++ b/examples/deposit/in.deposit.molecule.shake @@ -21,11 +21,11 @@ bond_coeff 1 5.0 1.0 neigh_modify delay 0 -group addatoms type 2 +group addatoms empty region mobile block 0 5 0 5 2 INF group mobile region mobile -compute add addatoms temp +compute add addatoms temp compute_modify add dynamic/dof yes extra/dof 0 fix 1 addatoms nve diff --git a/examples/deposit/log.10Mar21.deposit.molecule.rigid-small.g++.1 b/examples/deposit/log.10Mar21.deposit.molecule.rigid-small.g++.1 new file mode 100644 index 0000000000..0f5a1afcfa --- /dev/null +++ b/examples/deposit/log.10Mar21.deposit.molecule.rigid-small.g++.1 @@ -0,0 +1,218 @@ +LAMMPS (10 Mar 2021) + using 1 OpenMP thread(s) per MPI task +# sample surface deposition script for molecules + +units lj +atom_style bond +boundary p p f + +lattice fcc 1.0 +Lattice spacing in x,y,z = 1.5874011 1.5874011 1.5874011 +region box block 0 5 0 5 0 10 +create_box 3 box bond/types 1 extra/bond/per/atom 1 +Created orthogonal box = (0.0000000 0.0000000 0.0000000) to (7.9370053 7.9370053 15.874011) + 1 by 1 by 1 MPI processor grid + +region substrate block INF INF INF INF INF 3 +create_atoms 1 region substrate +Created 350 atoms + create_atoms CPU = 0.001 seconds + +pair_style lj/cut 2.5 +pair_coeff * * 1.0 1.0 +pair_coeff 1 2 1.0 1.0 5.0 +mass * 1.0 + +bond_style harmonic +bond_coeff 1 5.0 1.0 + +neigh_modify delay 0 + +molecule dimer molecule.dimer +Read molecule template dimer: + 1 molecules + 2 atoms with max type 3 + 1 bonds with max type 1 + 0 angles with max type 0 + 0 dihedrals with max type 0 + 0 impropers with max type 0 +region slab block 0 5 0 5 8 9 + +group addatoms empty +0 atoms in group addatoms +region mobile block 0 5 0 5 2 INF +group mobile region mobile +150 atoms in group mobile + +compute add addatoms temp +compute_modify add dynamic/dof yes extra/dof 0 + +fix 1 addatoms rigid/small molecule mol dimer + create bodies CPU = 0.000 seconds + 0 rigid bodies with 0 atoms + 1.0000000 = max distance from body owner to body atom +fix 2 mobile langevin 0.1 0.1 0.1 587283 +fix 3 mobile nve + +fix 4 addatoms deposit 100 0 100 12345 region slab near 1.0 mol dimer vz -1.0 -1.0 rigid 1 +fix 5 addatoms wall/reflect zhi EDGE + +thermo_style custom step atoms temp epair etotal press +thermo 100 +thermo_modify temp add lost/bond ignore lost warn +WARNING: Temperature for thermo pressure is not for group all (src/thermo.cpp:468) + +#dump 1 all atom 50 dump.deposit.atom + +#dump 2 all image 50 image.*.jpg type type # axes yes 0.8 0.02 view 80 -30 +#dump_modify 2 pad 5 + +#dump 3 all movie 50 tmp.mpg type type # axes yes 0.8 0.02 view 80 -30 +#dump_modify 3 pad 5 + +run 10000 +WARNING: Should not allow rigid bodies to bounce off relecting walls (src/fix_wall_reflect.cpp:182) +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 5.3 + ghost atom cutoff = 5.3 + binsize = 2.65, bins = 3 3 6 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair lj/cut, perpetual + attributes: half, newton on + pair build: half/bin/newton + stencil: half/bin/3d/newton + bin: standard +Per MPI rank memory allocation (min/avg/max) = 5.929 | 5.929 | 5.929 Mbytes +Step Atoms Temp E_pair TotEng Press + 0 350 0 -6.9215833 -6.9215833 -1.0052629 + 100 352 1.0079368 -6.8875167 -6.8803581 -0.73353914 + 200 354 1.0081552 -6.8594643 -6.8452248 -0.70421276 + 300 356 1.0085803 -6.8171524 -6.7959042 -0.6917826 + 400 358 1.0099188 -6.7852701 -6.7570601 -0.70371699 + 500 360 1.0140221 -6.7493429 -6.7141338 -0.68415307 + 600 362 1.026148 -6.7105231 -6.6680032 -0.68314418 + 700 364 1.0683344 -6.6725162 -6.621154 -0.65747369 + 800 366 1.0958952 -6.6412275 -6.5813425 -0.68789614 + 900 368 1.1250033 -6.6101882 -6.541404 -0.66674346 + 1000 370 1.2326373 -6.5993719 -6.5160856 -0.6968868 + 1100 372 1.1397426 -6.5912861 -6.5070309 -0.63330356 + 1200 374 1.0514292 -6.5905747 -6.5062354 -0.71020362 + 1300 376 1.003296 -6.5747765 -6.4880555 -0.65459732 + 1400 378 0.82999289 -6.5681797 -6.4913285 -0.60438126 + 1500 380 0.90239175 -6.575298 -6.4862461 -0.66528725 + 1600 382 0.86399799 -6.5692206 -6.4787496 -0.65027781 + 1700 384 0.64747231 -6.5644237 -6.4927634 -0.6304614 + 1800 386 0.74288971 -6.5515735 -6.4649672 -0.67772325 + 1900 388 0.7257202 -6.5565091 -6.4676644 -0.66173549 + 2000 390 0.73381036 -6.5631515 -6.4690733 -0.64685916 + 2100 392 0.76476562 -6.5574124 -6.4549885 -0.68866192 + 2200 394 0.65932468 -6.5511557 -6.459118 -0.71728829 + 2300 396 0.70269509 -6.5728146 -6.4707819 -0.64362081 + 2400 398 0.60528919 -6.5845991 -6.4933494 -0.63956327 + 2500 400 0.51025744 -6.5812452 -6.5015175 -0.68706961 + 2600 402 0.5245131 -6.6003894 -6.5155801 -0.68972215 + 2700 404 0.46330251 -6.5659175 -6.4885092 -0.72870942 + 2800 406 0.48039778 -6.5715192 -6.488692 -0.753758 + 2900 408 0.53698616 -6.5813154 -6.4858951 -0.67117541 + 3000 410 0.50231419 -6.5886963 -6.4968096 -0.71905351 + 3100 412 0.49420225 -6.596733 -6.5037702 -0.65947518 + 3200 414 0.42703699 -6.5879338 -6.5054146 -0.80033546 + 3300 416 0.44306009 -6.580249 -6.4923825 -0.76503083 + 3400 418 0.55620672 -6.5923388 -6.4792346 -0.69367877 + 3500 420 0.39815033 -6.5911154 -6.5081674 -0.65569211 + 3600 422 0.44197847 -6.6026382 -6.5083774 -0.73299102 + 3700 424 0.45049389 -6.6060616 -6.5077817 -0.7552914 + 3800 426 0.43047295 -6.6079275 -6.51193 -0.71501328 + 3900 428 0.43779129 -6.6099306 -6.5102001 -0.71539515 + 4000 430 0.41113503 -6.6123009 -6.5166881 -0.74177096 + 4100 432 0.32800011 -6.5983566 -6.5205325 -0.71688103 + 4200 434 0.39168203 -6.6110342 -6.5162724 -0.78927697 + 4300 436 0.48151013 -6.6183315 -6.4996106 -0.70523035 + 4400 438 0.45391027 -6.6331732 -6.5191775 -0.7270855 + 4500 440 0.349126 -6.6091657 -6.5199006 -0.76974115 + 4600 442 0.43375023 -6.6219188 -6.5090653 -0.74576212 + 4700 444 0.40071749 -6.6184164 -6.5123707 -0.71919052 + 4800 446 0.414292 -6.6298132 -6.5183445 -0.76237313 + 4900 448 0.44210681 -6.6364174 -6.5155288 -0.78753121 + 5000 450 0.36101771 -6.6232703 -6.5229876 -0.73927083 + 5100 452 0.41481171 -6.6442404 -6.5272305 -0.76316209 + 5200 454 0.40283527 -6.6512252 -6.5358759 -0.79645689 + 5300 456 0.3642061 -6.6530346 -6.5472072 -0.77458364 + 5400 458 0.38449826 -6.6514864 -6.5381518 -0.73083784 + 5500 460 0.42559408 -6.6769326 -6.5497169 -0.78932279 + 5600 462 0.38905756 -6.6698705 -6.5519743 -0.77118812 + 5700 464 0.38354955 -6.6706904 -6.5528977 -0.75067129 + 5800 466 0.36760943 -6.6942519 -6.5798669 -0.685487 + 5900 468 0.30783118 -6.6838159 -6.5867965 -0.79233808 + 6000 470 0.33145368 -6.6733504 -6.5675673 -0.84390449 + 6100 472 0.39252324 -6.6912189 -6.5643973 -0.83342022 + 6200 474 0.32342144 -6.6906083 -6.5848481 -0.71262158 + 6300 476 0.34445238 -6.7008453 -6.5868721 -0.76650756 + 6400 478 0.38152782 -6.7017838 -6.5740758 -0.77113022 + 6500 480 0.37540166 -6.7119996 -6.5849105 -0.79907635 + 6600 482 0.3579419 -6.7034721 -6.5809401 -0.8141269 + 6700 484 0.33538235 -6.6916682 -6.575601 -0.83265486 + 6800 486 0.34081871 -6.6931924 -6.573976 -0.80582583 + 6900 488 0.3555283 -6.6939997 -6.5683263 -0.74771423 + 7000 490 0.3543769 -6.7093364 -6.5827732 -0.77643516 + 7100 492 0.31263107 -6.698361 -6.5855723 -0.73108333 + 7200 494 0.32107 -6.6959056 -6.5789166 -0.7575478 + 7300 496 0.32908165 -6.7137605 -6.592677 -0.86538023 + 7400 498 0.32539571 -6.7030353 -6.5821554 -0.79337428 + 7500 500 0.33902577 -6.7078178 -6.5806832 -0.85408988 + 7600 502 0.35530921 -6.707507 -6.5730274 -0.79914613 + 7700 504 0.32391812 -6.6978823 -6.5741635 -0.78603595 + 7800 506 0.36390015 -6.7151325 -6.5748943 -0.83164222 + 7900 508 0.3372561 -6.7086718 -6.5775535 -0.7949992 + 8000 510 0.36612946 -6.7225238 -6.5789437 -0.80322866 + 8100 512 0.34622305 -6.7229825 -6.5860486 -0.70478659 + 8200 514 0.3212233 -6.7202524 -6.5921381 -0.91836713 + 8300 516 0.3402461 -6.721488 -6.5846642 -0.88273592 + 8400 518 0.34070258 -6.7268378 -6.5887152 -0.76057264 + 8500 520 0.36267747 -6.744602 -6.5963924 -0.81051317 + 8600 522 0.3439948 -6.7376267 -6.595943 -0.84600203 + 8700 524 0.30960289 -6.7276471 -6.5991382 -0.90965986 + 8800 526 0.28868972 -6.7159628 -6.595218 -0.876093 + 8900 528 0.31020216 -6.7162903 -6.5855707 -0.83193125 + 9000 530 0.31836275 -6.7171479 -6.5819939 -0.82093897 + 9100 532 0.32543293 -6.724167 -6.5850016 -0.7690143 + 9200 534 0.32644265 -6.7139575 -6.5733549 -0.86903096 + 9300 536 0.33050759 -6.7254715 -6.5821077 -0.94504522 + 9400 538 0.30372582 -6.7139931 -6.5813247 -0.91128612 + 9500 540 0.32943659 -6.7206223 -6.5757312 -0.87818439 + 9600 542 0.30911968 -6.708091 -6.5712114 -0.79092372 + 9700 544 0.33909826 -6.7222948 -6.5711342 -0.80266151 + 9800 546 0.29015141 -6.7086869 -6.5784908 -0.87763769 + 9900 548 0.33838474 -6.7384955 -6.5856667 -0.85630604 + 10000 550 0.30213198 -6.7338924 -6.5965597 -0.75738882 +Loop time of 17.2852 on 1 procs for 10000 steps with 550 atoms + +Performance: 249924.414 tau/day, 578.529 timesteps/s +99.7% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 9.637 | 9.637 | 9.637 | 0.0 | 55.75 +Bond | 0.025444 | 0.025444 | 0.025444 | 0.0 | 0.15 +Neigh | 4.6852 | 4.6852 | 4.6852 | 0.0 | 27.11 +Comm | 0.65556 | 0.65556 | 0.65556 | 0.0 | 3.79 +Output | 0.0099883 | 0.0099883 | 0.0099883 | 0.0 | 0.06 +Modify | 2.1895 | 2.1895 | 2.1895 | 0.0 | 12.67 +Other | | 0.08248 | | | 0.48 + +Nlocal: 550.000 ave 550 max 550 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 2367.00 ave 2367 max 2367 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 36781.0 ave 36781 max 36781 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 36781 +Ave neighs/atom = 66.874545 +Ave special neighs/atom = 0.36363636 +Neighbor list builds = 840 +Dangerous builds = 0 +Total wall time: 0:00:17 diff --git a/examples/deposit/log.10Mar21.deposit.molecule.rigid-small.g++.4 b/examples/deposit/log.10Mar21.deposit.molecule.rigid-small.g++.4 new file mode 100644 index 0000000000..0dcae43ba2 --- /dev/null +++ b/examples/deposit/log.10Mar21.deposit.molecule.rigid-small.g++.4 @@ -0,0 +1,218 @@ +LAMMPS (10 Mar 2021) + using 1 OpenMP thread(s) per MPI task +# sample surface deposition script for molecules + +units lj +atom_style bond +boundary p p f + +lattice fcc 1.0 +Lattice spacing in x,y,z = 1.5874011 1.5874011 1.5874011 +region box block 0 5 0 5 0 10 +create_box 3 box bond/types 1 extra/bond/per/atom 1 +Created orthogonal box = (0.0000000 0.0000000 0.0000000) to (7.9370053 7.9370053 15.874011) + 1 by 1 by 4 MPI processor grid + +region substrate block INF INF INF INF INF 3 +create_atoms 1 region substrate +Created 350 atoms + create_atoms CPU = 0.139 seconds + +pair_style lj/cut 2.5 +pair_coeff * * 1.0 1.0 +pair_coeff 1 2 1.0 1.0 5.0 +mass * 1.0 + +bond_style harmonic +bond_coeff 1 5.0 1.0 + +neigh_modify delay 0 + +molecule dimer molecule.dimer +Read molecule template dimer: + 1 molecules + 2 atoms with max type 3 + 1 bonds with max type 1 + 0 angles with max type 0 + 0 dihedrals with max type 0 + 0 impropers with max type 0 +region slab block 0 5 0 5 8 9 + +group addatoms empty +0 atoms in group addatoms +region mobile block 0 5 0 5 2 INF +group mobile region mobile +150 atoms in group mobile + +compute add addatoms temp +compute_modify add dynamic/dof yes extra/dof 0 + +fix 1 addatoms rigid/small molecule mol dimer + create bodies CPU = 0.006 seconds + 0 rigid bodies with 0 atoms + 1.0000000 = max distance from body owner to body atom +fix 2 mobile langevin 0.1 0.1 0.1 587283 +fix 3 mobile nve + +fix 4 addatoms deposit 100 0 100 12345 region slab near 1.0 mol dimer vz -1.0 -1.0 rigid 1 +fix 5 addatoms wall/reflect zhi EDGE + +thermo_style custom step atoms temp epair etotal press +thermo 100 +thermo_modify temp add lost/bond ignore lost warn +WARNING: Temperature for thermo pressure is not for group all (src/thermo.cpp:468) + +#dump 1 all atom 50 dump.deposit.atom + +#dump 2 all image 50 image.*.jpg type type # axes yes 0.8 0.02 view 80 -30 +#dump_modify 2 pad 5 + +#dump 3 all movie 50 tmp.mpg type type # axes yes 0.8 0.02 view 80 -30 +#dump_modify 3 pad 5 + +run 10000 +WARNING: Should not allow rigid bodies to bounce off relecting walls (src/fix_wall_reflect.cpp:182) +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 5.3 + ghost atom cutoff = 5.3 + binsize = 2.65, bins = 3 3 6 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair lj/cut, perpetual + attributes: half, newton on + pair build: half/bin/newton + stencil: half/bin/3d/newton + bin: standard +Per MPI rank memory allocation (min/avg/max) = 5.255 | 5.852 | 6.302 Mbytes +Step Atoms Temp E_pair TotEng Press + 0 350 0 -6.9215833 -6.9215833 -1.0052629 + 100 352 1.0079368 -6.8946578 -6.8874992 -0.73775337 + 200 354 1.0081552 -6.8645575 -6.850318 -0.69629729 + 300 356 1.0085803 -6.821677 -6.8004288 -0.69532657 + 400 358 1.0099188 -6.7837923 -6.7555822 -0.68879568 + 500 360 1.0140221 -6.7446709 -6.7094618 -0.72991641 + 600 362 1.026146 -6.7129201 -6.6704003 -0.67063836 + 700 364 1.0683193 -6.6776523 -6.6262908 -0.65572472 + 800 366 1.0958893 -6.6402029 -6.5803182 -0.66307281 + 900 368 1.1231768 -6.6050912 -6.5364187 -0.64076928 + 1000 370 1.1976283 -6.5942507 -6.5133299 -0.69249019 + 1100 372 1.0506263 -6.5772313 -6.499564 -0.63072939 + 1200 374 0.93724351 -6.5732957 -6.4981157 -0.64963897 + 1300 376 0.93899686 -6.5578406 -6.4766773 -0.65096289 + 1400 378 0.8704974 -6.5468498 -6.4662482 -0.67613931 + 1500 380 0.84490693 -6.5401094 -6.4567304 -0.64385968 + 1600 382 0.9243154 -6.5611604 -6.4643734 -0.62096869 + 1700 384 0.67202953 -6.5590557 -6.4846775 -0.67807465 + 1800 386 0.8712464 -6.5654953 -6.4639251 -0.65860236 + 1900 388 0.70011668 -6.5808612 -6.495151 -0.65146463 + 2000 390 0.64019295 -6.5652168 -6.4831408 -0.70291888 + 2100 392 0.67578277 -6.5596196 -6.469113 -0.63315981 + 2200 394 0.60785287 -6.558941 -6.4740885 -0.7133822 + 2300 396 0.8155086 -6.5756022 -6.4571887 -0.69176417 + 2400 398 0.69028748 -6.5875474 -6.483484 -0.63743938 + 2500 400 0.5013913 -6.5871851 -6.5088427 -0.65872179 + 2600 402 0.51268385 -6.5782356 -6.495339 -0.74289067 + 2700 404 0.57745388 -6.5815718 -6.4850912 -0.67922914 + 2800 406 0.47317895 -6.5974978 -6.5159152 -0.64657562 + 2900 408 0.50593124 -6.6019054 -6.5120034 -0.64211427 + 3000 410 0.44423233 -6.5956684 -6.5144064 -0.66526127 + 3100 412 0.40808865 -6.5949863 -6.5182221 -0.62722445 + 3200 414 0.40692632 -6.5866689 -6.5080358 -0.76440608 + 3300 416 0.43908529 -6.5851721 -6.4980939 -0.69345883 + 3400 418 0.53825907 -6.5880076 -6.478553 -0.69726204 + 3500 420 0.46363057 -6.6135193 -6.5169296 -0.58015901 + 3600 422 0.39262699 -6.621857 -6.5381213 -0.74921264 + 3700 424 0.42679205 -6.6146579 -6.5215488 -0.69040431 + 3800 426 0.38997492 -6.6139725 -6.5270063 -0.78237667 + 3900 428 0.5222531 -6.6403886 -6.5214174 -0.78298122 + 4000 430 0.47841128 -6.6502681 -6.5390097 -0.68125967 + 4100 432 0.44609186 -6.6610827 -6.5552392 -0.81157037 + 4200 434 0.4591431 -6.6858064 -6.5747234 -0.79000753 + 4300 436 0.40690573 -6.6800195 -6.579693 -0.6781696 + 4400 438 0.43023944 -6.6849804 -6.5769294 -0.7620548 + 4500 440 0.40889421 -6.6783124 -6.5737656 -0.8577593 + 4600 442 0.41452051 -6.6968565 -6.5890061 -0.70427746 + 4700 444 0.36740394 -6.6920933 -6.5948636 -0.69303162 + 4800 446 0.40112316 -6.6869413 -6.5790158 -0.84792822 + 4900 448 0.42437165 -6.6789835 -6.5629444 -0.82278531 + 5000 450 0.41822898 -6.6770254 -6.5608507 -0.72224472 + 5100 452 0.38445688 -6.6738997 -6.5654522 -0.7022418 + 5200 454 0.39998238 -6.6670536 -6.5525212 -0.73639959 + 5300 456 0.39471029 -6.6728592 -6.5581681 -0.70419927 + 5400 458 0.35817807 -6.6702423 -6.5646658 -0.81657219 + 5500 460 0.37151428 -6.6690855 -6.558035 -0.78076653 + 5600 462 0.32642513 -6.6622352 -6.5633185 -0.69118644 + 5700 464 0.43665879 -6.6811227 -6.5470195 -0.77500043 + 5800 466 0.40704721 -6.6858874 -6.5592311 -0.72683597 + 5900 468 0.3861903 -6.6896953 -6.5679794 -0.78001958 + 6000 470 0.34073346 -6.6833717 -6.574627 -0.78170837 + 6100 472 0.39953874 -6.7083668 -6.5792785 -0.81791744 + 6200 474 0.36685189 -6.7114648 -6.5915027 -0.80545451 + 6300 476 0.35851799 -6.7261023 -6.607475 -0.77350495 + 6400 478 0.41771823 -6.7427425 -6.6029205 -0.85319003 + 6500 480 0.36519478 -6.732662 -6.6090284 -0.78712805 + 6600 482 0.30669571 -6.7269784 -6.6219892 -0.76698134 + 6700 484 0.3384344 -6.7261448 -6.6090213 -0.79935239 + 6800 486 0.36420902 -6.7320259 -6.6046277 -0.84650552 + 6900 488 0.40181215 -6.7490619 -6.6070279 -0.75753238 + 7000 490 0.30536068 -6.7398924 -6.6308351 -0.73210162 + 7100 492 0.28813004 -6.7257287 -6.6217794 -0.92178435 + 7200 494 0.30956277 -6.7342688 -6.6214727 -0.77532949 + 7300 496 0.36625115 -6.7528159 -6.6180561 -0.76247835 + 7400 498 0.30935271 -6.7401433 -6.6252231 -0.82809158 + 7500 500 0.33222282 -6.7410421 -6.6164585 -0.81948236 + 7600 502 0.33318693 -6.7488106 -6.622704 -0.82395904 + 7700 504 0.34570598 -6.7547394 -6.6226989 -0.85644369 + 7800 506 0.34587242 -6.7446006 -6.6113099 -0.82476511 + 7900 508 0.2969166 -6.7305429 -6.6151078 -0.8210214 + 8000 510 0.32355758 -6.7437629 -6.6168776 -0.81719054 + 8100 512 0.33784479 -6.7545537 -6.6209335 -0.78082067 + 8200 514 0.32351289 -6.7525032 -6.6234757 -0.87093587 + 8300 516 0.31900134 -6.7550972 -6.6268166 -0.79928704 + 8400 518 0.3338521 -6.7588757 -6.6235302 -0.81699503 + 8500 520 0.33115184 -6.7614854 -6.6261589 -0.79958489 + 8600 522 0.29478929 -6.7490188 -6.6276018 -0.81954456 + 8700 524 0.267993 -6.7467764 -6.6355389 -0.76642994 + 8800 526 0.28792085 -6.7527118 -6.6322887 -0.86911619 + 8900 528 0.32430992 -6.75901 -6.6223453 -0.87087898 + 9000 530 0.33151321 -6.7534845 -6.6127478 -0.79309499 + 9100 532 0.32760982 -6.7599992 -6.6199028 -0.7506309 + 9200 534 0.32579101 -6.7671489 -6.6268269 -0.94238755 + 9300 536 0.35144354 -6.7782581 -6.625813 -0.77952234 + 9400 538 0.33689976 -6.7804455 -6.6332867 -0.75768501 + 9500 540 0.3052486 -6.7745436 -6.6402908 -0.89621525 + 9600 542 0.30617581 -6.7648172 -6.6292412 -0.90623541 + 9700 544 0.30097715 -6.7714379 -6.6372707 -0.85534149 + 9800 546 0.31297479 -6.7814978 -6.6410604 -0.88651064 + 9900 548 0.31832347 -6.790661 -6.6468926 -1.006 + 10000 550 0.29239559 -6.7823137 -6.6494066 -1.0337518 +Loop time of 34.7661 on 4 procs for 10000 steps with 550 atoms + +Performance: 124259.065 tau/day, 287.637 timesteps/s +73.4% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0.0076709 | 3.1286 | 9.1834 | 211.7 | 9.00 +Bond | 0.0040276 | 0.010416 | 0.022169 | 7.0 | 0.03 +Neigh | 0.052413 | 1.5948 | 4.885 | 155.3 | 4.59 +Comm | 4.9736 | 12.242 | 20.073 | 166.2 | 35.21 +Output | 0.053549 | 0.10104 | 0.21642 | 21.0 | 0.29 +Modify | 13.435 | 16.191 | 23.851 | 110.0 | 46.57 +Other | | 1.499 | | | 4.31 + +Nlocal: 137.500 ave 299 max 2 min +Histogram: 2 0 0 0 0 0 0 1 0 1 +Nghost: 1898.75 ave 2679 max 524 min +Histogram: 1 0 0 0 0 0 1 0 0 2 +Neighs: 9204.00 ave 23014 max 0 min +Histogram: 2 0 0 0 0 1 0 0 0 1 + +Total # of neighbors = 36816 +Ave neighs/atom = 66.938182 +Ave special neighs/atom = 0.36363636 +Neighbor list builds = 832 +Dangerous builds = 0 +Total wall time: 0:00:34 diff --git a/src/RIGID/fix_rigid_nh_small.cpp b/src/RIGID/fix_rigid_nh_small.cpp index af2adb540d..3956fcf35d 100644 --- a/src/RIGID/fix_rigid_nh_small.cpp +++ b/src/RIGID/fix_rigid_nh_small.cpp @@ -1365,6 +1365,19 @@ int FixRigidNHSmall::modify_param(int narg, char **arg) return FixRigidSmall::modify_param(narg,arg); } +/* ---------------------------------------------------------------------- + disallow using fix rigid/n??/small fixes with fix deposit + we would need custom functionality to update data structures + used by all fixes derived from this class but not fix rigid/small +------------------------------------------------------------------------- */ + +void FixRigidNHSmall::set_molecule(int, tagint, int, + double *, double *, double *) +{ + error->all(FLERR,fmt::format("Molecule update not (yet) implemented for " + "fix {}", style)); +} + /* ---------------------------------------------------------------------- */ void FixRigidNHSmall::allocate_chain() diff --git a/src/RIGID/fix_rigid_nh_small.h b/src/RIGID/fix_rigid_nh_small.h index e04290aee8..32c4c1ab74 100644 --- a/src/RIGID/fix_rigid_nh_small.h +++ b/src/RIGID/fix_rigid_nh_small.h @@ -80,6 +80,7 @@ class FixRigidNHSmall : public FixRigidSmall { void nh_epsilon_dot(); void compute_dof(); + void set_molecule(int, tagint, int, double *, double *, double *); void allocate_chain(); void allocate_order(); void deallocate_chain(); diff --git a/src/RIGID/fix_rigid_small.h b/src/RIGID/fix_rigid_small.h index d6e97c06fd..6534017971 100644 --- a/src/RIGID/fix_rigid_small.h +++ b/src/RIGID/fix_rigid_small.h @@ -43,7 +43,7 @@ class FixRigidSmall : public Fix { void grow_arrays(int); void copy_arrays(int, int, int); void set_arrays(int); - void set_molecule(int, tagint, int, double *, double *, double *); + virtual void set_molecule(int, tagint, int, double *, double *, double *); int pack_exchange(int, double *); int unpack_exchange(int, double *); diff --git a/src/fix.cpp b/src/fix.cpp index b9d9fb3969..32a76cc125 100644 --- a/src/fix.cpp +++ b/src/fix.cpp @@ -174,6 +174,12 @@ void Fix::modify_params(int narg, char **arg) } } +void::Fix::set_molecule(int, tagint, int, double *, double *, double *) +{ + error->all(FLERR,fmt::format("Molecule update not implemented for " + "fix {}", style)); +} + /* ---------------------------------------------------------------------- setup for peratom energy and global/peratom virial computation see integrate::ev_set() for values of eflag (0-3) and vflag (0-6) diff --git a/src/fix.h b/src/fix.h index 7092b56c8f..31add74ee4 100644 --- a/src/fix.h +++ b/src/fix.h @@ -155,7 +155,7 @@ class Fix : protected Pointers { virtual void copy_arrays(int, int, int) {} virtual void set_arrays(int) {} virtual void update_arrays(int, int) {} - virtual void set_molecule(int, tagint, int, double *, double *, double *) {} + virtual void set_molecule(int, tagint, int, double *, double *, double *); virtual void clear_bonus() {} virtual int pack_border(int, int *, double *) {return 0;} From 24d9d6d17d1fbe1485b86debdf7c3bdac854bca0 Mon Sep 17 00:00:00 2001 From: "Ronald E. Miller" Date: Tue, 30 Mar 2021 11:27:39 -0400 Subject: [PATCH 189/257] update to kim_interactions to correctly handle incorrect combinations of periodic and f/s boundary conditions when the SM has to choose between kspace or real space coulomb calculations. This version treats "p p p" in kspace, "f f f" or "s s s" in realspace, and "p p f" with kspace-slab. all others are sent to kspace-slab and then caught there as an error. --- src/KIM/kim_interactions.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/KIM/kim_interactions.cpp b/src/KIM/kim_interactions.cpp index b6a1ed6f47..c3da21b50d 100644 --- a/src/KIM/kim_interactions.cpp +++ b/src/KIM/kim_interactions.cpp @@ -94,6 +94,7 @@ void KimInteractions::command(int narg, char **arg) void KimInteractions::do_setup(int narg, char **arg) { + static bool kim_update=0; bool fixed_types; if ((narg == 1) && (0 == strcmp("fixed_types",arg[0]))) { fixed_types = true; @@ -185,9 +186,11 @@ void KimInteractions::do_setup(int narg, char **arg) KIM_SimulatorModel_GetSimulatorFieldMetadata( simulatorModel,i,&sim_lines,&sim_field); if (0 == strcmp(sim_field,"model-defn")) { + if (kim_update) input->one("variable kim_update equal 1"); + else input->one("variable kim_update equal 0"); if (domain->periodicity[0]&&domain->periodicity[1]&&domain->periodicity[2]) input->one("variable kim_periodic equal 1"); - else if (domain->periodicity[0]&&domain->periodicity[1]&&!domain->periodicity[2]) input->one("variable kim_periodic equal 2"); - else input->one("variable kim_periodic equal 0"); + else if (!domain->periodicity[0]&&!domain->periodicity[1]&&!domain->periodicity[2]) input->one("variable kim_periodic equal 0"); + else input->one("variable kim_periodic equal 2"); sim_model_idx = i; for (int j=0; j < sim_lines; ++j) { KIM_SimulatorModel_GetSimulatorFieldLine( @@ -217,7 +220,8 @@ void KimInteractions::do_setup(int narg, char **arg) KIM_SimulatorModel_OpenAndInitializeTemplateMap(simulatorModel); - } else { + } else if (!kim_update) { + // not a simulator model. issue pair_style and pair_coeff commands. @@ -242,6 +246,7 @@ void KimInteractions::do_setup(int narg, char **arg) // End output to log file input->write_echo("#=== END kim_interactions ====================================\n\n"); + kim_update=1; } /* ---------------------------------------------------------------------- */ From 2dbf59efa9fb4f30456a7cbb00f5a2b8eaeaecbe Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Mar 2021 11:43:56 -0400 Subject: [PATCH 190/257] update install instructions for updates via patch and git for CMake/GNU make --- doc/src/Install_git.rst | 70 +++++++++++++++++++++++++++------------ doc/src/Install_patch.rst | 62 +++++++++++++++++++++++++--------- 2 files changed, 94 insertions(+), 38 deletions(-) diff --git a/doc/src/Install_git.rst b/doc/src/Install_git.rst index a84f31a80d..3c10171ea3 100644 --- a/doc/src/Install_git.rst +++ b/doc/src/Install_git.rst @@ -86,33 +86,59 @@ check out any other desired branch) first. Once you have updated your local files with a ``git pull`` (or ``git checkout``), you still need to re-build LAMMPS if any source files have -changed. To do this, you should cd to the src directory and type: +changed. How to do this depends on the build system you are using. -.. code-block:: bash +.. tabs:: - $ make purge # remove any deprecated src files - $ make package-update # sync package files with src files - $ make foo # re-build for your machine (mpi, serial, etc) + .. tab:: CMake build -just as described on the :doc:`Apply patch ` page, -after a patch has been installed. + Change to your build folder and type: -.. warning:: + .. code-block:: bash - If you wish to edit/change a src file that is from a - package, you should edit the version of the file inside the package - sub-directory with src, then re-install the package. The version in - the source directory is merely a copy and will be wiped out if you type "make - package-update". + cmake . --build -.. warning:: + CMake should auto-detect whether it needs to re-run the CMake + configuration step and otherwise redo the build for all files + that have been changed or files that depend on changed files. + In case some build options have been changed or renamed, you + may have to update those by running: - The GitHub servers support both the "git://" and - "https://" access protocols for anonymous read-only access. If you - have a correspondingly configured GitHub account, you may also use - SSH access with the URL "git@github.com:lammps/lammps.git". + .. code-block:: bash -The LAMMPS GitHub project is managed by Christoph Junghans (LANL, -junghans at lanl.gov), Axel Kohlmeyer (Temple U, akohlmey at -gmail.com) and Richard Berger (Temple U, richard.berger at -temple.edu). + cmake . + + and then rebuild. + + .. tab:: Traditional make + + Switch to the src directory and type: + + .. code-block:: bash + + $ make purge # remove any deprecated src files + $ make package-update # sync package files with src files + $ make foo # re-build for your machine (mpi, serial, etc) + + Just as described on the :doc:`Apply patch ` page, + after a patch has been installed. + + .. warning:: + + If you wish to edit/change a src file that is from a package, + you should edit the version of the file inside the package + sub-directory with src, then re-install the package. The + version in the source directory is merely a copy and will be + wiped out if you type "make package-update". + +.. admonition:: Git protocols + :class: note + + The servers at github.com support the "git://" and "https://" access + protocols for anonymous, read-only access. If you have a suitably + configured GitHub account, you may also use SSH protocol with the + URL "git@github.com:lammps/lammps.git". + +The LAMMPS GitHub project is currently managed by Axel Kohlmeyer +(Temple U, akohlmey at gmail.com) and Richard Berger (Temple U, +richard.berger at temple.edu). diff --git a/doc/src/Install_patch.rst b/doc/src/Install_patch.rst index 39e007bb67..b1f36b19e0 100644 --- a/doc/src/Install_patch.rst +++ b/doc/src/Install_patch.rst @@ -43,24 +43,54 @@ up to date. * A list of updated files print out to the screen. The -b switch creates backup files of your originals (e.g. src/force.cpp.orig), so you can manually undo the patch if something goes wrong. -* Type the following from the src directory, to enforce consistency - between the src and package directories. This is OK to do even if you - don't use one or more packages. If you are applying several patches - successively, you only need to type this once at the end. The purge - command removes deprecated src files if any were removed by the patch - from package sub-directories. - .. code-block:: bash +* Once you have updated your local files you need to re-build LAMMPS. + If you are applying several patches successively, you only need to + do the rebuild once at the end. How to do it depends on the build + system you are using. - $ make purge - $ make package-update + .. tabs:: -* Re-build LAMMPS via the "make" command. + .. tab:: CMake build -.. warning:: + Change to your build folder and type: - If you wish to edit/change a source file that is part of a package, - you should edit the version of the file inside the package folder in - src, and then re-install or update the package. The version in the - src directory is merely a copy and will be wiped out when you type - "make package-update". + .. code-block:: bash + + cmake . --build + + CMake should auto-detect whether it needs to re-run the CMake + configuration step and otherwise redo the build for all files + that have been changed or files that depend on changed files. + In case some build options have been changed or renamed, you + may have to update those by running: + + .. code-block:: bash + + cmake . + + and then rebuild. + + .. tab:: Traditional make + + Switch to the src directory and type: + + .. code-block:: bash + + $ make purge # remove any deprecated src files + $ make package-update # sync package files with src files + $ make foo # re-build for your machine (mpi, serial, etc) + + to enforce consistency of the source between the src folder + and package directories. This is OK to do even if you don't + use any packages. The "make purge" command removes any deprecated + src files if they were removed by the patch from a package + sub-directory. + + .. warning:: + + If you wish to edit/change a src file that is from a package, + you should edit the version of the file inside the package + sub-directory with src, then re-install the package. The + version in the source directory is merely a copy and will be + wiped out if you type "make package-update". From 4ee24b85b0e786b6bf98f998fd4d45e8994da20b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Mar 2021 11:45:47 -0400 Subject: [PATCH 191/257] fix a few minor issues with the docs --- doc/src/Build_basics.rst | 2 +- doc/src/angle_cosine_periodic.rst | 6 ------ doc/src/dihedral_table.rst | 4 ++-- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/doc/src/Build_basics.rst b/doc/src/Build_basics.rst index af6120630d..30e668a283 100644 --- a/doc/src/Build_basics.rst +++ b/doc/src/Build_basics.rst @@ -1,7 +1,7 @@ Basic build options =================== -The following topics are covered on this page, for building both with +The following topics are covered on this page, for building with both CMake and make: * :ref:`Serial vs parallel build ` diff --git a/doc/src/angle_cosine_periodic.rst b/doc/src/angle_cosine_periodic.rst index 8c60ac1ebb..4983745618 100644 --- a/doc/src/angle_cosine_periodic.rst +++ b/doc/src/angle_cosine_periodic.rst @@ -71,9 +71,3 @@ Default none ----------- - -.. _cosine-Mayo: - -**(Mayo)** Mayo, Olfason, Goddard III, J Phys Chem, 94, 8897-8909 -(1990). diff --git a/doc/src/dihedral_table.rst b/doc/src/dihedral_table.rst index f1b14065fd..a456fecebd 100644 --- a/doc/src/dihedral_table.rst +++ b/doc/src/dihedral_table.rst @@ -15,10 +15,10 @@ Syntax .. code-block:: LAMMPS - dihedral_style style interp Ntable + dihedral_style style interpolation Ntable * style = *table* or *table/cut* -* interp = *linear* or *spline* = method of interpolation +* interpolation = *linear* or *spline* = method of interpolation * Ntable = size of the internal lookup table Examples From 8f5d11c0c576e4ea4b3a8682a329ee949438124a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Mar 2021 13:34:31 -0400 Subject: [PATCH 192/257] add missing return --- src/deprecated.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/deprecated.cpp b/src/deprecated.cpp index 40974e202b..4e596abb43 100644 --- a/src/deprecated.cpp +++ b/src/deprecated.cpp @@ -47,6 +47,7 @@ void Deprecated::command(int narg, char **arg) newcmd.append(arg[i]); } input->one(newcmd); + return; } error->all(FLERR,"This command is no longer available"); } From 2e86cb4176743859deb289e3018be9df92288d43 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Mar 2021 15:33:11 -0400 Subject: [PATCH 193/257] for atom style template number of bonds does not depend on newton_bond --- src/read_data.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/read_data.cpp b/src/read_data.cpp index 90aafd4b98..09fb8f3eae 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -793,7 +793,7 @@ void ReadData::command(int narg, char **arg) special.build(); } - // for atom style template systems, count total bonds,angles,etc + // for atom style template just count total bonds, etc. from template(s) if (atom->molecular == Atom::TEMPLATE) { Molecule **onemols = atom->avec->onemols; @@ -821,13 +821,6 @@ void ReadData::command(int narg, char **arg) MPI_Allreduce(&ndihedrals,&atom->ndihedrals,1,MPI_LMP_BIGINT,MPI_SUM,world); MPI_Allreduce(&nimpropers,&atom->nimpropers,1,MPI_LMP_BIGINT,MPI_SUM,world); - if (!force->newton_bond) { - atom->nbonds /= 2; - atom->nangles /= 3; - atom->ndihedrals /= 4; - atom->nimpropers /= 4; - } - if (me == 0) { std::string mesg; From e22f9c4768fb29f3dd0646ea303a623b79d15a74 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Mar 2021 16:48:51 -0400 Subject: [PATCH 194/257] newton bond off does not work with atom style template currently --- src/neighbor.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 0055678f41..68fa3ca96e 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -1363,6 +1363,10 @@ void Neighbor::init_topology() onoff = improper_off; MPI_Allreduce(&onoff,&improper_off,1,MPI_INT,MPI_MAX,world); + // newton_bond off is not supported with atom style template + if ((atom->molecular == Atom::TEMPLATE) && (force->newton_bond == 0)) + error->all(FLERR,"Must use 'newton bond on' with atom style template"); + // instantiate NTopo classes if (atom->avec->bonds_allow) { From eea2f45a95d7c43df38df672a882933ae3e9e8ea Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Mar 2021 17:19:28 -0400 Subject: [PATCH 195/257] force newton bond to be on since we don't support it to be off (yet) --- unittest/formats/test_atom_styles.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index 37d436a7a2..a08bddcba4 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -2711,7 +2711,7 @@ TEST_F(AtomStyleTest, template) command("write_data test_atom_styles.data"); command("clear"); command("units real"); - command("newton off"); + command("newton off on"); command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); command("atom_style template twomols"); command("pair_style zero 4.0"); @@ -3127,7 +3127,7 @@ TEST_F(AtomStyleTest, template_charge) command("write_data test_atom_styles.data"); command("clear"); command("units real"); - command("newton off"); + command("newton off on"); command("molecule twomols h2o.mol co2.mol offset 2 1 1 0 0"); command("atom_style hybrid template twomols charge"); command("pair_style zero 4.0"); From 183b30abd7d66d66bbe4d577c9ffdc844b533ea3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Mar 2021 18:30:22 -0400 Subject: [PATCH 196/257] use strmatch() consistently to detect respa and verlet runstyles with optional suffix --- src/BODY/fix_wall_body_polygon.cpp | 2 +- src/BODY/fix_wall_body_polyhedron.cpp | 2 +- src/CLASS2/pair_lj_class2.cpp | 4 ++-- src/CLASS2/pair_lj_class2_coul_long.cpp | 4 ++-- src/GPU/fix_gpu.cpp | 2 +- src/GPU/fix_nh_gpu.cpp | 2 +- src/GPU/fix_nve_gpu.cpp | 2 +- src/GPU/pppm_gpu.cpp | 2 +- src/GRANULAR/fix_freeze.cpp | 2 +- src/GRANULAR/fix_wall_gran.cpp | 4 ++-- src/KOKKOS/fix_setforce_kokkos.cpp | 2 +- src/KOKKOS/fix_shake_kokkos.cpp | 2 +- src/KOKKOS/pair_buck_coul_cut_kokkos.cpp | 2 +- src/KOKKOS/pair_buck_coul_long_kokkos.cpp | 2 +- src/KOKKOS/pair_buck_kokkos.cpp | 2 +- src/KOKKOS/pair_coul_long_kokkos.cpp | 2 +- src/KOKKOS/pair_hybrid_kokkos.cpp | 2 +- .../pair_lj_charmm_coul_charmm_implicit_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_charmm_coul_long_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_class2_coul_long_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_class2_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_cut_coul_long_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_cut_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_expand_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_gromacs_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_sdk_kokkos.cpp | 2 +- src/KOKKOS/pair_morse_kokkos.cpp | 2 +- src/KOKKOS/pair_yukawa_kokkos.cpp | 2 +- src/KOKKOS/pair_zbl_kokkos.cpp | 2 +- src/KSPACE/pair_buck_long_coul_long.cpp | 4 ++-- src/KSPACE/pair_lj_charmmfsw_coul_long.cpp | 4 ++-- src/KSPACE/pair_lj_long_coul_long.cpp | 4 ++-- src/MANYBODY/fix_qeq_comb.cpp | 2 +- src/MC/fix_bond_break.cpp | 2 +- src/MC/fix_bond_create.cpp | 2 +- src/MISC/fix_efield.cpp | 4 ++-- src/MISC/fix_gld.cpp | 2 +- src/MISC/fix_orient_bcc.cpp | 4 ++-- src/MISC/fix_orient_fcc.cpp | 4 ++-- src/MISC/fix_ttm.cpp | 2 +- src/MOLECULE/dihedral_charmm.cpp | 2 +- src/MOLECULE/dihedral_charmmfsw.cpp | 2 +- src/POEMS/fix_poems.cpp | 2 +- src/QEQ/fix_qeq_dynamic.cpp | 2 +- src/QEQ/fix_qeq_fire.cpp | 2 +- src/QEQ/fix_qeq_point.cpp | 2 +- src/QEQ/fix_qeq_shielded.cpp | 2 +- src/QEQ/fix_qeq_slater.cpp | 2 +- src/RIGID/fix_rigid.cpp | 2 +- src/RIGID/fix_rigid_small.cpp | 2 +- src/RIGID/fix_shake.cpp | 4 ++-- src/SPIN/fix_precession_spin.cpp | 4 ++-- src/USER-BOCS/fix_bocs.cpp | 4 ++-- src/USER-COLVARS/fix_colvars.cpp | 4 ++-- src/USER-DRUDE/fix_langevin_drude.cpp | 2 +- src/USER-DRUDE/fix_tgnh_drude.cpp | 4 ++-- src/USER-EFF/fix_nve_eff.cpp | 2 +- src/USER-FEP/fix_adapt_fep.cpp | 2 +- src/USER-INTEL/fix_nh_intel.cpp | 2 +- src/USER-LB/fix_lb_viscous.cpp | 4 ++-- src/USER-MANIFOLD/fix_manifoldforce.cpp | 2 +- src/USER-MISC/fix_addtorque.cpp | 4 ++-- src/USER-MISC/fix_electron_stopping_fit.cpp | 2 +- src/USER-MISC/fix_ffl.cpp | 4 ++-- src/USER-MISC/fix_filter_corotate.cpp | 2 +- src/USER-MISC/fix_flow_gauss.cpp | 4 ++-- src/USER-MISC/fix_gle.cpp | 4 ++-- src/USER-MISC/fix_grem.cpp | 4 ++-- src/USER-MISC/fix_imd.cpp | 2 +- src/USER-MISC/fix_npt_cauchy.cpp | 4 ++-- src/USER-MISC/fix_nvk.cpp | 2 +- src/USER-MISC/fix_orient_eco.cpp | 4 ++-- src/USER-MISC/fix_pafi.cpp | 4 ++-- src/USER-MISC/fix_rhok.cpp | 4 ++-- src/USER-MISC/fix_smd.cpp | 10 +++++----- src/USER-MISC/fix_ti_spring.cpp | 4 ++-- src/USER-MISC/fix_ttm_mod.cpp | 2 +- src/USER-MISC/fix_wall_region_ees.cpp | 4 ++-- src/USER-MISC/pair_lj_expand_coul_long.cpp | 4 ++-- src/USER-OMP/fix_omp.cpp | 5 ++--- src/USER-OMP/fix_qeq_comb_omp.cpp | 2 +- src/USER-QMMM/fix_qmmm.cpp | 2 +- src/USER-QTB/fix_qtb.cpp | 4 ++-- src/USER-REAXC/fix_qeq_reax.cpp | 2 +- src/USER-SMD/fix_smd_setvel.cpp | 2 +- src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp | 4 ++-- src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp | 4 ++-- src/fix_adapt.cpp | 2 +- src/fix_aveforce.cpp | 4 ++-- src/fix_drag.cpp | 4 ++-- src/fix_dt_reset.cpp | 2 +- src/fix_enforce2d.cpp | 2 +- src/fix_gravity.cpp | 4 ++-- src/fix_indent.cpp | 4 ++-- src/fix_langevin.cpp | 4 ++-- src/fix_lineforce.cpp | 2 +- src/fix_move.cpp | 2 +- src/fix_nh.cpp | 4 ++-- src/fix_numdiff.cpp | 4 ++-- src/fix_nve_limit.cpp | 2 +- src/fix_nve_noforce.cpp | 2 +- src/fix_planeforce.cpp | 2 +- src/fix_restrain.cpp | 4 ++-- src/fix_setforce.cpp | 4 ++-- src/fix_spring.cpp | 4 ++-- src/fix_spring_chunk.cpp | 4 ++-- src/fix_spring_rg.cpp | 4 ++-- src/fix_spring_self.cpp | 4 ++-- src/fix_store_force.cpp | 4 ++-- src/fix_viscous.cpp | 4 ++-- src/fix_wall.cpp | 4 ++-- src/fix_wall_region.cpp | 4 ++-- src/neighbor.cpp | 2 +- src/pair_hybrid.cpp | 2 +- src/pair_lj96_cut.cpp | 4 ++-- src/pair_mie_cut.cpp | 4 ++-- src/run.cpp | 2 +- 123 files changed, 177 insertions(+), 178 deletions(-) diff --git a/src/BODY/fix_wall_body_polygon.cpp b/src/BODY/fix_wall_body_polygon.cpp index 63df8d2a5c..027c0dbd5a 100644 --- a/src/BODY/fix_wall_body_polygon.cpp +++ b/src/BODY/fix_wall_body_polygon.cpp @@ -195,7 +195,7 @@ void FixWallBodyPolygon::init() void FixWallBodyPolygon::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); } diff --git a/src/BODY/fix_wall_body_polyhedron.cpp b/src/BODY/fix_wall_body_polyhedron.cpp index 45edf28c98..acfafaefbe 100644 --- a/src/BODY/fix_wall_body_polyhedron.cpp +++ b/src/BODY/fix_wall_body_polyhedron.cpp @@ -202,7 +202,7 @@ void FixWallBodyPolyhedron::init() void FixWallBodyPolyhedron::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); } diff --git a/src/CLASS2/pair_lj_class2.cpp b/src/CLASS2/pair_lj_class2.cpp index 3727b17493..23b0be7396 100644 --- a/src/CLASS2/pair_lj_class2.cpp +++ b/src/CLASS2/pair_lj_class2.cpp @@ -491,7 +491,7 @@ void PairLJClass2::init_style() int irequest; int respa = 0; - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; } @@ -506,7 +506,7 @@ void PairLJClass2::init_style() // set rRESPA cutoffs - if (strstr(update->integrate_style,"respa") && + if (utils::strmatch(update->integrate_style,"^respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = nullptr; diff --git a/src/CLASS2/pair_lj_class2_coul_long.cpp b/src/CLASS2/pair_lj_class2_coul_long.cpp index 8b4a6bd732..9bebae15c8 100644 --- a/src/CLASS2/pair_lj_class2_coul_long.cpp +++ b/src/CLASS2/pair_lj_class2_coul_long.cpp @@ -671,7 +671,7 @@ void PairLJClass2CoulLong::init_style() int irequest; int respa = 0; - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; } @@ -688,7 +688,7 @@ void PairLJClass2CoulLong::init_style() // set rRESPA cutoffs - if (strstr(update->integrate_style,"respa") && + if (utils::strmatch(update->integrate_style,"^respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = nullptr; diff --git a/src/GPU/fix_gpu.cpp b/src/GPU/fix_gpu.cpp index 9fc3e67e5c..66a3e85941 100644 --- a/src/GPU/fix_gpu.cpp +++ b/src/GPU/fix_gpu.cpp @@ -297,7 +297,7 @@ void FixGPU::setup(int vflag) error->all(FLERR, "Cannot use neigh_modify exclude with GPU neighbor builds"); - if (strstr(update->integrate_style,"verlet")) post_force(vflag); + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { // In setup only, all forces calculated on GPU are put in the outer level ((Respa *) update->integrate)->copy_flevel_f(_nlevels_respa-1); diff --git a/src/GPU/fix_nh_gpu.cpp b/src/GPU/fix_nh_gpu.cpp index 8b57289a50..c41099c6d2 100644 --- a/src/GPU/fix_nh_gpu.cpp +++ b/src/GPU/fix_nh_gpu.cpp @@ -63,7 +63,7 @@ FixNHGPU::~FixNHGPU() void FixNHGPU::setup(int vflag) { FixNH::setup(vflag); - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) _respa_on = 1; else _respa_on = 0; diff --git a/src/GPU/fix_nve_gpu.cpp b/src/GPU/fix_nve_gpu.cpp index c3dd5b6ae2..9c6705deac 100644 --- a/src/GPU/fix_nve_gpu.cpp +++ b/src/GPU/fix_nve_gpu.cpp @@ -52,7 +52,7 @@ FixNVEGPU::~FixNVEGPU() void FixNVEGPU::setup(int vflag) { FixNVE::setup(vflag); - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) _respa_on = 1; else _respa_on = 0; diff --git a/src/GPU/pppm_gpu.cpp b/src/GPU/pppm_gpu.cpp index 61d0144b73..d6a827354c 100644 --- a/src/GPU/pppm_gpu.cpp +++ b/src/GPU/pppm_gpu.cpp @@ -149,7 +149,7 @@ void PPPMGPU::init() // GPU precision specific init bool respa_value=false; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) respa_value=true; if (order>8) diff --git a/src/GRANULAR/fix_freeze.cpp b/src/GRANULAR/fix_freeze.cpp index a343683b03..6a16bbb1f6 100644 --- a/src/GRANULAR/fix_freeze.cpp +++ b/src/GRANULAR/fix_freeze.cpp @@ -69,7 +69,7 @@ void FixFreeze::init() void FixFreeze::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { int nlevels_respa = ((Respa *) update->integrate)->nlevels; diff --git a/src/GRANULAR/fix_wall_gran.cpp b/src/GRANULAR/fix_wall_gran.cpp index d18b72aa65..5e8d568b7a 100644 --- a/src/GRANULAR/fix_wall_gran.cpp +++ b/src/GRANULAR/fix_wall_gran.cpp @@ -464,7 +464,7 @@ void FixWallGran::init() dt = update->dt; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; // check for FixRigid so can extract rigid body masses @@ -511,7 +511,7 @@ void FixWallGran::init() void FixWallGran::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1); diff --git a/src/KOKKOS/fix_setforce_kokkos.cpp b/src/KOKKOS/fix_setforce_kokkos.cpp index 81de089960..30899bf402 100644 --- a/src/KOKKOS/fix_setforce_kokkos.cpp +++ b/src/KOKKOS/fix_setforce_kokkos.cpp @@ -67,7 +67,7 @@ void FixSetForceKokkos::init() { FixSetForce::init(); - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) error->all(FLERR,"Cannot (yet) use respa with Kokkos"); } diff --git a/src/KOKKOS/fix_shake_kokkos.cpp b/src/KOKKOS/fix_shake_kokkos.cpp index 97a2932415..253c7ee7e0 100644 --- a/src/KOKKOS/fix_shake_kokkos.cpp +++ b/src/KOKKOS/fix_shake_kokkos.cpp @@ -156,7 +156,7 @@ void FixShakeKokkos::init() { FixShake::init(); - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) error->all(FLERR,"Cannot yet use respa with Kokkos"); if (rattle) diff --git a/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp b/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp index 1b6139a61a..975c191c3d 100644 --- a/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp +++ b/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp @@ -285,7 +285,7 @@ void PairBuckCoulCutKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_buck_coul_long_kokkos.cpp b/src/KOKKOS/pair_buck_coul_long_kokkos.cpp index 771258f18b..2812abb026 100644 --- a/src/KOKKOS/pair_buck_coul_long_kokkos.cpp +++ b/src/KOKKOS/pair_buck_coul_long_kokkos.cpp @@ -447,7 +447,7 @@ void PairBuckCoulLongKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_buck_kokkos.cpp b/src/KOKKOS/pair_buck_kokkos.cpp index bc25a26ded..b51bde119c 100644 --- a/src/KOKKOS/pair_buck_kokkos.cpp +++ b/src/KOKKOS/pair_buck_kokkos.cpp @@ -205,7 +205,7 @@ void PairBuckKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_coul_long_kokkos.cpp b/src/KOKKOS/pair_coul_long_kokkos.cpp index affdf76ab0..4075108823 100644 --- a/src/KOKKOS/pair_coul_long_kokkos.cpp +++ b/src/KOKKOS/pair_coul_long_kokkos.cpp @@ -405,7 +405,7 @@ void PairCoulLongKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_hybrid_kokkos.cpp b/src/KOKKOS/pair_hybrid_kokkos.cpp index 540a6a368a..5ef2edf1b6 100644 --- a/src/KOKKOS/pair_hybrid_kokkos.cpp +++ b/src/KOKKOS/pair_hybrid_kokkos.cpp @@ -90,7 +90,7 @@ void PairHybridKokkos::compute(int eflag, int vflag) Respa *respa = nullptr; respaflag = 0; - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { respa = (Respa *) update->integrate; if (respa->nhybrid_styles > 0) respaflag = 1; } diff --git a/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.cpp b/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.cpp index b8fcc04b00..a0abce1510 100644 --- a/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.cpp +++ b/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.cpp @@ -450,7 +450,7 @@ void PairLJCharmmCoulCharmmImplicitKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.cpp b/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.cpp index 8391338037..f683204d9d 100644 --- a/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.cpp +++ b/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.cpp @@ -451,7 +451,7 @@ void PairLJCharmmCoulCharmmKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.cpp b/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.cpp index b54e5c96c9..7f9876a76f 100644 --- a/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.cpp +++ b/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.cpp @@ -459,7 +459,7 @@ void PairLJCharmmCoulLongKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp b/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp index 281f29405f..36a15da628 100644 --- a/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp +++ b/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp @@ -287,7 +287,7 @@ void PairLJClass2CoulCutKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_class2_coul_long_kokkos.cpp b/src/KOKKOS/pair_lj_class2_coul_long_kokkos.cpp index de7b04159a..031d025544 100644 --- a/src/KOKKOS/pair_lj_class2_coul_long_kokkos.cpp +++ b/src/KOKKOS/pair_lj_class2_coul_long_kokkos.cpp @@ -442,7 +442,7 @@ void PairLJClass2CoulLongKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_class2_kokkos.cpp b/src/KOKKOS/pair_lj_class2_kokkos.cpp index 12b0c02421..cef3c1f8d8 100644 --- a/src/KOKKOS/pair_lj_class2_kokkos.cpp +++ b/src/KOKKOS/pair_lj_class2_kokkos.cpp @@ -223,7 +223,7 @@ void PairLJClass2Kokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp b/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp index e2bf45c00a..636a72b5e1 100644 --- a/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp +++ b/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp @@ -278,7 +278,7 @@ void PairLJCutCoulCutKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp b/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp index 29eacfa774..8b4e189442 100644 --- a/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp +++ b/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp @@ -307,7 +307,7 @@ void PairLJCutCoulDebyeKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp b/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp index 31380d88a8..cbeb0ab70a 100644 --- a/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp +++ b/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp @@ -300,7 +300,7 @@ void PairLJCutCoulDSFKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_cut_coul_long_kokkos.cpp b/src/KOKKOS/pair_lj_cut_coul_long_kokkos.cpp index 4270238c71..244acc644a 100644 --- a/src/KOKKOS/pair_lj_cut_coul_long_kokkos.cpp +++ b/src/KOKKOS/pair_lj_cut_coul_long_kokkos.cpp @@ -440,7 +440,7 @@ void PairLJCutCoulLongKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_cut_kokkos.cpp b/src/KOKKOS/pair_lj_cut_kokkos.cpp index 2a900dac7a..bffb921490 100644 --- a/src/KOKKOS/pair_lj_cut_kokkos.cpp +++ b/src/KOKKOS/pair_lj_cut_kokkos.cpp @@ -217,7 +217,7 @@ void PairLJCutKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_expand_kokkos.cpp b/src/KOKKOS/pair_lj_expand_kokkos.cpp index 3e6e955f02..d351f2d5fc 100644 --- a/src/KOKKOS/pair_lj_expand_kokkos.cpp +++ b/src/KOKKOS/pair_lj_expand_kokkos.cpp @@ -227,7 +227,7 @@ void PairLJExpandKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.cpp b/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.cpp index ca59ec9d01..fa4a3ca06d 100644 --- a/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.cpp +++ b/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.cpp @@ -436,7 +436,7 @@ void PairLJGromacsCoulGromacsKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_gromacs_kokkos.cpp b/src/KOKKOS/pair_lj_gromacs_kokkos.cpp index c7bcacc778..58fe845b71 100644 --- a/src/KOKKOS/pair_lj_gromacs_kokkos.cpp +++ b/src/KOKKOS/pair_lj_gromacs_kokkos.cpp @@ -272,7 +272,7 @@ void PairLJGromacsKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_lj_sdk_kokkos.cpp b/src/KOKKOS/pair_lj_sdk_kokkos.cpp index b752225902..f8f1fa87cc 100644 --- a/src/KOKKOS/pair_lj_sdk_kokkos.cpp +++ b/src/KOKKOS/pair_lj_sdk_kokkos.cpp @@ -255,7 +255,7 @@ void PairLJSDKKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_morse_kokkos.cpp b/src/KOKKOS/pair_morse_kokkos.cpp index bab19c2f44..74c2934510 100644 --- a/src/KOKKOS/pair_morse_kokkos.cpp +++ b/src/KOKKOS/pair_morse_kokkos.cpp @@ -234,7 +234,7 @@ void PairMorseKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_yukawa_kokkos.cpp b/src/KOKKOS/pair_yukawa_kokkos.cpp index 39e604c9aa..123b0a2d84 100644 --- a/src/KOKKOS/pair_yukawa_kokkos.cpp +++ b/src/KOKKOS/pair_yukawa_kokkos.cpp @@ -107,7 +107,7 @@ void PairYukawaKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KOKKOS/pair_zbl_kokkos.cpp b/src/KOKKOS/pair_zbl_kokkos.cpp index a530b66ee0..954c2edf26 100644 --- a/src/KOKKOS/pair_zbl_kokkos.cpp +++ b/src/KOKKOS/pair_zbl_kokkos.cpp @@ -81,7 +81,7 @@ void PairZBLKokkos::init_style() // error if rRESPA with inner levels - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { int respa = 0; if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; diff --git a/src/KSPACE/pair_buck_long_coul_long.cpp b/src/KSPACE/pair_buck_long_coul_long.cpp index c2c46f359b..f392179152 100644 --- a/src/KSPACE/pair_buck_long_coul_long.cpp +++ b/src/KSPACE/pair_buck_long_coul_long.cpp @@ -248,7 +248,7 @@ void PairBuckLongCoulLong::init_style() // set rRESPA cutoffs - if (strstr(update->integrate_style,"respa") && + if (utils::strmatch(update->integrate_style,"^respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = nullptr; @@ -264,7 +264,7 @@ void PairBuckLongCoulLong::init_style() int irequest; int respa = 0; - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; } diff --git a/src/KSPACE/pair_lj_charmmfsw_coul_long.cpp b/src/KSPACE/pair_lj_charmmfsw_coul_long.cpp index 459eac1687..ea48f0676f 100644 --- a/src/KSPACE/pair_lj_charmmfsw_coul_long.cpp +++ b/src/KSPACE/pair_lj_charmmfsw_coul_long.cpp @@ -740,7 +740,7 @@ void PairLJCharmmfswCoulLong::init_style() int irequest; int respa = 0; - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; } @@ -779,7 +779,7 @@ void PairLJCharmmfswCoulLong::init_style() // set & error check interior rRESPA cutoffs - if (strstr(update->integrate_style,"respa") && + if (utils::strmatch(update->integrate_style,"^respa") && ((Respa *) update->integrate)->level_inner >= 0) { cut_respa = ((Respa *) update->integrate)->cutoff; if (MIN(cut_lj,cut_coul) < cut_respa[3]) diff --git a/src/KSPACE/pair_lj_long_coul_long.cpp b/src/KSPACE/pair_lj_long_coul_long.cpp index 2b34cf7f1b..da3b3c19e0 100644 --- a/src/KSPACE/pair_lj_long_coul_long.cpp +++ b/src/KSPACE/pair_lj_long_coul_long.cpp @@ -242,7 +242,7 @@ void PairLJLongCoulLong::init_style() // set rRESPA cutoffs - if (strstr(update->integrate_style,"respa") && + if (utils::strmatch(update->integrate_style,"^respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = nullptr; @@ -258,7 +258,7 @@ void PairLJLongCoulLong::init_style() int irequest; int respa = 0; - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; } diff --git a/src/MANYBODY/fix_qeq_comb.cpp b/src/MANYBODY/fix_qeq_comb.cpp index 7c2d18fc13..910db90822 100644 --- a/src/MANYBODY/fix_qeq_comb.cpp +++ b/src/MANYBODY/fix_qeq_comb.cpp @@ -138,7 +138,7 @@ void FixQEQComb::init() void FixQEQComb::setup(int vflag) { firstflag = 1; - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/MC/fix_bond_break.cpp b/src/MC/fix_bond_break.cpp index 56da69a7bc..8974b9039f 100644 --- a/src/MC/fix_bond_break.cpp +++ b/src/MC/fix_bond_break.cpp @@ -143,7 +143,7 @@ int FixBondBreak::setmask() void FixBondBreak::init() { - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; // enable angle/dihedral/improper breaking if any defined diff --git a/src/MC/fix_bond_create.cpp b/src/MC/fix_bond_create.cpp index c8c0af3a3e..634837595b 100644 --- a/src/MC/fix_bond_create.cpp +++ b/src/MC/fix_bond_create.cpp @@ -232,7 +232,7 @@ int FixBondCreate::setmask() void FixBondCreate::init() { - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; // check cutoff for iatomtype,jatomtype diff --git a/src/MISC/fix_efield.cpp b/src/MISC/fix_efield.cpp index 1181f554cf..5eb3caf5ea 100644 --- a/src/MISC/fix_efield.cpp +++ b/src/MISC/fix_efield.cpp @@ -209,7 +209,7 @@ void FixEfield::init() update->whichflag == 2 && estyle == NONE) error->all(FLERR,"Must use variable energy with fix efield"); - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -219,7 +219,7 @@ void FixEfield::init() void FixEfield::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/MISC/fix_gld.cpp b/src/MISC/fix_gld.cpp index 3f6c3da258..d0ad26c740 100644 --- a/src/MISC/fix_gld.cpp +++ b/src/MISC/fix_gld.cpp @@ -206,7 +206,7 @@ void FixGLD::init() dtv = update->dt; dtf = 0.5 * update->dt * force->ftm2v; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) step_respa = ((Respa *) update->integrate)->step; } diff --git a/src/MISC/fix_orient_bcc.cpp b/src/MISC/fix_orient_bcc.cpp index 4c6693f729..520940f2f0 100644 --- a/src/MISC/fix_orient_bcc.cpp +++ b/src/MISC/fix_orient_bcc.cpp @@ -202,7 +202,7 @@ int FixOrientBCC::setmask() void FixOrientBCC::init() { - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -228,7 +228,7 @@ void FixOrientBCC::init_list(int /*id*/, NeighList *ptr) void FixOrientBCC::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/MISC/fix_orient_fcc.cpp b/src/MISC/fix_orient_fcc.cpp index a59e412fde..c94e91a0b5 100644 --- a/src/MISC/fix_orient_fcc.cpp +++ b/src/MISC/fix_orient_fcc.cpp @@ -200,7 +200,7 @@ int FixOrientFCC::setmask() void FixOrientFCC::init() { - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -226,7 +226,7 @@ void FixOrientFCC::init_list(int /*id*/, NeighList *ptr) void FixOrientFCC::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/MISC/fix_ttm.cpp b/src/MISC/fix_ttm.cpp index 4658c0c943..da71d736c2 100644 --- a/src/MISC/fix_ttm.cpp +++ b/src/MISC/fix_ttm.cpp @@ -207,7 +207,7 @@ void FixTTM::init() for (int iznode = 0; iznode < nznodes; iznode++) net_energy_transfer_all[ixnode][iynode][iznode] = 0; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } diff --git a/src/MOLECULE/dihedral_charmm.cpp b/src/MOLECULE/dihedral_charmm.cpp index cc60dbec2b..d56c875744 100644 --- a/src/MOLECULE/dihedral_charmm.cpp +++ b/src/MOLECULE/dihedral_charmm.cpp @@ -368,7 +368,7 @@ void DihedralCharmm::coeff(int narg, char **arg) void DihedralCharmm::init_style() { - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { Respa *r = (Respa *) update->integrate; if (r->level_pair >= 0 && (r->level_pair != r->level_dihedral)) error->all(FLERR,"Dihedral style charmm must be set to same" diff --git a/src/MOLECULE/dihedral_charmmfsw.cpp b/src/MOLECULE/dihedral_charmmfsw.cpp index 1164e93f18..09372f67ac 100644 --- a/src/MOLECULE/dihedral_charmmfsw.cpp +++ b/src/MOLECULE/dihedral_charmmfsw.cpp @@ -386,7 +386,7 @@ void DihedralCharmmfsw::coeff(int narg, char **arg) void DihedralCharmmfsw::init_style() { - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { Respa *r = (Respa *) update->integrate; if (r->level_pair >= 0 && (r->level_pair != r->level_dihedral)) error->all(FLERR,"Dihedral style charmmfsw must be set to same" diff --git a/src/POEMS/fix_poems.cpp b/src/POEMS/fix_poems.cpp index bb74e90850..3d5b3697f7 100644 --- a/src/POEMS/fix_poems.cpp +++ b/src/POEMS/fix_poems.cpp @@ -389,7 +389,7 @@ void FixPOEMS::init() // rRESPA info - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { step_respa = ((Respa *) update->integrate)->step; nlevels_respa = ((Respa *) update->integrate)->nlevels; } diff --git a/src/QEQ/fix_qeq_dynamic.cpp b/src/QEQ/fix_qeq_dynamic.cpp index 2bd63b718d..b06bde223b 100644 --- a/src/QEQ/fix_qeq_dynamic.cpp +++ b/src/QEQ/fix_qeq_dynamic.cpp @@ -78,7 +78,7 @@ void FixQEqDynamic::init() error->warning(FLERR,"Fix qeq/dynamic tolerance may be too small" " for damped dynamics"); - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } diff --git a/src/QEQ/fix_qeq_fire.cpp b/src/QEQ/fix_qeq_fire.cpp index 6e51c906bc..b33a7745e0 100644 --- a/src/QEQ/fix_qeq_fire.cpp +++ b/src/QEQ/fix_qeq_fire.cpp @@ -91,7 +91,7 @@ void FixQEqFire::init() error->warning(FLERR,"Fix qeq/fire tolerance may be too small" " for damped fires"); - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; comb = (PairComb *) force->pair_match("comb",1); diff --git a/src/QEQ/fix_qeq_point.cpp b/src/QEQ/fix_qeq_point.cpp index f112c4859f..3d71135ae1 100644 --- a/src/QEQ/fix_qeq_point.cpp +++ b/src/QEQ/fix_qeq_point.cpp @@ -57,7 +57,7 @@ void FixQEqPoint::init() int ntypes = atom->ntypes; memory->create(shld,ntypes+1,ntypes+1,"qeq:shielding"); - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } diff --git a/src/QEQ/fix_qeq_shielded.cpp b/src/QEQ/fix_qeq_shielded.cpp index decfe69ccc..356a747ed3 100644 --- a/src/QEQ/fix_qeq_shielded.cpp +++ b/src/QEQ/fix_qeq_shielded.cpp @@ -68,7 +68,7 @@ void FixQEqShielded::init() error->all(FLERR,"Invalid param file for fix qeq/shielded"); } - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } diff --git a/src/QEQ/fix_qeq_slater.cpp b/src/QEQ/fix_qeq_slater.cpp index 5cab1f1979..9b90f78d7a 100644 --- a/src/QEQ/fix_qeq_slater.cpp +++ b/src/QEQ/fix_qeq_slater.cpp @@ -79,7 +79,7 @@ void FixQEqSlater::init() error->all(FLERR,"Invalid param file for fix qeq/slater"); } - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } diff --git a/src/RIGID/fix_rigid.cpp b/src/RIGID/fix_rigid.cpp index c211e0e4ca..a8a0e1409f 100644 --- a/src/RIGID/fix_rigid.cpp +++ b/src/RIGID/fix_rigid.cpp @@ -750,7 +750,7 @@ void FixRigid::init() dtf = 0.5 * update->dt * force->ftm2v; dtq = 0.5 * update->dt; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) step_respa = ((Respa *) update->integrate)->step; // setup rigid bodies, using current atom info. if reinitflag is not set, diff --git a/src/RIGID/fix_rigid_small.cpp b/src/RIGID/fix_rigid_small.cpp index bdc7330d6d..b7e0a1b2ac 100644 --- a/src/RIGID/fix_rigid_small.cpp +++ b/src/RIGID/fix_rigid_small.cpp @@ -600,7 +600,7 @@ void FixRigidSmall::init() dtf = 0.5 * update->dt * force->ftm2v; dtq = 0.5 * update->dt; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) step_respa = ((Respa *) update->integrate)->step; } diff --git a/src/RIGID/fix_shake.cpp b/src/RIGID/fix_shake.cpp index adef291ed9..390fe88309 100644 --- a/src/RIGID/fix_shake.cpp +++ b/src/RIGID/fix_shake.cpp @@ -456,7 +456,7 @@ void FixShake::setup(int vflag) // set respa to 0 if verlet is used and to 1 otherwise - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) respa = 0; else respa = 1; @@ -2956,7 +2956,7 @@ void FixShake::unpack_forward_comm(int n, int first, double *buf) void FixShake::reset_dt() { - if (strstr(update->integrate_style,"verlet")) { + if (utils::strmatch(update->integrate_style,"^verlet")) { dtv = update->dt; if (rattle) dtfsq = 0.5 * update->dt * update->dt * force->ftm2v; else dtfsq = update->dt * update->dt * force->ftm2v; diff --git a/src/SPIN/fix_precession_spin.cpp b/src/SPIN/fix_precession_spin.cpp index 70ea7e1a09..17b9d3eb22 100644 --- a/src/SPIN/fix_precession_spin.cpp +++ b/src/SPIN/fix_precession_spin.cpp @@ -186,7 +186,7 @@ void FixPrecessionSpin::init() k1ch = k1c/hbar; k2ch = k2c/hbar; - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -225,7 +225,7 @@ void FixPrecessionSpin::init() void FixPrecessionSpin::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/USER-BOCS/fix_bocs.cpp b/src/USER-BOCS/fix_bocs.cpp index 60fb03cdf8..bd217e60a8 100644 --- a/src/USER-BOCS/fix_bocs.cpp +++ b/src/USER-BOCS/fix_bocs.cpp @@ -590,7 +590,7 @@ void FixBocs::init() if (force->kspace) kspace_flag = 1; else kspace_flag = 0; - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { nlevels_respa = ((Respa *) update->integrate)->nlevels; step_respa = ((Respa *) update->integrate)->step; dto = 0.5*step_respa[0]; @@ -1850,7 +1850,7 @@ void FixBocs::reset_dt() // If using respa, then remap is performed in innermost level - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) dto = 0.5*step_respa[0]; if (pstat_flag) diff --git a/src/USER-COLVARS/fix_colvars.cpp b/src/USER-COLVARS/fix_colvars.cpp index 74972a8076..a1b992059e 100644 --- a/src/USER-COLVARS/fix_colvars.cpp +++ b/src/USER-COLVARS/fix_colvars.cpp @@ -412,7 +412,7 @@ void FixColvars::init() if ((me == 0) && (update->whichflag == 2)) error->warning(FLERR,"Using fix colvars with minimization"); - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } @@ -680,7 +680,7 @@ void FixColvars::setup(int vflag) proxy->setup(); // initialize forces - if (strstr(update->integrate_style,"verlet") || (update->whichflag == 2)) + if (utils::strmatch(update->integrate_style,"^verlet") || (update->whichflag == 2)) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1); diff --git a/src/USER-DRUDE/fix_langevin_drude.cpp b/src/USER-DRUDE/fix_langevin_drude.cpp index 2dabec3a30..44d2556b61 100644 --- a/src/USER-DRUDE/fix_langevin_drude.cpp +++ b/src/USER-DRUDE/fix_langevin_drude.cpp @@ -156,7 +156,7 @@ void FixLangevinDrude::init() void FixLangevinDrude::setup(int /*vflag*/) { - if (!strstr(update->integrate_style,"verlet")) + if (!utils::strmatch(update->integrate_style,"^verlet")) error->all(FLERR,"RESPA style not compatible with fix langevin/drude"); if (!comm->ghost_velocity) error->all(FLERR,"fix langevin/drude requires ghost velocities. Use comm_modify vel yes"); diff --git a/src/USER-DRUDE/fix_tgnh_drude.cpp b/src/USER-DRUDE/fix_tgnh_drude.cpp index 49a4061878..d8bf1d76f9 100644 --- a/src/USER-DRUDE/fix_tgnh_drude.cpp +++ b/src/USER-DRUDE/fix_tgnh_drude.cpp @@ -671,7 +671,7 @@ void FixTGNHDrude::init() if (force->kspace) kspace_flag = 1; else kspace_flag = 0; - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { nlevels_respa = ((Respa *) update->integrate)->nlevels; step_respa = ((Respa *) update->integrate)->step; dto = 0.5*step_respa[0]; @@ -1593,7 +1593,7 @@ void FixTGNHDrude::reset_dt() // If using respa, then remap is performed in innermost level - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) dto = 0.5*step_respa[0]; } diff --git a/src/USER-EFF/fix_nve_eff.cpp b/src/USER-EFF/fix_nve_eff.cpp index 58acdcc258..bfdd85df49 100644 --- a/src/USER-EFF/fix_nve_eff.cpp +++ b/src/USER-EFF/fix_nve_eff.cpp @@ -58,7 +58,7 @@ void FixNVEEff::init() dtv = update->dt; dtf = 0.5 * update->dt * force->ftm2v; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) step_respa = ((Respa *) update->integrate)->step; } diff --git a/src/USER-FEP/fix_adapt_fep.cpp b/src/USER-FEP/fix_adapt_fep.cpp index c8a65539b4..7f17179087 100644 --- a/src/USER-FEP/fix_adapt_fep.cpp +++ b/src/USER-FEP/fix_adapt_fep.cpp @@ -356,7 +356,7 @@ void FixAdaptFEP::init() fix_chg = (FixStore *) modify->fix[ifix]; } - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } diff --git a/src/USER-INTEL/fix_nh_intel.cpp b/src/USER-INTEL/fix_nh_intel.cpp index 19245cccbf..6105892041 100644 --- a/src/USER-INTEL/fix_nh_intel.cpp +++ b/src/USER-INTEL/fix_nh_intel.cpp @@ -317,7 +317,7 @@ void FixNHIntel::reset_dt() // If using respa, then remap is performed in innermost level - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) dto = 0.5*step_respa[0]; if (pstat_flag) diff --git a/src/USER-LB/fix_lb_viscous.cpp b/src/USER-LB/fix_lb_viscous.cpp index 08a0a10356..a13fea3a1a 100644 --- a/src/USER-LB/fix_lb_viscous.cpp +++ b/src/USER-LB/fix_lb_viscous.cpp @@ -79,7 +79,7 @@ int FixLbViscous::setmask() void FixLbViscous::init() { - if (strcmp(update->integrate_style,"respa") == 0) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } @@ -88,7 +88,7 @@ void FixLbViscous::init() void FixLbViscous::setup(int vflag) { - if (strstr(update->integrate_style,"verlet") != nullptr) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1); diff --git a/src/USER-MANIFOLD/fix_manifoldforce.cpp b/src/USER-MANIFOLD/fix_manifoldforce.cpp index 26d209e7a9..b48decddba 100644 --- a/src/USER-MANIFOLD/fix_manifoldforce.cpp +++ b/src/USER-MANIFOLD/fix_manifoldforce.cpp @@ -120,7 +120,7 @@ void FixManifoldForce::init() void FixManifoldForce::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { int nlevels_respa = ((Respa *) update->integrate)->nlevels; diff --git a/src/USER-MISC/fix_addtorque.cpp b/src/USER-MISC/fix_addtorque.cpp index b19f51a10b..59f2560e0b 100644 --- a/src/USER-MISC/fix_addtorque.cpp +++ b/src/USER-MISC/fix_addtorque.cpp @@ -130,7 +130,7 @@ void FixAddTorque::init() varflag = EQUAL; else varflag = CONSTANT; - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -140,7 +140,7 @@ void FixAddTorque::init() void FixAddTorque::setup(int vflag) { - if (strcmp(update->integrate_style,"verlet") == 0) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/USER-MISC/fix_electron_stopping_fit.cpp b/src/USER-MISC/fix_electron_stopping_fit.cpp index 2d9034aaef..8768ed5f3d 100644 --- a/src/USER-MISC/fix_electron_stopping_fit.cpp +++ b/src/USER-MISC/fix_electron_stopping_fit.cpp @@ -140,7 +140,7 @@ void FixElectronStoppingFit::init() void FixElectronStoppingFit::setup(int vflag) { - if (strcmp(update->integrate_style,"verlet") == 0) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1); diff --git a/src/USER-MISC/fix_ffl.cpp b/src/USER-MISC/fix_ffl.cpp index eb9f033afc..6dfa9eb2ca 100644 --- a/src/USER-MISC/fix_ffl.cpp +++ b/src/USER-MISC/fix_ffl.cpp @@ -156,7 +156,7 @@ void FixFFL::init() { } } - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { nlevels_respa = ((Respa *) update->integrate)->nlevels; step_respa = ((Respa *) update->integrate)->step; } @@ -178,7 +178,7 @@ void FixFFL::init_ffl() { /* ---------------------------------------------------------------------- */ void FixFFL::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1); diff --git a/src/USER-MISC/fix_filter_corotate.cpp b/src/USER-MISC/fix_filter_corotate.cpp index 38b22c1189..6e6dce84a7 100644 --- a/src/USER-MISC/fix_filter_corotate.cpp +++ b/src/USER-MISC/fix_filter_corotate.cpp @@ -277,7 +277,7 @@ void FixFilterCorotate::init() // could have changed locations in fix list since created // set ptrs to rRESPA variables - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { nlevels_respa = ((Respa *) update->integrate)->nlevels; } else error->all(FLERR,"Fix filter/corotate requires rRESPA!"); diff --git a/src/USER-MISC/fix_flow_gauss.cpp b/src/USER-MISC/fix_flow_gauss.cpp index 3c913f8039..9e6a2c0174 100644 --- a/src/USER-MISC/fix_flow_gauss.cpp +++ b/src/USER-MISC/fix_flow_gauss.cpp @@ -123,7 +123,7 @@ void FixFlowGauss::init() { //if respa level specified by fix_modify, then override default (outermost) //if specified level too high, set to max level - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); @@ -146,7 +146,7 @@ void FixFlowGauss::setup(int vflag) if (mTot <= 0.0) error->all(FLERR,"Invalid group mass in fix flow/gauss"); - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); post_force_respa(vflag,ilevel_respa,0); ((Respa *) update->integrate)->copy_f_flevel(ilevel_respa); diff --git a/src/USER-MISC/fix_gle.cpp b/src/USER-MISC/fix_gle.cpp index a83ab0f9ce..8a7459b79d 100644 --- a/src/USER-MISC/fix_gle.cpp +++ b/src/USER-MISC/fix_gle.cpp @@ -416,7 +416,7 @@ void FixGLE::init() } } - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { nlevels_respa = ((Respa *) update->integrate)->nlevels; step_respa = ((Respa *) update->integrate)->step; } @@ -502,7 +502,7 @@ void FixGLE::init_gles() void FixGLE::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1); diff --git a/src/USER-MISC/fix_grem.cpp b/src/USER-MISC/fix_grem.cpp index 64c7e4a6b7..e036eff205 100644 --- a/src/USER-MISC/fix_grem.cpp +++ b/src/USER-MISC/fix_grem.cpp @@ -200,10 +200,10 @@ void FixGrem::init() void FixGrem::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) error->all(FLERR,"Run style 'respa' is not supported"); } diff --git a/src/USER-MISC/fix_imd.cpp b/src/USER-MISC/fix_imd.cpp index 8796de289e..f9591db4d3 100644 --- a/src/USER-MISC/fix_imd.cpp +++ b/src/USER-MISC/fix_imd.cpp @@ -601,7 +601,7 @@ int FixIMD::setmask() /* ---------------------------------------------------------------------- */ void FixIMD::init() { - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; return; diff --git a/src/USER-MISC/fix_npt_cauchy.cpp b/src/USER-MISC/fix_npt_cauchy.cpp index 37d6e5286b..802cabea67 100644 --- a/src/USER-MISC/fix_npt_cauchy.cpp +++ b/src/USER-MISC/fix_npt_cauchy.cpp @@ -765,7 +765,7 @@ void FixNPTCauchy::init() if (force->kspace) kspace_flag = 1; else kspace_flag = 0; - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { nlevels_respa = ((Respa *) update->integrate)->nlevels; step_respa = ((Respa *) update->integrate)->step; dto = 0.5*step_respa[0]; @@ -1752,7 +1752,7 @@ void FixNPTCauchy::reset_dt() // If using respa, then remap is performed in innermost level - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) dto = 0.5*step_respa[0]; if (pstat_flag) diff --git a/src/USER-MISC/fix_nvk.cpp b/src/USER-MISC/fix_nvk.cpp index d21f4efe4e..ef6c390f95 100644 --- a/src/USER-MISC/fix_nvk.cpp +++ b/src/USER-MISC/fix_nvk.cpp @@ -59,7 +59,7 @@ void FixNVK::init() dtv = update->dt; dtf = 0.5 * update->dt; - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { error->all(FLERR,"Fix nvk not yet enabled for RESPA"); step_respa = ((Respa *) update->integrate)->step; } diff --git a/src/USER-MISC/fix_orient_eco.cpp b/src/USER-MISC/fix_orient_eco.cpp index 3d6db4cd4f..56da3cd6a1 100644 --- a/src/USER-MISC/fix_orient_eco.cpp +++ b/src/USER-MISC/fix_orient_eco.cpp @@ -177,7 +177,7 @@ void FixOrientECO::init() { MPI_Bcast(&norm_fac, 1, MPI_DOUBLE, 0, world); MPI_Bcast(&inv_norm_fac, 1, MPI_DOUBLE, 0, world); - if (strstr(update->integrate_style, "respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels - 1; if (respa_level >= 0) ilevel_respa = MIN(respa_level, ilevel_respa); } @@ -201,7 +201,7 @@ void FixOrientECO::init_list(int /* id */, NeighList *ptr) { /* ---------------------------------------------------------------------- */ void FixOrientECO::setup(int vflag) { - if (strstr(update->integrate_style, "verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/USER-MISC/fix_pafi.cpp b/src/USER-MISC/fix_pafi.cpp index c2ad62d7d0..7d5216f540 100644 --- a/src/USER-MISC/fix_pafi.cpp +++ b/src/USER-MISC/fix_pafi.cpp @@ -180,7 +180,7 @@ void FixPAFI::init() error->all(FLERR,"Compute for fix pafi must have 9 fields per atom"); - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { step_respa = ((Respa *) update->integrate)->step; // nve nlevels_respa = ((Respa *) update->integrate)->nlevels; if (respa_level >= 0) ilevel_respa = MIN(respa_level,nlevels_respa-1); @@ -191,7 +191,7 @@ void FixPAFI::init() void FixPAFI::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else for (int ilevel = 0; ilevel < nlevels_respa; ilevel++) { diff --git a/src/USER-MISC/fix_rhok.cpp b/src/USER-MISC/fix_rhok.cpp index f546b9a814..18e1ed195f 100644 --- a/src/USER-MISC/fix_rhok.cpp +++ b/src/USER-MISC/fix_rhok.cpp @@ -95,7 +95,7 @@ int FixRhok::setmask() void FixRhok::init() { // RESPA boilerplate - if (strcmp( update->integrate_style, "respa" ) == 0) + if (utils::strmatch(update->integrate_style,"^respa")) mNLevelsRESPA = ((Respa *) update->integrate)->nlevels; // Count the number of affected particles @@ -117,7 +117,7 @@ void FixRhok::init() // Initial application of the fix to a system (when doing MD) void FixRhok::setup( int inVFlag ) { - if (strcmp( update->integrate_style, "verlet" ) == 0) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force( inVFlag ); else { diff --git a/src/USER-MISC/fix_smd.cpp b/src/USER-MISC/fix_smd.cpp index 8ea1beac71..bc8ede4a17 100644 --- a/src/USER-MISC/fix_smd.cpp +++ b/src/USER-MISC/fix_smd.cpp @@ -159,7 +159,7 @@ void FixSMD::init() zn = dz/r_old; } - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -169,7 +169,7 @@ void FixSMD::init() void FixSMD::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); @@ -190,7 +190,7 @@ void FixSMD::post_force(int vflag) else smd_couple(); if (styleflag & SMD_CVEL) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) r_old += v_smd * update->dt; else r_old += v_smd * ((Respa *) update->integrate)->step[ilevel_respa]; @@ -205,7 +205,7 @@ void FixSMD::smd_tether() group->xcm(igroup,masstotal,xcm); double dt = update->dt; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) dt = ((Respa *) update->integrate)->step[ilevel_respa]; // fx,fy,fz = components of k * (r-r0) @@ -311,7 +311,7 @@ void FixSMD::smd_couple() group->xcm(igroup2,masstotal2,xcm2); double dt = update->dt; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) dt = ((Respa *) update->integrate)->step[ilevel_respa]; // renormalize direction of spring diff --git a/src/USER-MISC/fix_ti_spring.cpp b/src/USER-MISC/fix_ti_spring.cpp index 766b9df5eb..1d6079d4d6 100644 --- a/src/USER-MISC/fix_ti_spring.cpp +++ b/src/USER-MISC/fix_ti_spring.cpp @@ -141,7 +141,7 @@ int FixTISpring::setmask() void FixTISpring::init() { - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } @@ -149,7 +149,7 @@ void FixTISpring::init() void FixTISpring::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1); diff --git a/src/USER-MISC/fix_ttm_mod.cpp b/src/USER-MISC/fix_ttm_mod.cpp index 7056ad6a00..d4023b6011 100644 --- a/src/USER-MISC/fix_ttm_mod.cpp +++ b/src/USER-MISC/fix_ttm_mod.cpp @@ -230,7 +230,7 @@ void FixTTMMod::init() for (int iznode = 0; iznode < nznodes; iznode++) net_energy_transfer_all[ixnode][iynode][iznode] = 0; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } diff --git a/src/USER-MISC/fix_wall_region_ees.cpp b/src/USER-MISC/fix_wall_region_ees.cpp index 51e0af9dc4..8a79b73034 100644 --- a/src/USER-MISC/fix_wall_region_ees.cpp +++ b/src/USER-MISC/fix_wall_region_ees.cpp @@ -118,7 +118,7 @@ void FixWallRegionEES::init() offset = 0; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } @@ -126,7 +126,7 @@ void FixWallRegionEES::init() void FixWallRegionEES::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1); diff --git a/src/USER-MISC/pair_lj_expand_coul_long.cpp b/src/USER-MISC/pair_lj_expand_coul_long.cpp index f49d181e0f..84eb86aaa8 100644 --- a/src/USER-MISC/pair_lj_expand_coul_long.cpp +++ b/src/USER-MISC/pair_lj_expand_coul_long.cpp @@ -690,7 +690,7 @@ void PairLJExpandCoulLong::init_style() int irequest; int respa = 0; - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; } @@ -707,7 +707,7 @@ void PairLJExpandCoulLong::init_style() // set rRESPA cutoffs - if (strstr(update->integrate_style,"respa") && + if (utils::strmatch(update->integrate_style,"^respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = nullptr; diff --git a/src/USER-OMP/fix_omp.cpp b/src/USER-OMP/fix_omp.cpp index 23671f4c7e..678df7c22a 100644 --- a/src/USER-OMP/fix_omp.cpp +++ b/src/USER-OMP/fix_omp.cpp @@ -203,9 +203,8 @@ void FixOMP::init() thr[i]->_timer_active=-1; } - if ((strstr(update->integrate_style,"respa") != nullptr) - && (strstr(update->integrate_style,"respa/omp") == nullptr)) - error->all(FLERR,"Need to use respa/omp for r-RESPA with /omp styles"); + if (!utils::strmatch(update->integrate_style,"^respa/omp")) + error->all(FLERR,"Must use respa/omp for r-RESPA with /omp styles"); if (force->pair && force->pair->compute_flag) _pair_compute_flag = true; else _pair_compute_flag = false; diff --git a/src/USER-OMP/fix_qeq_comb_omp.cpp b/src/USER-OMP/fix_qeq_comb_omp.cpp index aceff62ebc..6844729e92 100644 --- a/src/USER-OMP/fix_qeq_comb_omp.cpp +++ b/src/USER-OMP/fix_qeq_comb_omp.cpp @@ -58,7 +58,7 @@ void FixQEQCombOMP::init() error->all(FLERR,"Must use pair_style comb or " "comb/omp with fix qeq/comb/omp"); - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } diff --git a/src/USER-QMMM/fix_qmmm.cpp b/src/USER-QMMM/fix_qmmm.cpp index 6689ebdb9d..fab658f8f2 100644 --- a/src/USER-QMMM/fix_qmmm.cpp +++ b/src/USER-QMMM/fix_qmmm.cpp @@ -651,7 +651,7 @@ void FixQMMM::exchange_forces() void FixQMMM::init() { - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) error->all(FLERR,"Fix qmmm does not currently support r-RESPA"); if (do_init) { diff --git a/src/USER-QTB/fix_qtb.cpp b/src/USER-QTB/fix_qtb.cpp index e4e645a1bb..a4f6e8678f 100644 --- a/src/USER-QTB/fix_qtb.cpp +++ b/src/USER-QTB/fix_qtb.cpp @@ -216,7 +216,7 @@ void FixQTB::init() } // respa - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } @@ -225,7 +225,7 @@ void FixQTB::init() ------------------------------------------------------------------------- */ void FixQTB::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1); diff --git a/src/USER-REAXC/fix_qeq_reax.cpp b/src/USER-REAXC/fix_qeq_reax.cpp index 44088043f0..3109950ff2 100644 --- a/src/USER-REAXC/fix_qeq_reax.cpp +++ b/src/USER-REAXC/fix_qeq_reax.cpp @@ -370,7 +370,7 @@ void FixQEqReax::init() init_shielding(); init_taper(); - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } diff --git a/src/USER-SMD/fix_smd_setvel.cpp b/src/USER-SMD/fix_smd_setvel.cpp index 471159ea53..312deb4d19 100644 --- a/src/USER-SMD/fix_smd_setvel.cpp +++ b/src/USER-SMD/fix_smd_setvel.cpp @@ -208,7 +208,7 @@ void FixSMDSetVel::init() { /* ---------------------------------------------------------------------- */ void FixSMDSetVel::setup(int vflag) { - if (strstr(update->integrate_style, "verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else error->all(FLERR,"Fix smd/setvel does not support RESPA"); diff --git a/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp b/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp index 556d303d30..c1bf0a308d 100644 --- a/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp +++ b/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp @@ -338,7 +338,7 @@ void PairLJSwitch3CoulGaussLong::init_style() int irequest; int respa = 0; - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; } @@ -355,7 +355,7 @@ void PairLJSwitch3CoulGaussLong::init_style() // set rRESPA cutoffs - if (strstr(update->integrate_style,"respa") && + if (utils::strmatch(update->integrate_style,"^respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = nullptr; diff --git a/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp b/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp index 47ddf8c7ad..187778bb66 100644 --- a/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp +++ b/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp @@ -340,7 +340,7 @@ void PairMM3Switch3CoulGaussLong::init_style() int irequest; int respa = 0; - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; } @@ -357,7 +357,7 @@ void PairMM3Switch3CoulGaussLong::init_style() // set rRESPA cutoffs - if (strstr(update->integrate_style,"respa") && + if (utils::strmatch(update->integrate_style,"^respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = nullptr; diff --git a/src/fix_adapt.cpp b/src/fix_adapt.cpp index c09b6481f6..51fdb16d5d 100644 --- a/src/fix_adapt.cpp +++ b/src/fix_adapt.cpp @@ -462,7 +462,7 @@ void FixAdapt::init() fix_chg = (FixStore *) modify->fix[ifix]; } - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } diff --git a/src/fix_aveforce.cpp b/src/fix_aveforce.cpp index 5ce50aafea..867643499a 100644 --- a/src/fix_aveforce.cpp +++ b/src/fix_aveforce.cpp @@ -155,7 +155,7 @@ void FixAveForce::init() if (xstyle == EQUAL || ystyle == EQUAL || zstyle == EQUAL) varflag = EQUAL; else varflag = CONSTANT; - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { nlevels_respa = ((Respa *) update->integrate)->nlevels; if (respa_level >= 0) ilevel_respa = MIN(respa_level,nlevels_respa-1); else ilevel_respa = nlevels_respa-1; @@ -166,7 +166,7 @@ void FixAveForce::init() void FixAveForce::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else for (int ilevel = 0; ilevel < nlevels_respa; ilevel++) { diff --git a/src/fix_drag.cpp b/src/fix_drag.cpp index 40b8af7f9a..03209ce729 100644 --- a/src/fix_drag.cpp +++ b/src/fix_drag.cpp @@ -69,7 +69,7 @@ int FixDrag::setmask() void FixDrag::init() { - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -79,7 +79,7 @@ void FixDrag::init() void FixDrag::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/fix_dt_reset.cpp b/src/fix_dt_reset.cpp index 336911e8c7..34cecc45de 100644 --- a/src/fix_dt_reset.cpp +++ b/src/fix_dt_reset.cpp @@ -112,7 +112,7 @@ void FixDtReset::init() // set rRESPA flag respaflag = 0; - if (strstr(update->integrate_style,"respa")) respaflag = 1; + if (utils::strmatch(update->integrate_style,"^respa")) respaflag = 1; // check for DCD or XTC dumps diff --git a/src/fix_enforce2d.cpp b/src/fix_enforce2d.cpp index c1b8285a4b..1284a9b78c 100644 --- a/src/fix_enforce2d.cpp +++ b/src/fix_enforce2d.cpp @@ -90,7 +90,7 @@ void FixEnforce2D::init() void FixEnforce2D::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { int nlevels_respa = ((Respa *) update->integrate)->nlevels; diff --git a/src/fix_gravity.cpp b/src/fix_gravity.cpp index 194f5731bc..8c6baab1ee 100644 --- a/src/fix_gravity.cpp +++ b/src/fix_gravity.cpp @@ -181,7 +181,7 @@ int FixGravity::setmask() void FixGravity::init() { - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -243,7 +243,7 @@ void FixGravity::init() void FixGravity::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/fix_indent.cpp b/src/fix_indent.cpp index 48355446d1..d2a7ba0d2a 100644 --- a/src/fix_indent.cpp +++ b/src/fix_indent.cpp @@ -153,7 +153,7 @@ void FixIndent::init() error->all(FLERR,"Variable for fix indent is not equal style"); } - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -163,7 +163,7 @@ void FixIndent::init() void FixIndent::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/fix_langevin.cpp b/src/fix_langevin.cpp index 66da7a9633..bf9d5cad23 100644 --- a/src/fix_langevin.cpp +++ b/src/fix_langevin.cpp @@ -310,7 +310,7 @@ void FixLangevin::init() if (temperature && temperature->tempbias) tbiasflag = BIAS; else tbiasflag = NOBIAS; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; if (utils::strmatch(update->integrate_style,"^respa") && gjfflag) @@ -367,7 +367,7 @@ void FixLangevin::setup(int vflag) } } } - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1); diff --git a/src/fix_lineforce.cpp b/src/fix_lineforce.cpp index 9582d8db51..6a77442ea4 100644 --- a/src/fix_lineforce.cpp +++ b/src/fix_lineforce.cpp @@ -59,7 +59,7 @@ int FixLineForce::setmask() void FixLineForce::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { int nlevels_respa = ((Respa *) update->integrate)->nlevels; diff --git a/src/fix_move.cpp b/src/fix_move.cpp index e37fe52cc9..6b640cd747 100644 --- a/src/fix_move.cpp +++ b/src/fix_move.cpp @@ -433,7 +433,7 @@ void FixMove::init() if (velocityflag) memory->create(velocity,maxatom,3,"move:velocity"); else velocity = nullptr; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } diff --git a/src/fix_nh.cpp b/src/fix_nh.cpp index 120aeeb7de..d95763f06b 100644 --- a/src/fix_nh.cpp +++ b/src/fix_nh.cpp @@ -728,7 +728,7 @@ void FixNH::init() if (force->kspace) kspace_flag = 1; else kspace_flag = 0; - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { nlevels_respa = ((Respa *) update->integrate)->nlevels; step_respa = ((Respa *) update->integrate)->step; dto = 0.5*step_respa[0]; @@ -1722,7 +1722,7 @@ void FixNH::reset_dt() // If using respa, then remap is performed in innermost level - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) dto = 0.5*step_respa[0]; if (pstat_flag) diff --git a/src/fix_numdiff.cpp b/src/fix_numdiff.cpp index 10926ec440..495e196749 100644 --- a/src/fix_numdiff.cpp +++ b/src/fix_numdiff.cpp @@ -120,7 +120,7 @@ void FixNumDiff::init() if (force->kspace && force->kspace->compute_flag) kspace_compute_flag = 1; else kspace_compute_flag = 0; - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -130,7 +130,7 @@ void FixNumDiff::init() void FixNumDiff::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/fix_nve_limit.cpp b/src/fix_nve_limit.cpp index 7ee0e6f80e..58db5e25d9 100644 --- a/src/fix_nve_limit.cpp +++ b/src/fix_nve_limit.cpp @@ -66,7 +66,7 @@ void FixNVELimit::init() vlimitsq = (xlimit/dtv) * (xlimit/dtv); ncount = 0; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) step_respa = ((Respa *) update->integrate)->step; // warn if using fix shake, which will lead to invalid constraint forces diff --git a/src/fix_nve_noforce.cpp b/src/fix_nve_noforce.cpp index 3a9c1c6442..61528a0024 100644 --- a/src/fix_nve_noforce.cpp +++ b/src/fix_nve_noforce.cpp @@ -47,7 +47,7 @@ void FixNVENoforce::init() { dtv = update->dt; - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) step_respa = ((Respa *) update->integrate)->step; } diff --git a/src/fix_planeforce.cpp b/src/fix_planeforce.cpp index cc0b43054a..783d26ac9e 100644 --- a/src/fix_planeforce.cpp +++ b/src/fix_planeforce.cpp @@ -59,7 +59,7 @@ int FixPlaneForce::setmask() void FixPlaneForce::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { int nlevels_respa = ((Respa *) update->integrate)->nlevels; diff --git a/src/fix_restrain.cpp b/src/fix_restrain.cpp index 82e91c8289..ff61703c1a 100644 --- a/src/fix_restrain.cpp +++ b/src/fix_restrain.cpp @@ -185,7 +185,7 @@ int FixRestrain::setmask() void FixRestrain::init() { - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -195,7 +195,7 @@ void FixRestrain::init() void FixRestrain::setup(int vflag) { - if (strcmp(update->integrate_style,"verlet") == 0) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/fix_setforce.cpp b/src/fix_setforce.cpp index 7d41b428c9..d59d091f42 100644 --- a/src/fix_setforce.cpp +++ b/src/fix_setforce.cpp @@ -166,7 +166,7 @@ void FixSetForce::init() varflag = EQUAL; else varflag = CONSTANT; - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { nlevels_respa = ((Respa *) update->integrate)->nlevels; if (respa_level >= 0) ilevel_respa = MIN(respa_level,nlevels_respa-1); else ilevel_respa = nlevels_respa-1; @@ -192,7 +192,7 @@ void FixSetForce::init() void FixSetForce::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else for (int ilevel = 0; ilevel < nlevels_respa; ilevel++) { diff --git a/src/fix_spring.cpp b/src/fix_spring.cpp index 89d569fc8b..200d9f072a 100644 --- a/src/fix_spring.cpp +++ b/src/fix_spring.cpp @@ -128,7 +128,7 @@ void FixSpring::init() masstotal = group->mass(igroup); if (styleflag == COUPLE) masstotal2 = group->mass(igroup2); - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -138,7 +138,7 @@ void FixSpring::init() void FixSpring::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/fix_spring_chunk.cpp b/src/fix_spring_chunk.cpp index 8eb35e74aa..a007aabefc 100644 --- a/src/fix_spring_chunk.cpp +++ b/src/fix_spring_chunk.cpp @@ -112,7 +112,7 @@ void FixSpringChunk::init() if (strcmp(idchunk,ccom->idchunk) != 0) error->all(FLERR,"Fix spring chunk chunkID not same as comID chunkID"); - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -122,7 +122,7 @@ void FixSpringChunk::init() void FixSpringChunk::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/fix_spring_rg.cpp b/src/fix_spring_rg.cpp index cabdc4b11f..58249bbd2d 100644 --- a/src/fix_spring_rg.cpp +++ b/src/fix_spring_rg.cpp @@ -77,7 +77,7 @@ void FixSpringRG::init() rg0_flag = 0; } - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -87,7 +87,7 @@ void FixSpringRG::init() void FixSpringRG::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/fix_spring_self.cpp b/src/fix_spring_self.cpp index 7a22cbd3f8..9f649faec0 100644 --- a/src/fix_spring_self.cpp +++ b/src/fix_spring_self.cpp @@ -120,7 +120,7 @@ int FixSpringSelf::setmask() void FixSpringSelf::init() { - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -130,7 +130,7 @@ void FixSpringSelf::init() void FixSpringSelf::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/fix_store_force.cpp b/src/fix_store_force.cpp index 460422aee9..1541294f6c 100644 --- a/src/fix_store_force.cpp +++ b/src/fix_store_force.cpp @@ -68,7 +68,7 @@ int FixStoreForce::setmask() void FixStoreForce::init() { - if (strstr(update->integrate_style,"respa")) + if (utils::strmatch(update->integrate_style,"^respa")) nlevels_respa = ((Respa *) update->integrate)->nlevels; } @@ -76,7 +76,7 @@ void FixStoreForce::init() void FixStoreForce::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1); diff --git a/src/fix_viscous.cpp b/src/fix_viscous.cpp index 7bdac6aeaf..0c7d682ae2 100644 --- a/src/fix_viscous.cpp +++ b/src/fix_viscous.cpp @@ -80,7 +80,7 @@ void FixViscous::init() { int max_respa = 0; - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = max_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,max_respa); } @@ -90,7 +90,7 @@ void FixViscous::init() void FixViscous::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/fix_wall.cpp b/src/fix_wall.cpp index 677085854c..280ce848c6 100644 --- a/src/fix_wall.cpp +++ b/src/fix_wall.cpp @@ -263,7 +263,7 @@ void FixWall::init() for (int m = 0; m < nwall; m++) precompute(m); - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -273,7 +273,7 @@ void FixWall::init() void FixWall::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) { + if (utils::strmatch(update->integrate_style,"^verlet")) { if (!fldflag) post_force(vflag); } else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/fix_wall_region.cpp b/src/fix_wall_region.cpp index 7e30fe2361..e5c9167ce4 100644 --- a/src/fix_wall_region.cpp +++ b/src/fix_wall_region.cpp @@ -187,7 +187,7 @@ void FixWallRegion::init() offset = coeff3*r4inv*r4inv*rinv - coeff4*r2inv*rinv; } - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { ilevel_respa = ((Respa *) update->integrate)->nlevels-1; if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); } @@ -197,7 +197,7 @@ void FixWallRegion::init() void FixWallRegion::setup(int vflag) { - if (strstr(update->integrate_style,"verlet")) + if (utils::strmatch(update->integrate_style,"^verlet")) post_force(vflag); else { ((Respa *) update->integrate)->copy_flevel_f(ilevel_respa); diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 68fa3ca96e..fb0a244cc0 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -319,7 +319,7 @@ void Neighbor::init() // rRESPA cutoffs int respa = 0; - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; } diff --git a/src/pair_hybrid.cpp b/src/pair_hybrid.cpp index 377364b8e5..c7b6048139 100644 --- a/src/pair_hybrid.cpp +++ b/src/pair_hybrid.cpp @@ -114,7 +114,7 @@ void PairHybrid::compute(int eflag, int vflag) Respa *respa = nullptr; respaflag = 0; - if (strstr(update->integrate_style,"respa")) { + if (utils::strmatch(update->integrate_style,"^respa")) { respa = (Respa *) update->integrate; if (respa->nhybrid_styles > 0) respaflag = 1; } diff --git a/src/pair_lj96_cut.cpp b/src/pair_lj96_cut.cpp index b68d595098..65f2d40e00 100644 --- a/src/pair_lj96_cut.cpp +++ b/src/pair_lj96_cut.cpp @@ -490,7 +490,7 @@ void PairLJ96Cut::init_style() int irequest; int respa = 0; - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; } @@ -505,7 +505,7 @@ void PairLJ96Cut::init_style() // set rRESPA cutoffs - if (strstr(update->integrate_style,"respa") && + if (utils::strmatch(update->integrate_style,"^respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = nullptr; diff --git a/src/pair_mie_cut.cpp b/src/pair_mie_cut.cpp index 043ad3aeaa..503ed60d1b 100644 --- a/src/pair_mie_cut.cpp +++ b/src/pair_mie_cut.cpp @@ -499,7 +499,7 @@ void PairMIECut::init_style() int irequest; int respa = 0; - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { + if (update->whichflag == 1 && utils::strmatch(update->integrate_style,"^respa")) { if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; } @@ -514,7 +514,7 @@ void PairMIECut::init_style() // set rRESPA cutoffs - if (strstr(update->integrate_style,"respa") && + if (utils::strmatch(update->integrate_style,"^respa") && ((Respa *) update->integrate)->level_inner >= 0) cut_respa = ((Respa *) update->integrate)->cutoff; else cut_respa = nullptr; diff --git a/src/run.cpp b/src/run.cpp index fedf020d9d..c503e174ff 100644 --- a/src/run.cpp +++ b/src/run.cpp @@ -134,7 +134,7 @@ void Run::command(int narg, char **arg) error->all(FLERR,"Run command stop value is before end of run"); } - if (!preflag && strstr(update->integrate_style,"respa")) + if (!preflag && utils::strmatch(update->integrate_style,"^respa")) error->all(FLERR,"Run flag 'pre no' not compatible with r-RESPA"); // if nevery, make copies of arg strings that are commands From 7092a7769c8cce2dd9e81aa6381cf2c2af72882c Mon Sep 17 00:00:00 2001 From: Bhanuday Sharma <55601693+bhanudaysharma@users.noreply.github.com> Date: Wed, 31 Mar 2021 06:44:52 +0530 Subject: [PATCH 197/257] Update units.rst In LJ units, the conversion formula between rho and rho* should be corrected to \rho^* = \rho \frac{\sigma^{dim}}{m} --- doc/src/units.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/units.rst b/doc/src/units.rst index 8ca29f4c49..3c0f4a220a 100644 --- a/doc/src/units.rst +++ b/doc/src/units.rst @@ -87,7 +87,7 @@ energy is a derived unit (in SI units you equivalently have the relation * charge = reduced LJ charge, where :math:`q^* = q \frac{1}{\sqrt{4 \pi \varepsilon_0 \sigma \epsilon}}` * dipole = reduced LJ dipole, moment where :math:`\mu^* = \mu \frac{1}{\sqrt{4 \pi \varepsilon_0 \sigma^3 \epsilon}}` * electric field = force/charge, where :math:`E^* = E \frac{\sqrt{4 \pi \varepsilon_0 \sigma \epsilon} \sigma}{\epsilon}` -* density = mass/volume, where :math:`\rho^* = \rho \sigma^{dim}` +* density = mass/volume, where :math:`\rho^* = \rho \frac{\sigma^{dim}}{m}` Note that for LJ units, the default mode of thermodynamic output via the :doc:`thermo_style ` command is to normalize all From e1cf6a312fabb721d7ee7103c619064e2e532ddd Mon Sep 17 00:00:00 2001 From: Oliver Henrich Date: Wed, 31 Mar 2021 18:56:50 +0100 Subject: [PATCH 198/257] Corrected error message --- src/USER-CGDNA/pair_oxdna2_coaxstk.cpp | 4 ++-- src/USER-CGDNA/pair_oxdna2_dh.cpp | 4 ++-- src/USER-CGDNA/pair_oxrna2_stk.cpp | 2 +- src/USER-CGDNA/pair_oxrna2_xstk.cpp | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/USER-CGDNA/pair_oxdna2_coaxstk.cpp b/src/USER-CGDNA/pair_oxdna2_coaxstk.cpp index f0b3386478..47d16c4806 100644 --- a/src/USER-CGDNA/pair_oxdna2_coaxstk.cpp +++ b/src/USER-CGDNA/pair_oxdna2_coaxstk.cpp @@ -551,7 +551,7 @@ void PairOxdna2Coaxstk::coeff(int narg, char **arg) { int count; - if (narg != 21) error->all(FLERR,"Incorrect args for pair coefficients in oxdna/coaxstk"); + if (narg != 21) error->all(FLERR,"Incorrect args for pair coefficients in oxdna2/coaxstk"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; @@ -673,7 +673,7 @@ void PairOxdna2Coaxstk::coeff(int narg, char **arg) } } - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients in oxdna/coaxstk"); + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients in oxdna2/coaxstk"); } diff --git a/src/USER-CGDNA/pair_oxdna2_dh.cpp b/src/USER-CGDNA/pair_oxdna2_dh.cpp index d877e0bf9a..6b0df2cde6 100644 --- a/src/USER-CGDNA/pair_oxdna2_dh.cpp +++ b/src/USER-CGDNA/pair_oxdna2_dh.cpp @@ -273,7 +273,7 @@ void PairOxdna2Dh::coeff(int narg, char **arg) { int count; - if (narg != 5) error->all(FLERR,"Incorrect args for pair coefficients in oxdna/dh"); + if (narg != 5) error->all(FLERR,"Incorrect args for pair coefficients in oxdna2/dh"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; @@ -356,7 +356,7 @@ void PairOxdna2Dh::coeff(int narg, char **arg) } } - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients in oxdna/dh"); + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients in oxdna2/dh"); } /* ---------------------------------------------------------------------- diff --git a/src/USER-CGDNA/pair_oxrna2_stk.cpp b/src/USER-CGDNA/pair_oxrna2_stk.cpp index 33480aa380..3b02a57501 100644 --- a/src/USER-CGDNA/pair_oxrna2_stk.cpp +++ b/src/USER-CGDNA/pair_oxrna2_stk.cpp @@ -1022,7 +1022,7 @@ void PairOxrna2Stk::coeff(int narg, char **arg) } } - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients in oxdna/stk"); + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients in oxrna2/stk"); } diff --git a/src/USER-CGDNA/pair_oxrna2_xstk.cpp b/src/USER-CGDNA/pair_oxrna2_xstk.cpp index c3b97bfa9c..71c6ca0356 100644 --- a/src/USER-CGDNA/pair_oxrna2_xstk.cpp +++ b/src/USER-CGDNA/pair_oxrna2_xstk.cpp @@ -576,7 +576,7 @@ void PairOxrna2Xstk::coeff(int narg, char **arg) { int count; - if (narg != 22) error->all(FLERR,"Incorrect args for pair coefficients in oxdna/xstk"); + if (narg != 22) error->all(FLERR,"Incorrect args for pair coefficients in oxrna2/xstk"); if (!allocated) allocate(); int ilo,ihi,jlo,jhi; @@ -707,7 +707,7 @@ void PairOxrna2Xstk::coeff(int narg, char **arg) } } - if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients in oxdna/xstk"); + if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients in oxrna2/xstk"); } From 0bde6c82a3630ec29381bdcc736a016c6c46782c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 31 Mar 2021 14:40:54 -0400 Subject: [PATCH 199/257] remove newton bond off check again --- src/neighbor.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/neighbor.cpp b/src/neighbor.cpp index fb0a244cc0..704d94c77c 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -1363,10 +1363,6 @@ void Neighbor::init_topology() onoff = improper_off; MPI_Allreduce(&onoff,&improper_off,1,MPI_INT,MPI_MAX,world); - // newton_bond off is not supported with atom style template - if ((atom->molecular == Atom::TEMPLATE) && (force->newton_bond == 0)) - error->all(FLERR,"Must use 'newton bond on' with atom style template"); - // instantiate NTopo classes if (atom->avec->bonds_allow) { From 9e412bb7a661088a9bc7b43cf0585fb9c9fb25ae Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 31 Mar 2021 11:42:39 -0700 Subject: [PATCH 200/257] Fixing bug with GPU neighboring when using builds supporting CUDPP. ...introduced in Feb 2021 GPU package update. Manifests when GPU library is built with -DUSE_CUDPP and -DLAL_USE_OLD_NEIGHBOR (latter forced with CUDA 11.2). --- lib/gpu/lal_neighbor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/gpu/lal_neighbor.cpp b/lib/gpu/lal_neighbor.cpp index aabba49575..a0d2eaa8c3 100644 --- a/lib/gpu/lal_neighbor.cpp +++ b/lib/gpu/lal_neighbor.cpp @@ -740,6 +740,7 @@ void Neighbor::build_nbor_list(double **x, const int inum, const int host_inum, // If binning on GPU, do this now if (_gpu_nbor==1) { + mn = _max_nbors; const numtyp i_cell_size=static_cast(1.0/_cell_size); const int neigh_block=_block_cell_id; const int GX=(int)ceil((float)nall/neigh_block); From c53f2d4629acfa1b88416e886bb1f2e498620bef Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 31 Mar 2021 14:55:07 -0400 Subject: [PATCH 201/257] correct USER-OMP respa/omp check --- src/USER-OMP/fix_omp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/USER-OMP/fix_omp.cpp b/src/USER-OMP/fix_omp.cpp index 678df7c22a..ccc86325db 100644 --- a/src/USER-OMP/fix_omp.cpp +++ b/src/USER-OMP/fix_omp.cpp @@ -203,7 +203,8 @@ void FixOMP::init() thr[i]->_timer_active=-1; } - if (!utils::strmatch(update->integrate_style,"^respa/omp")) + if (utils::strmatch(update->integrate_style,"^respa") + && !utils::strmatch(update->integrate_style,"^respa/omp")) error->all(FLERR,"Must use respa/omp for r-RESPA with /omp styles"); if (force->pair && force->pair->compute_flag) _pair_compute_flag = true; From 7699fb37080d55ac041611983ef3889905afc4e1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 31 Mar 2021 15:55:31 -0400 Subject: [PATCH 202/257] generalize some checks in fix rigid and rigid/small --- src/RIGID/fix_rigid.cpp | 15 ++++++--------- src/RIGID/fix_rigid_nh_small.cpp | 24 +++++++++++++----------- src/RIGID/fix_rigid_small.cpp | 14 ++++++-------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/RIGID/fix_rigid.cpp b/src/RIGID/fix_rigid.cpp index a8a0e1409f..985554f738 100644 --- a/src/RIGID/fix_rigid.cpp +++ b/src/RIGID/fix_rigid.cpp @@ -720,17 +720,14 @@ void FixRigid::init() } } - // error if npt,nph fix comes before rigid fix - - for (i = 0; i < modify->nfix; i++) { - if (strcmp(modify->fix[i]->style,"npt") == 0) break; - if (strcmp(modify->fix[i]->style,"nph") == 0) break; - } + // error if a fix changing the box comes before rigid fix + for (i = 0; i < modify->nfix; i++) + if (modify->fix[i]->box_change) break; if (i < modify->nfix) { for (int j = i; j < modify->nfix; j++) - if (strcmp(modify->fix[j]->style,"rigid") == 0) - error->all(FLERR,"Rigid fix must come before NPT/NPH fix"); + if (utils::strmatch(modify->fix[j]->style,"^rigid")) + error->all(FLERR,"Rigid fixes must come before any box changing fix"); } // add gravity forces based on gravity vector from fix @@ -738,7 +735,7 @@ void FixRigid::init() if (id_gravity) { int ifix = modify->find_fix(id_gravity); if (ifix < 0) error->all(FLERR,"Fix rigid cannot find fix gravity ID"); - if (strcmp(modify->fix[ifix]->style,"gravity") != 0) + if (!utils::strmatch(modify->fix[ifix]->style,"^gravity")) error->all(FLERR,"Fix rigid gravity fix is invalid"); int tmp; gvec = (double *) modify->fix[ifix]->extract("gvec",tmp); diff --git a/src/RIGID/fix_rigid_nh_small.cpp b/src/RIGID/fix_rigid_nh_small.cpp index 3956fcf35d..454f240bb4 100644 --- a/src/RIGID/fix_rigid_nh_small.cpp +++ b/src/RIGID/fix_rigid_nh_small.cpp @@ -19,22 +19,24 @@ #include "fix_rigid_nh_small.h" -#include -#include -#include "math_extra.h" #include "atom.h" +#include "comm.h" #include "compute.h" #include "domain.h" -#include "update.h" -#include "modify.h" -#include "fix_deform.h" -#include "group.h" -#include "comm.h" -#include "force.h" -#include "kspace.h" -#include "memory.h" #include "error.h" +#include "fix_deform.h" +#include "force.h" +#include "group.h" +#include "kspace.h" +#include "math_extra.h" +#include "memory.h" +#include "modify.h" +#include "molecule.h" #include "rigid_const.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; diff --git a/src/RIGID/fix_rigid_small.cpp b/src/RIGID/fix_rigid_small.cpp index b7e0a1b2ac..d9a0b82ae8 100644 --- a/src/RIGID/fix_rigid_small.cpp +++ b/src/RIGID/fix_rigid_small.cpp @@ -571,16 +571,14 @@ void FixRigidSmall::init() } } - // error if npt,nph fix comes before rigid fix + // error if a fix changing the box comes before rigid fix - for (i = 0; i < modify->nfix; i++) { - if (strcmp(modify->fix[i]->style,"npt") == 0) break; - if (strcmp(modify->fix[i]->style,"nph") == 0) break; - } + for (i = 0; i < modify->nfix; i++) + if (modify->fix[i]->box_change) break; if (i < modify->nfix) { for (int j = i; j < modify->nfix; j++) - if (strcmp(modify->fix[j]->style,"rigid") == 0) - error->all(FLERR,"Rigid fix must come before NPT/NPH fix"); + if (utils::strmatch(modify->fix[j]->style,"^rigid")) + error->all(FLERR,"Rigid fixes must come before any box changing fix"); } // add gravity forces based on gravity vector from fix @@ -588,7 +586,7 @@ void FixRigidSmall::init() if (id_gravity) { int ifix = modify->find_fix(id_gravity); if (ifix < 0) error->all(FLERR,"Fix rigid/small cannot find fix gravity ID"); - if (strcmp(modify->fix[ifix]->style,"gravity") != 0) + if (!utils::strmatch(modify->fix[ifix]->style,"^gravity")) error->all(FLERR,"Fix rigid/small gravity fix is invalid"); int tmp; gvec = (double *) modify->fix[ifix]->extract("gvec",tmp); From bed57e02f71168fabd0f7e2895e08162c2a0797b Mon Sep 17 00:00:00 2001 From: "Ronald E. Miller" Date: Wed, 31 Mar 2021 16:18:05 -0400 Subject: [PATCH 203/257] avoiding static variable --- src/KIM/kim_interactions.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/KIM/kim_interactions.cpp b/src/KIM/kim_interactions.cpp index 3b37c96870..9b63224f0f 100644 --- a/src/KIM/kim_interactions.cpp +++ b/src/KIM/kim_interactions.cpp @@ -65,6 +65,7 @@ #include "error.h" #include "fix_store_kim.h" #include "input.h" +#include "variable.h" #include "modify.h" #include "update.h" @@ -96,7 +97,6 @@ void KimInteractions::command(int narg, char **arg) void KimInteractions::do_setup(int narg, char **arg) { - static bool kim_update=0; bool fixed_types; const std::string arg_str(arg[0]); if ((narg == 1) && (arg_str == "fixed_types")) { @@ -130,6 +130,7 @@ void KimInteractions::do_setup(int narg, char **arg) "=======\n"); if (simulatorModel) { + auto first_visit = input->variable->find("kim_update"); if (!fixed_types) { std::string atom_type_sym_list = fmt::format("{}", fmt::join(arg, arg + narg, " ")); @@ -199,8 +200,8 @@ void KimInteractions::do_setup(int narg, char **arg) const std::string sim_field_str(sim_field); if (sim_field_str == "model-defn") { - if (kim_update) input->one("variable kim_update equal 1"); - else input->one("variable kim_update equal 0"); + if (first_visit<0) input->one("variable kim_update equal 0"); + else input->one("variable kim_update equal 1"); if (domain->periodicity[0] && domain->periodicity[1] && domain->periodicity[2]) @@ -242,7 +243,7 @@ void KimInteractions::do_setup(int narg, char **arg) KIM_SimulatorModel_OpenAndInitializeTemplateMap(simulatorModel); - } else if (!kim_update) { + } else { // not a simulator model. issue pair_style and pair_coeff commands. @@ -264,7 +265,6 @@ void KimInteractions::do_setup(int narg, char **arg) // End output to log file input->write_echo("#=== END kim interactions =============================" "=======\n\n"); - kim_update=1; } /* ---------------------------------------------------------------------- */ From f48af95d499536dd5da692ba0b3ea9c6361ffcee Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 1 Apr 2021 08:23:10 -0400 Subject: [PATCH 204/257] update gcmc example to use fix rigid/small --- examples/gcmc/in.gcmc.co2 | 48 +++--- examples/gcmc/log.27Nov18.gcmc.co2.g++.1 | 196 ----------------------- examples/gcmc/log.31Mar21.gcmc.co2.g++.1 | 196 +++++++++++++++++++++++ 3 files changed, 220 insertions(+), 220 deletions(-) delete mode 100644 examples/gcmc/log.27Nov18.gcmc.co2.g++.1 create mode 100644 examples/gcmc/log.31Mar21.gcmc.co2.g++.1 diff --git a/examples/gcmc/in.gcmc.co2 b/examples/gcmc/in.gcmc.co2 index b5e11d212d..1da9020a64 100644 --- a/examples/gcmc/in.gcmc.co2 +++ b/examples/gcmc/in.gcmc.co2 @@ -1,4 +1,4 @@ -# GCMC for CO2 molecular fluid, rigid/small/nvt dynamics +# GCMC for CO2 molecular fluid, rigid/small dynamics # Rigid CO2 TraPPE model # [Potoff and J.I. Siepmann, Vapor-liquid equilibria of # mixtures containing alkanes, carbon dioxide and @@ -7,7 +7,7 @@ # variables available on command line variable mu index -8.1 -variable disp index 0.5 +variable disp index 0.5 variable temp index 338.0 variable lbox index 10.0 variable spacing index 5.0 @@ -17,7 +17,7 @@ variable spacing index 5.0 units real atom_style full boundary p p p -pair_style lj/cut/coul/long 14 +pair_style lj/cut/coul/long 14 pair_modify mix arithmetic tail yes kspace_style ewald 0.0001 bond_style harmonic @@ -25,7 +25,7 @@ angle_style harmonic # box, start molecules on simple cubic lattice -lattice sc ${spacing} +lattice sc ${spacing} region box block 0 ${lbox} 0 ${lbox} 0 ${lbox} units box create_box 2 box & bond/types 1 & @@ -34,56 +34,56 @@ create_box 2 box & extra/angle/per/atom 1 & extra/special/per/atom 2 molecule co2mol CO2.txt -create_atoms 0 box mol co2mol 464563 units box - -# rigid CO2 TraPPE model +create_atoms 0 box mol co2mol 464563 units box + +# rigid CO2 TraPPE model pair_coeff 1 1 0.053649 2.8 -pair_coeff 2 2 0.156973 3.05 -bond_coeff 1 0 1.16 -angle_coeff 1 0 180 +pair_coeff 2 2 0.156973 3.05 +bond_coeff 1 0 1.16 +angle_coeff 1 0 180 # masses -mass 1 12.0107 -mass 2 15.9994 +mass 1 12.0107 +mass 2 15.9994 # MD settings group co2 type 1 2 neighbor 2.0 bin neigh_modify every 1 delay 10 check yes -velocity all create ${temp} 54654 +velocity all create ${temp} 54654 timestep 1.0 -# rigid constraints with thermostat +# rigid constraints with thermostat -fix myrigidnvt co2 rigid/nvt/small molecule temp ${temp} ${temp} 100 mol co2mol +fix myrigid co2 rigid/small molecule mol co2mol # dynamically update fix rigid/nvt/small temperature ndof -fix_modify myrigidnvt dynamic/dof yes +fix_modify myrigid dynamic/dof yes # gcmc variable tfac equal 5.0/3.0 # (3 trans + 2 rot)/(3 trans) fix mygcmc co2 gcmc 100 100 0 0 54341 ${temp} ${mu} ${disp} mol & - co2mol tfac_insert ${tfac} group co2 rigid myrigidnvt + co2mol tfac_insert ${tfac} group co2 rigid myrigid # atom counts -variable carbon atom "type==1" +variable carbon atom "type==1" variable oxygen atom "type==2" -group carbon dynamic co2 var carbon -group oxygen dynamic co2 var oxygen +group carbon dynamic co2 var carbon +group oxygen dynamic co2 var oxygen variable nC equal count(carbon) variable nO equal count(oxygen) # output -variable tacc equal f_mygcmc[2]/(f_mygcmc[1]+0.1) -variable iacc equal f_mygcmc[4]/(f_mygcmc[3]+0.1) -variable dacc equal f_mygcmc[6]/(f_mygcmc[5]+0.1) -variable racc equal f_mygcmc[8]/(f_mygcmc[7]+0.1) +variable tacc equal f_mygcmc[2]/(f_mygcmc[1]+0.1) +variable iacc equal f_mygcmc[4]/(f_mygcmc[3]+0.1) +variable dacc equal f_mygcmc[6]/(f_mygcmc[5]+0.1) +variable racc equal f_mygcmc[8]/(f_mygcmc[7]+0.1) # dynamically update default temperature ndof compute_modify thermo_temp dynamic/dof yes diff --git a/examples/gcmc/log.27Nov18.gcmc.co2.g++.1 b/examples/gcmc/log.27Nov18.gcmc.co2.g++.1 deleted file mode 100644 index 4ed9056d04..0000000000 --- a/examples/gcmc/log.27Nov18.gcmc.co2.g++.1 +++ /dev/null @@ -1,196 +0,0 @@ -LAMMPS (27 Nov 2018) - using 1 OpenMP thread(s) per MPI task -# GCMC for CO2 molecular fluid, rigid/small/nvt dynamics -# Rigid CO2 TraPPE model -# [Potoff and J.I. Siepmann, Vapor-liquid equilibria of -# mixtures containing alkanes, carbon dioxide and -# nitrogen AIChE J., 47,1676-1682 (2001)]. - -# variables available on command line - -variable mu index -8.1 -variable disp index 0.5 -variable temp index 338.0 -variable lbox index 10.0 -variable spacing index 5.0 - -# global model settings - -units real -atom_style full -boundary p p p -pair_style lj/cut/coul/long 14 -pair_modify mix arithmetic tail yes -kspace_style ewald 0.0001 -bond_style harmonic -angle_style harmonic - -# box, start molecules on simple cubic lattice - -lattice sc ${spacing} -lattice sc 5.0 -Lattice spacing in x,y,z = 5 5 5 -region box block 0 ${lbox} 0 ${lbox} 0 ${lbox} units box -region box block 0 10.0 0 ${lbox} 0 ${lbox} units box -region box block 0 10.0 0 10.0 0 ${lbox} units box -region box block 0 10.0 0 10.0 0 10.0 units box -create_box 2 box bond/types 1 angle/types 1 extra/bond/per/atom 2 extra/angle/per/atom 1 extra/special/per/atom 2 -Created orthogonal box = (0 0 0) to (10 10 10) - 1 by 1 by 1 MPI processor grid -molecule co2mol CO2.txt -Read molecule co2mol: - 3 atoms with max type 2 - 2 bonds with max type 1 - 1 angles with max type 1 - 0 dihedrals with max type 0 - 0 impropers with max type 0 -create_atoms 0 box mol co2mol 464563 units box -Created 24 atoms - Time spent = 0.00134993 secs - -# rigid CO2 TraPPE model - -pair_coeff 1 1 0.053649 2.8 -pair_coeff 2 2 0.156973 3.05 -bond_coeff 1 0 1.16 -angle_coeff 1 0 180 - -# masses - -mass 1 12.0107 -mass 2 15.9994 - -# MD settings - -group co2 type 1 2 -24 atoms in group co2 -neighbor 2.0 bin -neigh_modify every 1 delay 10 check yes -velocity all create ${temp} 54654 -velocity all create 338.0 54654 -timestep 1.0 - -# rigid constraints with thermostat - -fix myrigidnvt co2 rigid/nvt/small molecule temp ${temp} ${temp} 100 mol co2mol -fix myrigidnvt co2 rigid/nvt/small molecule temp 338.0 ${temp} 100 mol co2mol -fix myrigidnvt co2 rigid/nvt/small molecule temp 338.0 338.0 100 mol co2mol -8 rigid bodies with 24 atoms - 1.16 = max distance from body owner to body atom - -# dynamically update fix rigid/nvt/small temperature ndof -fix_modify myrigidnvt dynamic/dof yes - -# gcmc - -variable tfac equal 5.0/3.0 # (3 trans + 2 rot)/(3 trans) -fix mygcmc co2 gcmc 100 100 0 0 54341 ${temp} ${mu} ${disp} mol co2mol tfac_insert ${tfac} group co2 rigid myrigidnvt -fix mygcmc co2 gcmc 100 100 0 0 54341 338.0 ${mu} ${disp} mol co2mol tfac_insert ${tfac} group co2 rigid myrigidnvt -fix mygcmc co2 gcmc 100 100 0 0 54341 338.0 -8.1 ${disp} mol co2mol tfac_insert ${tfac} group co2 rigid myrigidnvt -fix mygcmc co2 gcmc 100 100 0 0 54341 338.0 -8.1 0.5 mol co2mol tfac_insert ${tfac} group co2 rigid myrigidnvt -fix mygcmc co2 gcmc 100 100 0 0 54341 338.0 -8.1 0.5 mol co2mol tfac_insert 1.66666666666667 group co2 rigid myrigidnvt - -# atom counts - -variable carbon atom "type==1" -variable oxygen atom "type==2" -group carbon dynamic co2 var carbon -dynamic group carbon defined -group oxygen dynamic co2 var oxygen -dynamic group oxygen defined -variable nC equal count(carbon) -variable nO equal count(oxygen) - -# output - -variable tacc equal f_mygcmc[2]/(f_mygcmc[1]+0.1) -variable iacc equal f_mygcmc[4]/(f_mygcmc[3]+0.1) -variable dacc equal f_mygcmc[6]/(f_mygcmc[5]+0.1) -variable racc equal f_mygcmc[8]/(f_mygcmc[7]+0.1) - -# dynamically update default temperature ndof -compute_modify thermo_temp dynamic/dof yes - -thermo_style custom step temp press pe ke density atoms v_iacc v_dacc v_tacc v_racc v_nC v_nO -thermo 1000 - -# run - -run 20000 -Ewald initialization ... - using 12-bit tables for long-range coulomb (src/kspace.cpp:321) - G vector (1/distance) = 0.164636 - estimated absolute RMS force accuracy = 0.0332064 - estimated relative force accuracy = 0.0001 - KSpace vectors: actual max1d max3d = 16 2 62 - kxmax kymax kzmax = 2 2 2 -WARNING: Fix gcmc using full_energy option (src/MC/fix_gcmc.cpp:487) -0 atoms in group FixGCMC:gcmc_exclusion_group:mygcmc -0 atoms in group FixGCMC:rotation_gas_atoms:mygcmc -WARNING: Neighbor exclusions used with KSpace solver may give inconsistent Coulombic energies (src/neighbor.cpp:471) -Neighbor list info ... - update every 1 steps, delay 10 steps, check yes - max neighbors/atom: 2000, page size: 100000 - master list distance cutoff = 16 - ghost atom cutoff = 16 - binsize = 8, bins = 2 2 2 - 1 neighbor lists, perpetual/occasional/extra = 1 0 0 - (1) pair lj/cut/coul/long, perpetual - attributes: half, newton on - pair build: half/bin/newton - stencil: half/bin/3d/newton - bin: standard -Per MPI rank memory allocation (min/avg/max) = 15.62 | 15.62 | 15.62 Mbytes -Step Temp Press PotEng KinEng Density Atoms v_iacc v_dacc v_tacc v_racc v_nC v_nO - 0 364.27579 4238.8631 -9.6809388 13.391989 0.5846359 24 0 0 0 0 8 16 - 1000 267.9799 -73.919548 -3.6735999 5.8578459 0.36539744 15 0.23663972 0.2494423 0 0 5 10 - 2000 409.06596 -98.033864 -6.7570039 10.974131 0.43847693 18 0.29379544 0.29816284 0 0 6 12 - 3000 279.3225 -836.47758 -26.434976 15.819539 0.87695385 36 0.23798567 0.24203908 0 0 12 24 - 4000 333.6181 606.63478 -30.35312 18.894592 0.87695385 36 0.19121778 0.19481508 0 0 12 24 - 5000 405.98741 -103.97582 -14.180277 16.942399 0.65771539 27 0.15272841 0.15982952 0 0 9 18 - 6000 283.5835 -240.01076 -6.7198093 7.607777 0.43847693 18 0.1606796 0.16536735 0 0 6 12 - 7000 142.00717 154.95914 -0.74192319 0.98769159 0.14615898 6 0.19501993 0.20103405 0 0 2 4 - 8000 376.67702 -118.12474 -10.774631 13.847899 0.5846359 24 0.20133396 0.20468352 0 0 8 16 - 9000 305.43166 -1095.8633 -10.388279 9.7112935 0.51155641 21 0.19445239 0.19869334 0 0 7 14 - 10000 244.08225 -179.31274 -12.974988 8.9732748 0.5846359 24 0.19098971 0.19586397 0 0 8 16 - 11000 305.03389 -568.94714 -21.745425 14.244887 0.73079488 30 0.18517522 0.18978828 0 0 10 20 - 12000 318.29735 767.76579 -37.184231 21.189508 1.0231128 42 0.17256426 0.17580267 0 0 14 28 - 13000 411.21707 433.01125 -4.5149215 8.9889065 0.36539744 15 0.16329385 0.16767604 0 0 5 10 - 14000 304.29535 148.28607 -2.3505844 6.6516754 0.36539744 15 0.17435868 0.17897674 0 0 5 10 - 15000 338.00555 2384.1424 -21.438264 17.463859 0.80387436 33 0.17237066 0.17634112 0 0 11 22 - 16000 613.56062 610.93867 -0.057364228 1.2192718 0.073079488 3 0.17128158 0.1758886 0 0 1 2 - 17000 432.63323 -980.52384 -15.79844 18.054365 0.65771539 27 0.17145651 0.17504846 0 0 9 18 - 18000 181.74572 -352.81765 -1.8617959 2.1669979 0.21923846 9 0.17292463 0.17654774 0 0 3 6 - 19000 208.55292 -248.38735 -4.2287767 4.5588154 0.36539744 15 0.18168324 0.18454331 0 0 5 10 - 20000 304.73317 -649.9896 -16.532405 12.716924 0.65771539 27 0.18085983 0.18345574 0 0 9 18 -Loop time of 21.0434 on 1 procs for 20000 steps with 27 atoms - -Performance: 82.116 ns/day, 0.292 hours/ns, 950.415 timesteps/s -98.5% CPU use with 1 MPI tasks x 1 OpenMP threads - -MPI task timing breakdown: -Section | min time | avg time | max time |%varavg| %total ---------------------------------------------------------------- -Pair | 2.2373 | 2.2373 | 2.2373 | 0.0 | 10.63 -Bond | 0.022895 | 0.022895 | 0.022895 | 0.0 | 0.11 -Kspace | 0.16756 | 0.16756 | 0.16756 | 0.0 | 0.80 -Neigh | 0.11436 | 0.11436 | 0.11436 | 0.0 | 0.54 -Comm | 0.26988 | 0.26988 | 0.26988 | 0.0 | 1.28 -Output | 0.0014684 | 0.0014684 | 0.0014684 | 0.0 | 0.01 -Modify | 18.193 | 18.193 | 18.193 | 0.0 | 86.45 -Other | | 0.03692 | | | 0.18 - -Nlocal: 27 ave 27 max 27 min -Histogram: 1 0 0 0 0 0 0 0 0 0 -Nghost: 2081 ave 2081 max 2081 min -Histogram: 1 0 0 0 0 0 0 0 0 0 -Neighs: 6264 ave 6264 max 6264 min -Histogram: 1 0 0 0 0 0 0 0 0 0 - -Total # of neighbors = 6264 -Ave neighs/atom = 232 -Ave special neighs/atom = 2 -Neighbor list builds = 20177 -Dangerous builds = 0 - -Total wall time: 0:00:21 diff --git a/examples/gcmc/log.31Mar21.gcmc.co2.g++.1 b/examples/gcmc/log.31Mar21.gcmc.co2.g++.1 new file mode 100644 index 0000000000..80de6554e4 --- /dev/null +++ b/examples/gcmc/log.31Mar21.gcmc.co2.g++.1 @@ -0,0 +1,196 @@ +LAMMPS (10 Mar 2021) + using 1 OpenMP thread(s) per MPI task +# GCMC for CO2 molecular fluid, rigid/small dynamics +# Rigid CO2 TraPPE model +# [Potoff and J.I. Siepmann, Vapor-liquid equilibria of +# mixtures containing alkanes, carbon dioxide and +# nitrogen AIChE J., 47,1676-1682 (2001)]. + +# variables available on command line + +variable mu index -8.1 +variable disp index 0.5 +variable temp index 338.0 +variable lbox index 10.0 +variable spacing index 5.0 + +# global model settings + +units real +atom_style full +boundary p p p +pair_style lj/cut/coul/long 14 +pair_modify mix arithmetic tail yes +kspace_style ewald 0.0001 +bond_style harmonic +angle_style harmonic + +# box, start molecules on simple cubic lattice + +lattice sc ${spacing} +lattice sc 5.0 +Lattice spacing in x,y,z = 5.0000000 5.0000000 5.0000000 +region box block 0 ${lbox} 0 ${lbox} 0 ${lbox} units box +region box block 0 10.0 0 ${lbox} 0 ${lbox} units box +region box block 0 10.0 0 10.0 0 ${lbox} units box +region box block 0 10.0 0 10.0 0 10.0 units box +create_box 2 box bond/types 1 angle/types 1 extra/bond/per/atom 2 extra/angle/per/atom 1 extra/special/per/atom 2 +Created orthogonal box = (0.0000000 0.0000000 0.0000000) to (10.000000 10.000000 10.000000) + 1 by 1 by 1 MPI processor grid +molecule co2mol CO2.txt +Read molecule template co2mol: + 1 molecules + 3 atoms with max type 2 + 2 bonds with max type 1 + 1 angles with max type 1 + 0 dihedrals with max type 0 + 0 impropers with max type 0 +create_atoms 0 box mol co2mol 464563 units box +Created 24 atoms + create_atoms CPU = 0.002 seconds + +# rigid CO2 TraPPE model + +pair_coeff 1 1 0.053649 2.8 +pair_coeff 2 2 0.156973 3.05 +bond_coeff 1 0 1.16 +angle_coeff 1 0 180 + +# masses + +mass 1 12.0107 +mass 2 15.9994 + +# MD settings + +group co2 type 1 2 +24 atoms in group co2 +neighbor 2.0 bin +neigh_modify every 1 delay 10 check yes +velocity all create ${temp} 54654 +velocity all create 338.0 54654 +timestep 1.0 + +# rigid constraints with thermostat + +fix myrigid co2 rigid/small molecule mol co2mol + create bodies CPU = 0.000 seconds + 8 rigid bodies with 24 atoms + 1.1600000 = max distance from body owner to body atom + +# dynamically update fix rigid/nvt/small temperature ndof +fix_modify myrigid dynamic/dof yes + +# gcmc + +variable tfac equal 5.0/3.0 # (3 trans + 2 rot)/(3 trans) +fix mygcmc co2 gcmc 100 100 0 0 54341 ${temp} ${mu} ${disp} mol co2mol tfac_insert ${tfac} group co2 rigid myrigid +fix mygcmc co2 gcmc 100 100 0 0 54341 338.0 ${mu} ${disp} mol co2mol tfac_insert ${tfac} group co2 rigid myrigid +fix mygcmc co2 gcmc 100 100 0 0 54341 338.0 -8.1 ${disp} mol co2mol tfac_insert ${tfac} group co2 rigid myrigid +fix mygcmc co2 gcmc 100 100 0 0 54341 338.0 -8.1 0.5 mol co2mol tfac_insert ${tfac} group co2 rigid myrigid +fix mygcmc co2 gcmc 100 100 0 0 54341 338.0 -8.1 0.5 mol co2mol tfac_insert 1.66666666666667 group co2 rigid myrigid + +# atom counts + +variable carbon atom "type==1" +variable oxygen atom "type==2" +group carbon dynamic co2 var carbon +dynamic group carbon defined +group oxygen dynamic co2 var oxygen +dynamic group oxygen defined +variable nC equal count(carbon) +variable nO equal count(oxygen) + +# output + +variable tacc equal f_mygcmc[2]/(f_mygcmc[1]+0.1) +variable iacc equal f_mygcmc[4]/(f_mygcmc[3]+0.1) +variable dacc equal f_mygcmc[6]/(f_mygcmc[5]+0.1) +variable racc equal f_mygcmc[8]/(f_mygcmc[7]+0.1) + +# dynamically update default temperature ndof +compute_modify thermo_temp dynamic/dof yes + +thermo_style custom step temp press pe ke density atoms v_iacc v_dacc v_tacc v_racc v_nC v_nO +thermo 1000 + +# run + +run 20000 +Ewald initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:339) + G vector (1/distance) = 0.16463644 + estimated absolute RMS force accuracy = 0.033206372 + estimated relative force accuracy = 0.0001 + KSpace vectors: actual max1d max3d = 16 2 62 + kxmax kymax kzmax = 2 2 2 +WARNING: Fix gcmc using full_energy option (src/MC/fix_gcmc.cpp:482) +0 atoms in group FixGCMC:gcmc_exclusion_group:mygcmc +0 atoms in group FixGCMC:rotation_gas_atoms:mygcmc +WARNING: Neighbor exclusions used with KSpace solver may give inconsistent Coulombic energies (src/neighbor.cpp:486) +Neighbor list info ... + update every 1 steps, delay 10 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 16 + ghost atom cutoff = 16 + binsize = 8, bins = 2 2 2 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair lj/cut/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/newton + stencil: half/bin/3d/newton + bin: standard +Per MPI rank memory allocation (min/avg/max) = 15.62 | 15.62 | 15.62 Mbytes +Step Temp Press PotEng KinEng Density Atoms v_iacc v_dacc v_tacc v_racc v_nC v_nO + 0 364.27579 4238.8631 -9.6809388 13.391989 0.5846359 24 0 0 0 0 8 16 + 1000 261.50949 -204.60974 -9.6459249 8.3147747 0.51155641 21 0.096366192 0.097590121 0 0 7 14 + 2000 479.39697 231.28436 -7.0089345 10.47927 0.36539744 15 0.085531005 0.085453295 0 0 5 10 + 3000 318.31766 -433.17133 -7.3680951 8.5396005 0.43847693 18 0.078556687 0.080101462 0 0 6 12 + 4000 357.40776 -186.78 -16.453111 14.915105 0.65771539 27 0.082003877 0.08249082 0 0 9 18 + 5000 399.94731 1524.2909 -16.624678 18.677282 0.73079488 30 0.071285101 0.072731705 0 0 10 20 + 6000 354.71736 60.134827 -18.988979 16.565073 0.73079488 30 0.071615663 0.071713414 0 0 10 20 + 7000 483.32057 966.32174 -5.7393251 10.565037 0.36539744 15 0.087027775 0.089855826 0 0 5 10 + 8000 547.68562 494.96891 -4.125626 11.97201 0.36539744 15 0.11738082 0.11937373 0 0 5 10 + 9000 433.76488 390.91467 -0.85312985 5.1718828 0.21923846 9 0.13265238 0.13513212 0 0 3 6 + 10000 330.01685 -862.07457 -26.494645 18.690633 0.87695385 36 0.13775034 0.13905403 0 0 12 24 + 11000 334.26318 -578.48274 -13.236965 12.288625 0.5846359 24 0.13713936 0.13960485 0 0 8 16 + 12000 243.68657 -1244.7156 -25.757644 12.590645 0.80387436 33 0.1339588 0.13588739 0 0 11 22 + 13000 307.66758 -429.66928 -17.864639 14.367878 0.73079488 30 0.12604721 0.1278094 0 0 10 20 + 14000 330.91434 495.97112 -15.374248 13.809499 0.65771539 27 0.12011756 0.12145865 0 0 9 18 + 15000 564.87966 982.72332 -14.810525 26.379517 0.73079488 30 0.12164324 0.12343521 0 0 10 20 + 16000 342.63867 -54.776299 -2.2580523 5.7875978 0.29231795 12 0.13535812 0.13790758 0 0 4 8 + 17000 461.07005 -2.4317694 -1.145154 3.2068452 0.14615898 6 0.1444739 0.14730804 0 0 2 4 + 18000 197.21207 -40.124433 -7.0857418 5.2906654 0.43847693 18 0.14403997 0.14574329 0 0 6 12 + 19000 393.36395 -420.49802 -11.172739 14.461366 0.5846359 24 0.15005606 0.15142063 0 0 8 16 + 20000 356.48539 56.071962 -1.7861789 4.2504609 0.21923846 9 0.15422732 0.15627984 0 0 3 6 +Loop time of 19.5982 on 1 procs for 20000 steps with 9 atoms + +Performance: 88.171 ns/day, 0.272 hours/ns, 1020.502 timesteps/s +99.5% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 2.3404 | 2.3404 | 2.3404 | 0.0 | 11.94 +Bond | 0.033919 | 0.033919 | 0.033919 | 0.0 | 0.17 +Kspace | 0.19974 | 0.19974 | 0.19974 | 0.0 | 1.02 +Neigh | 0.11478 | 0.11478 | 0.11478 | 0.0 | 0.59 +Comm | 0.22538 | 0.22538 | 0.22538 | 0.0 | 1.15 +Output | 0.00096536 | 0.00096536 | 0.00096536 | 0.0 | 0.00 +Modify | 16.627 | 16.627 | 16.627 | 0.0 | 84.84 +Other | | 0.05594 | | | 0.29 + +Nlocal: 9.00000 ave 9 max 9 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 703.000 ave 703 max 703 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 719.000 ave 719 max 719 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 719 +Ave neighs/atom = 79.888889 +Ave special neighs/atom = 2.0000000 +Neighbor list builds = 20196 +Dangerous builds = 0 + +Total wall time: 0:00:19 From d72b390c41f63bae8f6cde7c9d4a56e6a9abf042 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 1 Apr 2021 08:48:39 -0400 Subject: [PATCH 205/257] correct check for box changing fixes --- src/RIGID/fix_rigid.cpp | 4 ++-- src/RIGID/fix_rigid_small.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/RIGID/fix_rigid.cpp b/src/RIGID/fix_rigid.cpp index 985554f738..26bbb9477f 100644 --- a/src/RIGID/fix_rigid.cpp +++ b/src/RIGID/fix_rigid.cpp @@ -725,7 +725,7 @@ void FixRigid::init() for (i = 0; i < modify->nfix; i++) if (modify->fix[i]->box_change) break; if (i < modify->nfix) { - for (int j = i; j < modify->nfix; j++) + for (int j = i+1; j < modify->nfix; j++) if (utils::strmatch(modify->fix[j]->style,"^rigid")) error->all(FLERR,"Rigid fixes must come before any box changing fix"); } @@ -736,7 +736,7 @@ void FixRigid::init() int ifix = modify->find_fix(id_gravity); if (ifix < 0) error->all(FLERR,"Fix rigid cannot find fix gravity ID"); if (!utils::strmatch(modify->fix[ifix]->style,"^gravity")) - error->all(FLERR,"Fix rigid gravity fix is invalid"); + error->all(FLERR,"Fix rigid gravity fix ID is not a gravity fix style"); int tmp; gvec = (double *) modify->fix[ifix]->extract("gvec",tmp); } diff --git a/src/RIGID/fix_rigid_small.cpp b/src/RIGID/fix_rigid_small.cpp index d9a0b82ae8..14bd9f7a55 100644 --- a/src/RIGID/fix_rigid_small.cpp +++ b/src/RIGID/fix_rigid_small.cpp @@ -576,7 +576,7 @@ void FixRigidSmall::init() for (i = 0; i < modify->nfix; i++) if (modify->fix[i]->box_change) break; if (i < modify->nfix) { - for (int j = i; j < modify->nfix; j++) + for (int j = i+1; j < modify->nfix; j++) if (utils::strmatch(modify->fix[j]->style,"^rigid")) error->all(FLERR,"Rigid fixes must come before any box changing fix"); } @@ -587,7 +587,7 @@ void FixRigidSmall::init() int ifix = modify->find_fix(id_gravity); if (ifix < 0) error->all(FLERR,"Fix rigid/small cannot find fix gravity ID"); if (!utils::strmatch(modify->fix[ifix]->style,"^gravity")) - error->all(FLERR,"Fix rigid/small gravity fix is invalid"); + error->all(FLERR,"Fix rigid gravity fix ID is not a gravity fix style"); int tmp; gvec = (double *) modify->fix[ifix]->extract("gvec",tmp); } From c9652f3aa695f95d62914cc94000cdcd51f4fd98 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 1 Apr 2021 09:31:54 -0400 Subject: [PATCH 206/257] update documentation for the extract_global() method of the lammps.lammps class --- python/lammps/core.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/python/lammps/core.py b/python/lammps/core.py index e112c4f3f8..3118cb3d99 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -729,12 +729,11 @@ class lammps(object): def extract_global(self, name, dtype=LAMMPS_AUTODETECT): """Query LAMMPS about global settings of different types. - This is a wrapper around the :cpp:func:`lammps_extract_global` - function of the C-library interface. Unlike the C function - this method returns the value and not a pointer and thus can - only return the first value for keywords representing a list - of values. The :cpp:func:`lammps_extract_global` documentation - includes a list of the supported keywords and their data types. + This is a wrapper around the :cpp:func:`lammps_extract_global` function + of the C-library interface. Since there are no pointers in Python, this + method will - unlike the C function - return the value or a list of + values. The :cpp:func:`lammps_extract_global` documentation includes a + list of the supported keywords and their data types. Since Python needs to know the data type to be able to interpret the result, by default, this function will try to auto-detect the data type by asking the library. You can also force a specific data type. For that From f867e69290beea676eb86b0cabae44768349df9f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 1 Apr 2021 09:35:52 -0400 Subject: [PATCH 207/257] include new split_lines() function in Developer docs --- doc/src/Developer_utils.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/src/Developer_utils.rst b/doc/src/Developer_utils.rst index 992df6ba63..17b4715dc7 100644 --- a/doc/src/Developer_utils.rst +++ b/doc/src/Developer_utils.rst @@ -101,6 +101,9 @@ and parsing files or arguments. .. doxygenfunction:: split_words :project: progguide +.. doxygenfunction:: split_lines + :project: progguide + .. doxygenfunction:: strmatch :project: progguide From e0aec1b5d9ba2c3d26d16beb11d5a100853b195f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 1 Apr 2021 09:39:17 -0400 Subject: [PATCH 208/257] remove obsoleted comment --- unittest/force-styles/test_fix_timestep.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index f72295716e..e4b0fa6e02 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -518,11 +518,9 @@ TEST(FixTimestep, plain) // rigid fixes need work to test properly with r-RESPA. // fix nve/limit cannot work with r-RESPA - // fix python/move implementation is missing library interface access to Repsa::step ifix = lmp->modify->find_fix("test"); if (!utils::strmatch(lmp->modify->fix[ifix]->style, "^rigid") && - !utils::strmatch(lmp->modify->fix[ifix]->style, "^nve/limit") - ) { + !utils::strmatch(lmp->modify->fix[ifix]->style, "^nve/limit")) { if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); From b5d2f5f2b27828a3544cb42a05ad0906044ab1f2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 1 Apr 2021 09:45:01 -0400 Subject: [PATCH 209/257] address whitespace issues --- src/KIM/kim_interactions.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/KIM/kim_interactions.cpp b/src/KIM/kim_interactions.cpp index 9b63224f0f..f12c1774d2 100644 --- a/src/KIM/kim_interactions.cpp +++ b/src/KIM/kim_interactions.cpp @@ -12,11 +12,11 @@ ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- - Contributing authors: Axel Kohlmeyer (Temple U), - Ryan S. Elliott (UMN) - Ellad B. Tadmor (UMN) - Ronald Miller (Carleton U) - Yaser Afshar (UMN) + Contributing authors: Axel Kohlmeyer (Temple U), + Ryan S. Elliott (UMN), + Ellad B. Tadmor (UMN), + Ronald Miller (Carleton U), + Yaser Afshar (UMN) ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- @@ -200,8 +200,8 @@ void KimInteractions::do_setup(int narg, char **arg) const std::string sim_field_str(sim_field); if (sim_field_str == "model-defn") { - if (first_visit<0) input->one("variable kim_update equal 0"); - else input->one("variable kim_update equal 1"); + if (first_visit < 0) input->one("variable kim_update equal 0"); + else input->one("variable kim_update equal 1"); if (domain->periodicity[0] && domain->periodicity[1] && domain->periodicity[2]) From 4c2fb7a4312501d59ab530a09a5c5054272d53bf Mon Sep 17 00:00:00 2001 From: Nick Curtis Date: Thu, 1 Apr 2021 09:43:13 -0500 Subject: [PATCH 210/257] Porting to new default platform for AMD/HIP in ROCm 4.1 --- cmake/Modules/Packages/GPU.cmake | 12 +++++++++--- doc/src/Build_extras.rst | 13 ++++++++++--- lib/gpu/Makefile.hip | 6 +++++- lib/gpu/README | 5 ++--- lib/gpu/lal_pre_cuda_hip.h | 8 ++++---- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/cmake/Modules/Packages/GPU.cmake b/cmake/Modules/Packages/GPU.cmake index 9aa917144b..68d74ea42e 100644 --- a/cmake/Modules/Packages/GPU.cmake +++ b/cmake/Modules/Packages/GPU.cmake @@ -218,7 +218,7 @@ elseif(GPU_API STREQUAL "HIP") if(NOT DEFINED HIP_PLATFORM) if(NOT DEFINED ENV{HIP_PLATFORM}) - set(HIP_PLATFORM "hcc" CACHE PATH "HIP Platform to be used during compilation") + set(HIP_PLATFORM "amd" CACHE PATH "HIP Platform to be used during compilation") else() set(HIP_PLATFORM $ENV{HIP_PLATFORM} CACHE PATH "HIP Platform used during compilation") endif() @@ -226,7 +226,7 @@ elseif(GPU_API STREQUAL "HIP") set(ENV{HIP_PLATFORM} ${HIP_PLATFORM}) - if(HIP_PLATFORM STREQUAL "hcc") + if(HIP_PLATFORM STREQUAL "hcc" OR HIP_PLATFORM STREQUAL "amd") set(HIP_ARCH "gfx906" CACHE STRING "HIP target architecture") elseif(HIP_PLATFORM STREQUAL "nvcc") find_package(CUDA REQUIRED) @@ -284,7 +284,7 @@ elseif(GPU_API STREQUAL "HIP") set(CUBIN_FILE "${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}.cubin") set(CUBIN_H_FILE "${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h") - if(HIP_PLATFORM STREQUAL "hcc") + if(HIP_PLATFORM STREQUAL "hcc" OR HIP_PLATFORM STREQUAL "amd") configure_file(${CU_FILE} ${CU_CPP_FILE} COPYONLY) if(HIP_COMPILER STREQUAL "clang") @@ -381,6 +381,12 @@ elseif(GPU_API STREQUAL "HIP") target_compile_definitions(hip_get_devices PRIVATE -D__HIP_PLATFORM_HCC__) target_include_directories(hip_get_devices PRIVATE ${HIP_ROOT_DIR}/../include) + elseif(HIP_PLATFORM STREQUAL "amd") + target_compile_definitions(gpu PRIVATE -D__HIP_PLATFORM_AMD__) + target_include_directories(gpu PRIVATE ${HIP_ROOT_DIR}/../include) + + target_compile_definitions(hip_get_devices PRIVATE -D__HIP_PLATFORM_AMD__) + target_include_directories(hip_get_devices PRIVATE ${HIP_ROOT_DIR}/../include) endif() target_link_libraries(lammps PRIVATE gpu) diff --git a/doc/src/Build_extras.rst b/doc/src/Build_extras.rst index 2081dc4bcd..3af018c656 100644 --- a/doc/src/Build_extras.rst +++ b/doc/src/Build_extras.rst @@ -125,7 +125,7 @@ CMake build # default is sm_50 -D HIP_ARCH=value # primary GPU hardware choice for GPU_API=hip # value depends on selected HIP_PLATFORM - # default is 'gfx906' for HIP_PLATFORM=hcc and 'sm_50' for HIP_PLATFORM=nvcc + # default is 'gfx906' for HIP_PLATFORM=amd and 'sm_50' for HIP_PLATFORM=nvcc -D HIP_USE_DEVICE_SORT=value # enables GPU sorting # value = yes (default) or no -D CUDPP_OPT=value # use GPU binning on with CUDA (should be off for modern GPUs) @@ -169,17 +169,24 @@ desired, you can set :code:`USE_STATIC_OPENCL_LOADER` to :code:`no`. If you are compiling with HIP, note that before running CMake you will have to set appropriate environment variables. Some variables such as -:code:`HCC_AMDGPU_TARGET` or :code:`CUDA_PATH` are necessary for :code:`hipcc` +:code:`HCC_AMDGPU_TARGET` (for ROCm <= 4.0) or :code:`CUDA_PATH` are necessary for :code:`hipcc` and the linker to work correctly. .. code:: bash - # AMDGPU target + # AMDGPU target (ROCm <= 4.0) export HIP_PLATFORM=hcc export HCC_AMDGPU_TARGET=gfx906 cmake -D PKG_GPU=on -D GPU_API=HIP -D HIP_ARCH=gfx906 -D CMAKE_CXX_COMPILER=hipcc .. make -j 4 +.. code:: bash + + # AMDGPU target (ROCm >= 4.1) + export HIP_PLATFORM=amd + cmake -D PKG_GPU=on -D GPU_API=HIP -D HIP_ARCH=gfx906 -D CMAKE_CXX_COMPILER=hipcc .. + make -j 4 + .. code:: bash # CUDA target (not recommended, use GPU_ARCH=cuda) diff --git a/lib/gpu/Makefile.hip b/lib/gpu/Makefile.hip index dbdef433ec..a736988596 100644 --- a/lib/gpu/Makefile.hip +++ b/lib/gpu/Makefile.hip @@ -1,6 +1,6 @@ # /* ---------------------------------------------------------------------- # Generic Linux Makefile for HIP -# - export HIP_PLATFORM=hcc (or nvcc) before execution +# - export HIP_PLATFORM=amd (or nvcc) before execution # - change HIP_ARCH for your GPU # ------------------------------------------------------------------------- */ @@ -42,6 +42,10 @@ ifeq (hcc,$(HIP_PLATFORM)) HIP_OPTS += -ffast-math # possible values: gfx803,gfx900,gfx906 HIP_ARCH = gfx906 +else ifeq (amd,$(HIP_PLATFORM)) + HIP_OPTS += -ffast-math + # possible values: gfx803,gfx900,gfx906 + HIP_ARCH = gfx906 else ifeq (nvcc,$(HIP_PLATFORM)) HIP_OPTS += --use_fast_math HIP_ARCH = -gencode arch=compute_30,code=[sm_30,compute_30] -gencode arch=compute_32,code=[sm_32,compute_32] -gencode arch=compute_35,code=[sm_35,compute_35] \ diff --git a/lib/gpu/README b/lib/gpu/README index dfffe11b81..eb22839a59 100644 --- a/lib/gpu/README +++ b/lib/gpu/README @@ -212,8 +212,8 @@ additionally requires cub (https://nvlabs.github.io/cub). Download and extract the cub directory to lammps/lib/gpu/ or specify an appropriate path in lammps/lib/gpu/Makefile.hip. 2. In Makefile.hip it is possible to specify the target platform via -export HIP_PLATFORM=hcc or HIP_PLATFORM=nvcc as well as the target -architecture (gfx803, gfx900, gfx906 etc.) +export HIP_PLATFORM=amd (ROCm >= 4.1), HIP_PLATFORM=hcc (ROCm <= 4.0) +or HIP_PLATFORM=nvcc as well as the target architecture (gfx803, gfx900, gfx906 etc.) 3. If your MPI implementation does not support `mpicxx --showme` command, it is required to specify the corresponding MPI compiler and linker flags in lammps/lib/gpu/Makefile.hip and in lammps/src/MAKE/OPTIONS/Makefile.hip. @@ -278,4 +278,3 @@ and Brown, W.M., Masako, Y. Implementing Molecular Dynamics on Hybrid High Performance Computers - Three-Body Potentials. Computer Physics Communications. 2013. 184: p. 2785–2793. - diff --git a/lib/gpu/lal_pre_cuda_hip.h b/lib/gpu/lal_pre_cuda_hip.h index d37b4a94c2..dfb6229bed 100644 --- a/lib/gpu/lal_pre_cuda_hip.h +++ b/lib/gpu/lal_pre_cuda_hip.h @@ -30,7 +30,7 @@ // ------------------------------------------------------------------------- -#ifdef __HIP_PLATFORM_HCC__ +#if defined(__HIP_PLATFORM_HCC__) || defined(__HIP_PLATFORM_AMD__) #define CONFIG_ID 303 #define SIMD_SIZE 64 #else @@ -161,7 +161,7 @@ // KERNEL MACROS - TEXTURES // ------------------------------------------------------------------------- -#ifdef __HIP_PLATFORM_HCC__ +#if defined(__HIP_PLATFORM_HCC__) || defined(__HIP_PLATFORM_AMD__) #define _texture(name, type) __device__ type* name #define _texture_2d(name, type) __device__ type* name #else @@ -201,7 +201,7 @@ #define mu_tex mu_ #endif -#ifdef __HIP_PLATFORM_HCC__ +#if defined(__HIP_PLATFORM_HCC__) || defined(__HIP_PLATFORM_AMD__) #undef fetch4 #undef fetch @@ -266,7 +266,7 @@ typedef struct _double4 double4; #endif #endif -#if defined(CUDA_PRE_NINE) || defined(__HIP_PLATFORM_HCC__) +#if defined(CUDA_PRE_NINE) || defined(__HIP_PLATFORM_HCC__) || defined(__HIP_PLATFORM_AMD__) #ifdef _SINGLE_SINGLE #define shfl_down __shfl_down From e7422a6bf73f836db3bd7689a30cbaf8a96174df Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 1 Apr 2021 11:26:54 -0400 Subject: [PATCH 211/257] silence compiler warnings --- src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp | 5 ++--- src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp b/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp index 556d303d30..ce0090ce5e 100644 --- a/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp +++ b/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp @@ -611,7 +611,7 @@ double PairLJSwitch3CoulGaussLong::single(int i, int j, int itype, int jtype, { double r2inv,r6inv,r,grij,expm2,t,erfc1,prefactor,prefactor2; double fraction,table,forcecoul,forcecoul2,forcelj,phicoul; - double rrij,expn2,erfc2,expb,ecoul,evdwl,trx,tr,ftr; + double rrij,expn2,erfc2,expb,evdwl,trx,tr,ftr; int itable; @@ -657,7 +657,7 @@ double PairLJSwitch3CoulGaussLong::single(int i, int j, int itype, int jtype, prefactor2 = -force->qqrd2e * atom->q[i]*atom->q[j]/r; forcecoul2 = prefactor2 * (erfc2 + EWALD_F*rrij*expn2); forcelj = expb*lj1[itype][jtype]*r-6.0*lj4[itype][jtype]*r6inv; - } else forcelj = 0.0; + } else forcelj = forcecoul2 = 0.0; double eng = 0.0; if (rsq < cut_coulsq) { @@ -672,7 +672,6 @@ double PairLJSwitch3CoulGaussLong::single(int i, int j, int itype, int jtype, } if (rsq < cut_ljsq[itype][jtype]) { - ecoul += prefactor2*erfc2*factor_coul; evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; } else evdwl = 0.0; diff --git a/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp b/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp index 47ddf8c7ad..4416a7c932 100644 --- a/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp +++ b/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp @@ -611,7 +611,7 @@ double PairMM3Switch3CoulGaussLong::single(int i, int j, int itype, int jtype, { double r2inv,r6inv,r,grij,expm2,t,erfc1,prefactor,prefactor2; double fraction,table,forcecoul,forcecoul2,forcelj,phicoul; - double expb,rrij,expn2,erfc2,ecoul,evdwl,trx,tr,ftr; + double expb,rrij,expn2,erfc2,evdwl,trx,tr,ftr; int itable; @@ -658,7 +658,7 @@ double PairMM3Switch3CoulGaussLong::single(int i, int j, int itype, int jtype, prefactor2 = -force->qqrd2e * atom->q[i]*atom->q[j]/r; forcecoul2 = prefactor2 * (erfc2 + EWALD_F*rrij*expn2); forcelj = expb*lj1[itype][jtype]*r-6.0*lj4[itype][jtype]*r6inv; - } else forcelj = 0.0; + } else forcelj = forcecoul2 = 0.0; double eng = 0.0; if (rsq < cut_coulsq) { @@ -673,7 +673,6 @@ double PairMM3Switch3CoulGaussLong::single(int i, int j, int itype, int jtype, } if (rsq < cut_ljsq[itype][jtype]) { - ecoul += prefactor2*erfc2*factor_coul; evdwl = expb-lj4[itype][jtype]*r6inv-offset[itype][jtype]; } else evdwl = 0.0; From 9ac246011e2d15f594bee7aedd61527897ee394a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 1 Apr 2021 11:48:54 -0400 Subject: [PATCH 212/257] remove flags and setup for multi-cutoff r-RESPA support which is missing --- .../pair_lj_switch3_coulgauss_long.cpp | 54 +++++-------------- .../pair_mm3_switch3_coulgauss_long.cpp | 50 ++++------------- 2 files changed, 22 insertions(+), 82 deletions(-) diff --git a/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp b/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp index ce0090ce5e..f406965e9b 100644 --- a/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp +++ b/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp @@ -17,21 +17,20 @@ #include "pair_lj_switch3_coulgauss_long.h" -#include -#include #include "atom.h" #include "comm.h" +#include "error.h" #include "force.h" #include "kspace.h" -#include "update.h" -#include "respa.h" -#include "neighbor.h" -#include "neigh_list.h" -#include "neigh_request.h" #include "math_const.h" #include "memory.h" -#include "error.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "update.h" +#include +#include using namespace LAMMPS_NS; using namespace MathConst; @@ -49,7 +48,6 @@ using namespace MathConst; PairLJSwitch3CoulGaussLong::PairLJSwitch3CoulGaussLong(LAMMPS *lmp) : Pair(lmp) { ewaldflag = pppmflag = 1; - respa_enable = 1; writedata = 1; ftable = nullptr; qdist = 0.0; @@ -170,8 +168,8 @@ void PairLJSwitch3CoulGaussLong::compute(int eflag, int vflag) expn2 = 0.0; erfc2 = 0.0; forcecoul2 = 0.0; - } - else { + prefactor2 = 0.0; + } else { rrij = lj2[itype][jtype]*r; expn2 = exp(-rrij*rrij); erfc2 = erfc(rrij); @@ -333,42 +331,19 @@ void PairLJSwitch3CoulGaussLong::init_style() if (!atom->q_flag) error->all(FLERR,"Pair style lj/switch3/coulgauss/long requires atom attribute q"); - // request regular or rRESPA neighbor list - - int irequest; - int respa = 0; - - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { - if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; - if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; - } - - irequest = neighbor->request(this,instance_me); - - if (respa >= 1) { - neighbor->requests[irequest]->respaouter = 1; - neighbor->requests[irequest]->respainner = 1; - } - if (respa == 2) neighbor->requests[irequest]->respamiddle = 1; - cut_coulsq = cut_coul * cut_coul; - // set rRESPA cutoffs - - if (strstr(update->integrate_style,"respa") && - ((Respa *) update->integrate)->level_inner >= 0) - cut_respa = ((Respa *) update->integrate)->cutoff; - else cut_respa = nullptr; - // insure use of KSpace long-range solver, set g_ewald if (force->kspace == nullptr) error->all(FLERR,"Pair style requires a KSpace style"); g_ewald = force->kspace->g_ewald; + neighbor->request(this,instance_me); + // setup force tables - if (ncoultablebits) init_tables(cut_coul,cut_respa); + if (ncoultablebits) init_tables(cut_coul,nullptr); } /* ---------------------------------------------------------------------- @@ -413,11 +388,6 @@ double PairLJSwitch3CoulGaussLong::init_one(int i, int j) lj4[j][i] = lj4[i][j]; offset[j][i] = offset[i][j]; - // check interior rRESPA cutoff - - if (cut_respa && MIN(cut_lj[i][j],cut_coul) < cut_respa[3]) - error->all(FLERR,"Pair cutoff < Respa interior cutoff"); - // compute I,J contribution to long-range tail correction // count total # of atoms of type I and J via Allreduce diff --git a/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp b/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp index 4416a7c932..64ea669a30 100644 --- a/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp +++ b/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp @@ -17,21 +17,20 @@ #include "pair_mm3_switch3_coulgauss_long.h" -#include -#include #include "atom.h" #include "comm.h" +#include "error.h" #include "force.h" #include "kspace.h" -#include "update.h" -#include "respa.h" -#include "neighbor.h" -#include "neigh_list.h" -#include "neigh_request.h" #include "math_const.h" #include "memory.h" -#include "error.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "update.h" +#include +#include using namespace LAMMPS_NS; using namespace MathConst; @@ -49,7 +48,6 @@ using namespace MathConst; PairMM3Switch3CoulGaussLong::PairMM3Switch3CoulGaussLong(LAMMPS *lmp) : Pair(lmp) { ewaldflag = pppmflag = 1; - respa_enable = 1; writedata = 1; ftable = nullptr; qdist = 0.0; @@ -335,42 +333,19 @@ void PairMM3Switch3CoulGaussLong::init_style() if (!atom->q_flag) error->all(FLERR,"Pair style mm3/switch3/coulgauss/long requires atom attribute q"); - // request regular or rRESPA neighbor list - - int irequest; - int respa = 0; - - if (update->whichflag == 1 && strstr(update->integrate_style,"respa")) { - if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; - if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; - } - - irequest = neighbor->request(this,instance_me); - - if (respa >= 1) { - neighbor->requests[irequest]->respaouter = 1; - neighbor->requests[irequest]->respainner = 1; - } - if (respa == 2) neighbor->requests[irequest]->respamiddle = 1; - cut_coulsq = cut_coul * cut_coul; - // set rRESPA cutoffs - - if (strstr(update->integrate_style,"respa") && - ((Respa *) update->integrate)->level_inner >= 0) - cut_respa = ((Respa *) update->integrate)->cutoff; - else cut_respa = nullptr; - // insure use of KSpace long-range solver, set g_ewald if (force->kspace == nullptr) error->all(FLERR,"Pair style requires a KSpace style"); g_ewald = force->kspace->g_ewald; + irequest = neighbor->request(this,instance_me); + // setup force tables - if (ncoultablebits) init_tables(cut_coul,cut_respa); + if (ncoultablebits) init_tables(cut_coul,nullptr); } /* ---------------------------------------------------------------------- @@ -414,11 +389,6 @@ double PairMM3Switch3CoulGaussLong::init_one(int i, int j) lj4[j][i] = lj4[i][j]; offset[j][i] = offset[i][j]; - // check interior rRESPA cutoff - - if (cut_respa && MIN(cut_lj[i][j],cut_coul) < cut_respa[3]) - error->all(FLERR,"Pair cutoff < Respa interior cutoff"); - // compute I,J contribution to long-range tail correction // count total # of atoms of type I and J via Allreduce From b5ef98cc22ea023579351a3c7fc2f1210f1801e3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 1 Apr 2021 12:42:07 -0400 Subject: [PATCH 213/257] consolidate the documentation for lj/switch3/coulgauss/long and mm3/switch3/coulgauss/long into a single file --- doc/src/Commands_pair.rst | 2 +- doc/src/Packages_details.rst | 2 +- doc/src/pair_lj_switch3_coulgauss_long.rst | 55 +++++++++- doc/src/pair_mm3_switch3_coulgauss_long.rst | 109 -------------------- doc/src/pair_style.rst | 2 +- 5 files changed, 53 insertions(+), 117 deletions(-) delete mode 100644 doc/src/pair_mm3_switch3_coulgauss_long.rst diff --git a/doc/src/Commands_pair.rst b/doc/src/Commands_pair.rst index da403aa87e..080f3eff20 100644 --- a/doc/src/Commands_pair.rst +++ b/doc/src/Commands_pair.rst @@ -187,7 +187,7 @@ OPT. * :doc:`mgpt ` * :doc:`mie/cut (g) ` * :doc:`mliap ` - * :doc:`mm3/switch3/coulgauss/long ` + * :doc:`mm3/switch3/coulgauss/long ` * :doc:`momb ` * :doc:`morse (gkot) ` * :doc:`morse/smooth/linear (o) ` diff --git a/doc/src/Packages_details.rst b/doc/src/Packages_details.rst index e858593c4c..173c515fc2 100644 --- a/doc/src/Packages_details.rst +++ b/doc/src/Packages_details.rst @@ -2456,6 +2456,6 @@ which discuss the `QuickFF `_ methodology. * :doc:`bond_style mm3 ` * :doc:`improper_style distharm ` * :doc:`improper_style sqdistharm ` -* :doc:`pair_style mm3/switch3/coulgauss/long ` +* :doc:`pair_style mm3/switch3/coulgauss/long ` * :doc:`pair_style lj/switch3/coulgauss/long ` * examples/USER/yaff diff --git a/doc/src/pair_lj_switch3_coulgauss_long.rst b/doc/src/pair_lj_switch3_coulgauss_long.rst index f791b9836b..6b918c1071 100644 --- a/doc/src/pair_lj_switch3_coulgauss_long.rst +++ b/doc/src/pair_lj_switch3_coulgauss_long.rst @@ -1,8 +1,12 @@ .. index:: pair_style lj/switch3/coulgauss/long +.. index:: pair_style mm3/switch3/coulgauss/long pair_style lj/switch3/coulgauss/long command ============================================ +pair_style mm3/switch3/coulgauss/long command +============================================= + Syntax """""" @@ -10,7 +14,7 @@ Syntax pair_style style args -* style = *lj/switch3/coulgauss/long* +* style = *lj/switch3/coulgauss/long* or *mm3/switch3/coulgauss/long* * args = list of arguments for a particular style .. parsed-literal:: @@ -20,6 +24,11 @@ Syntax cutoff2 = global cutoff for Coulombic (optional) (distance units) width = width parameter of the smoothing function (distance units) + *mm3/switch3/coulgauss/long* args = cutoff (cutoff2) width + cutoff = global cutoff for MM3 (and Coulombic if only 1 arg) (distance units) + cutoff2 = global cutoff for Coulombic (optional) (distance units) + width = width parameter of the smoothing function (distance units) + Examples """""""" @@ -31,6 +40,12 @@ Examples pair_style lj/switch3/coulgauss/long 12.0 10.0 3.0 pair_coeff 1 0.2 2.5 1.2 + pair_style mm3/switch3/coulgauss/long 12.0 3.0 + pair_coeff 1 0.2 2.5 1.2 + + pair_style mm3/switch3/coulgauss/long 12.0 10.0 3.0 + pair_coeff 1 0.2 2.5 1.2 + Description """"""""""" @@ -41,8 +56,17 @@ vdW potential E = 4\epsilon \left[ \left(\frac{\sigma}{r}\right)^{12}-\left(\frac{\sigma}{r}\right)^{6} \right] -, which goes smoothly to zero at the cutoff r_c as defined -by the switching function +The *mm3/switch3/coulgauss/long* style evaluates the MM3 +vdW potential :ref:`(Allinger) ` + +.. math:: + + E & = \epsilon_{ij} \left[ -2.25 \left(\frac{r_{v,ij}}{r_{ij}}\right)^6 + 1.84(10)^5 \exp\left[-12.0 r_{ij}/r_{v,ij}\right] \right] S_3(r_{ij}) \\ + r_{v,ij} & = r_{v,i} + r_{v,j} \\ + \epsilon_{ij} & = \sqrt{\epsilon_i \epsilon_j} + +Both potentials go smoothly to zero at the cutoff r_c as defined by the +switching function .. math:: @@ -85,14 +109,35 @@ commands: Mixing, shift, table, tail correction, restart, rRESPA info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" +For atom type pairs I,J and I != J, the epsilon and sigma coefficients +and cutoff distance for all of the lj/long pair styles can be mixed. +The default mix value is *geometric*\ . See the "pair_modify" command +for details. + Shifting the potential energy is not necessary because the switching function ensures that the potential is zero at the cut-off. +These pair styles support the :doc:`pair_modify ` table and +options since they can tabulate the short-range portion of the +long-range Coulombic interactions. + +Thes pair styles do not support the :doc:`pair_modify ` +tail option for adding a long-range tail correction to the +Lennard-Jones portion of the energy and pressure. + +These pair styles write their information to :doc:`binary restart files `, so pair_style and pair_coeff commands do not need +to be specified in an input script that reads a restart file. + +These pair styles can only be used via the *pair* keyword of the +:doc:`run_style respa ` command. They do not support the +*inner*\ , *middle*\ , *outer* keywords. + Restrictions """""""""""" -These styles are part of the USER-YAFF package. They are only -enabled if LAMMPS was built with that package. See the :doc:`Build package ` doc page for more info. +These styles are part of the USER-YAFF package. They are only enabled +if LAMMPS was built with that package. See the :doc:`Build package +` doc page for more info. Related commands """""""""""""""" diff --git a/doc/src/pair_mm3_switch3_coulgauss_long.rst b/doc/src/pair_mm3_switch3_coulgauss_long.rst deleted file mode 100644 index 798df0bf7a..0000000000 --- a/doc/src/pair_mm3_switch3_coulgauss_long.rst +++ /dev/null @@ -1,109 +0,0 @@ -.. index:: pair_style mm3/switch3/coulgauss/long - -pair_style mm3/switch3/coulgauss/long command -============================================= - -Syntax -"""""" - -.. code-block:: LAMMPS - - pair_style style args - -* style = *mm3/switch3/coulgauss/long* -* args = list of arguments for a particular style - -.. parsed-literal:: - - *mm3/switch3/coulgauss/long* args = cutoff (cutoff2) width - cutoff = global cutoff for MM3 (and Coulombic if only 1 arg) (distance units) - cutoff2 = global cutoff for Coulombic (optional) (distance units) - width = width parameter of the smoothing function (distance units) - -Examples -"""""""" - -.. code-block:: LAMMPS - - pair_style mm3/switch3/coulgauss/long 12.0 3.0 - pair_coeff 1 0.2 2.5 1.2 - - pair_style mm3/switch3/coulgauss/long 12.0 10.0 3.0 - pair_coeff 1 0.2 2.5 1.2 - -Description -""""""""""" - -The *mm3/switch3/coulgauss/long* style evaluates the MM3 -vdW potential :ref:`(Allinger) ` - -.. math:: - - E & = \epsilon_{ij} \left[ -2.25 \left(\frac{r_{v,ij}}{r_{ij}}\right)^6 + 1.84(10)^5 \exp\left[-12.0 r_{ij}/r_{v,ij}\right] \right] S_3(r_{ij}) \\ - r_{v,ij} & = r_{v,i} + r_{v,j} \\ - \epsilon_{ij} & = \sqrt{\epsilon_i \epsilon_j} - -, which goes smoothly to zero at the cutoff r_c as defined -by the switching function - -.. math:: - - S_3(r) = \left\lbrace \begin{array}{ll} - 1 & \quad\mathrm{if}\quad r < r_\mathrm{c} - w \\ - 3x^2 - 2x^3 & \quad\mathrm{if}\quad r < r_\mathrm{c} \quad\mathrm{with\quad} x=\frac{r_\mathrm{c} - r}{w} \\ - 0 & \quad\mathrm{if}\quad r >= r_\mathrm{c} - \end{array} \right. - -where w is the width defined in the arguments. This potential -is combined with Coulomb interaction between Gaussian charge densities: - -.. math:: - - E = \frac{q_i q_j \mathrm{erf}\left( r/\sqrt{\gamma_1^2+\gamma_2^2} \right) }{\epsilon r_{ij}} - -where :math:`q_i` and :math:`q_j` are the charges on the 2 atoms, -epsilon is the dielectric constant which can be set by the -:doc:`dielectric ` command, ::math:`\gamma_i` and -:math:`\gamma_j` are the widths of the Gaussian charge distribution and -erf() is the error-function. This style has to be used in conjunction -with the :doc:`kspace_style ` command - -If one cutoff is specified it is used for both the vdW and Coulomb -terms. If two cutoffs are specified, the first is used as the cutoff -for the vdW terms, and the second is the cutoff for the Coulombic term. - -The following coefficients must be defined for each pair of atoms -types via the :doc:`pair_coeff ` command as in the examples -above, or in the data file or restart files read by the -:doc:`read_data ` or :doc:`read_restart ` -commands: - -* :math:`\epsilon` (energy) -* :math:`r_v` (distance) -* :math:`\gamma` (distance) - ----------- - -Mixing, shift, table, tail correction, restart, rRESPA info -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -Mixing rules are fixed for this style as defined above. - -Shifting the potential energy is not necessary because the switching -function ensures that the potential is zero at the cut-off. - -Restrictions -"""""""""""" - -These styles are part of the USER-YAFF package. They are only -enabled if LAMMPS was built with that package. See the :doc:`Build package ` doc page for more info. - -Related commands -"""""""""""""""" - -:doc:`pair_coeff ` - -Default -""""""" - -none diff --git a/doc/src/pair_style.rst b/doc/src/pair_style.rst index fc66b778a1..89530895c4 100644 --- a/doc/src/pair_style.rst +++ b/doc/src/pair_style.rst @@ -250,7 +250,7 @@ accelerated styles exist. * :doc:`mgpt ` - simplified model generalized pseudopotential theory (MGPT) potential * :doc:`mesont/tpm ` - nanotubes mesoscopic force field * :doc:`mie/cut ` - Mie potential -* :doc:`mm3/switch3/coulgauss/long ` - smoothed MM3 vdW potential with Gaussian electrostatics +* :doc:`mm3/switch3/coulgauss/long ` - smoothed MM3 vdW potential with Gaussian electrostatics * :doc:`momb ` - Many-Body Metal-Organic (MOMB) force field * :doc:`morse ` - Morse potential * :doc:`morse/smooth/linear ` - linear smoothed Morse potential From 994ee59fd55200b74b80f1738f53b295bf4ee9ad Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 1 Apr 2021 12:42:48 -0400 Subject: [PATCH 214/257] correct single() functions for USER-YAFF pair styles to be consistent with compute() --- .../pair_lj_switch3_coulgauss_long.cpp | 37 ++++++++------- .../pair_mm3_switch3_coulgauss_long.cpp | 46 ++++++++++--------- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp b/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp index f406965e9b..c6bc65c196 100644 --- a/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp +++ b/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp @@ -580,8 +580,8 @@ double PairLJSwitch3CoulGaussLong::single(int i, int j, int itype, int jtype, double &fforce) { double r2inv,r6inv,r,grij,expm2,t,erfc1,prefactor,prefactor2; - double fraction,table,forcecoul,forcecoul2,forcelj,phicoul; - double rrij,expn2,erfc2,expb,evdwl,trx,tr,ftr; + double fraction,table,forcecoul,forcecoul2,forcelj; + double rrij,expn2,erfc2,expb,ecoul,evdwl,trx,tr,ftr; int itable; @@ -613,41 +613,41 @@ double PairLJSwitch3CoulGaussLong::single(int i, int j, int itype, int jtype, } else forcecoul = 0.0; if (rsq < cut_ljsq[itype][jtype]) { - r = sqrt(rsq); r6inv = r2inv*r2inv*r2inv; - rrij = lj2[itype][jtype] * r; - if (rrij==0.0) { + forcelj = r6inv*(12.0*lj3[itype][jtype]*r6inv-6.0*lj4[itype][jtype]); + if (lj2[itype][jtype] == 0.0) { expn2 = 0.0; erfc2 = 0.0; - } - else { + forcecoul2 = 0.0; + } else { + r = sqrt(rsq); + rrij = lj2[itype][jtype]*r; expn2 = exp(-rrij*rrij); erfc2 = erfc(rrij); + prefactor2 = -force->qqrd2e*atom->q[i]*atom->q[j]/r; + forcecoul2 = prefactor2*(erfc2+EWALD_F*rrij*expn2); } - prefactor2 = -force->qqrd2e * atom->q[i]*atom->q[j]/r; - forcecoul2 = prefactor2 * (erfc2 + EWALD_F*rrij*expn2); - forcelj = expb*lj1[itype][jtype]*r-6.0*lj4[itype][jtype]*r6inv; - } else forcelj = forcecoul2 = 0.0; + } else forcelj = 0.0; - double eng = 0.0; + evdwl = ecoul = 0.0; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) - phicoul = prefactor*erfc1; + ecoul = prefactor*erfc1; else { table = etable[itable] + fraction*detable[itable]; - phicoul = atom->q[i]*atom->q[j] * table; + ecoul = atom->q[i]*atom->q[j] * table; } - if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; - eng += phicoul; + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } if (rsq < cut_ljsq[itype][jtype]) { + ecoul += prefactor2*erfc2*factor_coul; evdwl = r6inv*(lj3[itype][jtype]*r6inv-lj4[itype][jtype]) - offset[itype][jtype]; } else evdwl = 0.0; // Truncation, see Yaff Switch3 - if (truncw>0) { + if (truncw > 0) { if (rsq < cut_ljsq[itype][jtype]) { if (r>cut_lj[itype][jtype]-truncw) { trx = (cut_lj[itype][jtype]-r)*truncwi; @@ -658,10 +658,9 @@ double PairLJSwitch3CoulGaussLong::single(int i, int j, int itype, int jtype, } } } - eng += evdwl*factor_lj; fforce = (forcecoul + factor_coul*forcecoul2 + factor_lj*forcelj) * r2inv; - return eng; + return evdwl*factor_lj + ecoul; } /* ---------------------------------------------------------------------- */ diff --git a/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp b/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp index 64ea669a30..e91ea5c695 100644 --- a/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp +++ b/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp @@ -171,8 +171,7 @@ void PairMM3Switch3CoulGaussLong::compute(int eflag, int vflag) expn2 = 0.0; erfc2 = 0.0; forcecoul2 = 0.0; - } - else { + } else { rrij = lj2[itype][jtype]*r; expn2 = exp(-rrij*rrij); erfc2 = erfc(rrij); @@ -341,7 +340,7 @@ void PairMM3Switch3CoulGaussLong::init_style() error->all(FLERR,"Pair style requires a KSpace style"); g_ewald = force->kspace->g_ewald; - irequest = neighbor->request(this,instance_me); + neighbor->request(this,instance_me); // setup force tables @@ -580,8 +579,8 @@ double PairMM3Switch3CoulGaussLong::single(int i, int j, int itype, int jtype, double &fforce) { double r2inv,r6inv,r,grij,expm2,t,erfc1,prefactor,prefactor2; - double fraction,table,forcecoul,forcecoul2,forcelj,phicoul; - double expb,rrij,expn2,erfc2,evdwl,trx,tr,ftr; + double fraction,table,forcecoul,forcecoul2,forcelj; + double expb,rrij,expn2,erfc2,evdwl,ecoul,trx,tr,ftr; int itable; @@ -614,40 +613,43 @@ double PairMM3Switch3CoulGaussLong::single(int i, int j, int itype, int jtype, if (rsq < cut_ljsq[itype][jtype]) { r = sqrt(rsq); - r6inv = r2inv*r2inv*r2inv; expb = lj3[itype][jtype]*exp(-lj1[itype][jtype]*r); - rrij = lj2[itype][jtype] * r; - if (rrij==0.0) { + forcelj = expb*lj1[itype][jtype]*r; + r6inv = r2inv*r2inv*r2inv; + forcelj -= 6.0*lj4[itype][jtype]*r6inv; + + if (lj2[itype][jtype] == 0.0) { expn2 = 0.0; erfc2 = 0.0; - } - else { + forcecoul2 = 0.0; + prefactor2 = 0.0; + } else { + rrij = lj2[itype][jtype]*r; expn2 = exp(-rrij*rrij); erfc2 = erfc(rrij); + prefactor2 = -force->qqrd2e * atom->q[i]*atom->q[j]/r; + forcecoul2 = prefactor2 * (erfc2 + EWALD_F*rrij*expn2); } - prefactor2 = -force->qqrd2e * atom->q[i]*atom->q[j]/r; - forcecoul2 = prefactor2 * (erfc2 + EWALD_F*rrij*expn2); - forcelj = expb*lj1[itype][jtype]*r-6.0*lj4[itype][jtype]*r6inv; - } else forcelj = forcecoul2 = 0.0; + } else expb = forcelj = 0.0; - double eng = 0.0; + evdwl = ecoul = 0.0; if (rsq < cut_coulsq) { if (!ncoultablebits || rsq <= tabinnersq) - phicoul = prefactor*erfc1; + ecoul = prefactor*erfc1; else { table = etable[itable] + fraction*detable[itable]; - phicoul = atom->q[i]*atom->q[j] * table; + ecoul = atom->q[i]*atom->q[j] * table; } - if (factor_coul < 1.0) phicoul -= (1.0-factor_coul)*prefactor; - eng += phicoul; + if (factor_coul < 1.0) ecoul -= (1.0-factor_coul)*prefactor; } if (rsq < cut_ljsq[itype][jtype]) { + ecoul += prefactor2*erfc2*factor_coul; evdwl = expb-lj4[itype][jtype]*r6inv-offset[itype][jtype]; } else evdwl = 0.0; // Truncation, see Yaff Switch3 - if (truncw>0) { + if (truncw > 0) { if (rsq < cut_ljsq[itype][jtype]) { if (r>cut_lj[itype][jtype]-truncw) { trx = (cut_lj[itype][jtype]-r)*truncwi; @@ -658,10 +660,10 @@ double PairMM3Switch3CoulGaussLong::single(int i, int j, int itype, int jtype, } } } - eng += evdwl*factor_lj; fforce = (forcecoul + factor_coul*forcecoul2 + factor_lj*forcelj) * r2inv; - return eng; + return ecoul + evdwl*factor_lj; +; } /* ---------------------------------------------------------------------- */ From c3eb52f46ab37f77748c35620e1052130ab96b2e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 1 Apr 2021 12:43:24 -0400 Subject: [PATCH 215/257] add force tests for USER-YAFF pair styles --- .../mol-pair-lj_switch3_coulgauss_long.yaml | 99 +++++++++++++++++++ .../mol-pair-lj_switch3_coulgauss_table.yaml | 99 +++++++++++++++++++ .../mol-pair-mm3_switch3_coulgauss_long.yaml | 99 +++++++++++++++++++ .../mol-pair-mm3_switch3_coulgauss_table.yaml | 99 +++++++++++++++++++ 4 files changed, 396 insertions(+) create mode 100644 unittest/force-styles/tests/mol-pair-lj_switch3_coulgauss_long.yaml create mode 100644 unittest/force-styles/tests/mol-pair-lj_switch3_coulgauss_table.yaml create mode 100644 unittest/force-styles/tests/mol-pair-mm3_switch3_coulgauss_long.yaml create mode 100644 unittest/force-styles/tests/mol-pair-mm3_switch3_coulgauss_table.yaml diff --git a/unittest/force-styles/tests/mol-pair-lj_switch3_coulgauss_long.yaml b/unittest/force-styles/tests/mol-pair-lj_switch3_coulgauss_long.yaml new file mode 100644 index 0000000000..e14044f9a0 --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-lj_switch3_coulgauss_long.yaml @@ -0,0 +1,99 @@ +--- +lammps_version: 10 Mar 2021 +date_generated: Thu Apr 1 12:05:31 202 +epsilon: 7.5e-14 +prerequisites: ! | + atom full + pair lj/switch3/coulgauss/long + kspace ewald +pre_commands: ! "" +post_commands: ! | + pair_modify mix arithmetic + pair_modify table 0 + kspace_style ewald 1.0e-6 + kspace_modify gewald 0.3 + kspace_modify compute no +input_file: in.fourmol +pair_style: lj/switch3/coulgauss/long 8.0 2.0 +pair_coeff: ! | + 1 1 0.02 2.5 1.0 + 2 2 0.005 1.0 0.7 + 2 4 0.005 0.5 0.7 + 3 3 0.02 3.2 1.3 + 4 4 0.015 3.1 1.2 + 5 5 0.015 3.1 1.2 +extract: ! | + epsilon 2 + sigma 2 + gamma 2 + cut_coul 0 +natoms: 29 +init_vdwl: 749.239201392283 +init_coul: 262.63137433058 +init_stress: ! |2- + 2.1905445805730942e+03 2.1830788072793757e+03 4.6581902800701146e+03 -7.4288115309776367e+02 2.6990012828168151e+01 6.7591505796334252e+02 +init_forces: ! |2 + 1 -2.2440985285095003e+01 2.6839510386427128e+02 3.3548778459373403e+02 + 2 1.6014525975608947e+02 1.2916401608538342e+02 -1.9007855889522560e+02 + 3 -1.3523588460187835e+02 -3.8701969631758487e+02 -1.4563951593124975e+02 + 4 -8.1626375608064503e+00 2.0129840978934559e+00 -5.9838237090267477e+00 + 5 -3.2509810426586694e+00 -3.8006496952690405e+00 1.2238094761779506e+01 + 6 -8.3272100467340556e+02 9.6240884847023358e+02 1.1512799880160530e+03 + 7 5.9109223946129624e+01 -3.3613343492781996e+02 -1.7166010182633938e+03 + 8 1.4374025374023395e+02 -1.0687979059788748e+02 3.9897084761513247e+02 + 9 8.0822098286061347e+01 8.1693084015402164e+01 3.5446319638063176e+02 + 10 5.3122611725677234e+02 -6.1057993090036803e+02 -1.8379536842135653e+02 + 11 -3.0599394771020791e+00 -5.2185583295434022e+00 -1.0179624348800495e+01 + 12 1.9237456341967800e+01 1.0181865500248987e+01 -6.1597937746835436e+00 + 13 8.3909903723672699e+00 -3.3718280449484173e+00 -3.3038121588715319e-01 + 14 -4.1292661630995928e+00 9.9336707464018092e-01 -9.3350058002796388e+00 + 15 4.2168785095757555e-01 8.7977955328786113e+00 2.0699990715180956e+00 + 16 4.6411046171725997e+02 -3.3264571918035432e+02 -1.1912223271773271e+03 + 17 -4.5697820722395699e+02 3.2194358869766086e+02 1.2030903913181610e+03 + 18 -2.9720972086277636e-01 1.7565528490258597e+00 2.4294604263813859e+00 + 19 -2.6658339749427125e+00 -3.5543359860963246e+00 -7.0028176604540848e-01 + 20 2.3030703223874878e+00 1.6788085961460804e+00 8.8715814688464914e-02 + 21 -7.2491063430524989e+01 -8.0704358691908013e+01 2.2713112476019884e+02 + 22 -1.1047017798074540e+02 -2.7622195109041627e+01 -1.7106972908159221e+02 + 23 1.8254515612066885e+02 1.0874225091685935e+02 -5.5558584096022528e+01 + 24 3.7139490938880684e+01 -2.1182968679989389e+02 1.1239472278345924e+02 + 25 -1.5173442669154963e+02 2.2482896227152501e+01 -1.2683235954885029e+02 + 26 1.1404997762743471e+02 1.8910942097520967e+02 1.3865307057956501e+01 + 27 5.1263700969024825e+01 -2.2708329767472884e+02 9.0733209359745530e+01 + 28 -1.8280634435959598e+02 7.6676771027308675e+01 -1.2320543486529729e+02 + 29 1.3193901693998819e+02 1.5040612832512986e+02 3.2448964935598738e+01 +run_vdwl: 719.395943067584 +run_coul: 262.577357625246 +run_stress: ! |2- + 2.1439469903049130e+03 2.1388099416476502e+03 4.3901771762143671e+03 -7.2215136136852652e+02 4.3981220891989977e+01 6.3726346095247902e+02 +run_forces: ! |2 + 1 -1.9342111296614632e+01 2.6536048036936916e+02 3.2628113020689460e+02 + 2 1.5478381002242270e+02 1.2483653341336152e+02 -1.8332859341112297e+02 + 3 -1.3348486669886435e+02 -3.7921582819403795e+02 -1.4287155661999228e+02 + 4 -8.1288301070929982e+00 2.0080316198654273e+00 -5.9722562656827858e+00 + 5 -3.2351829753164845e+00 -3.7719427860922665e+00 1.2190138978995325e+01 + 6 -8.0768848311420356e+02 9.2016491680294996e+02 1.0274658369925041e+03 + 7 5.6698550383493917e+01 -3.1122940570534678e+02 -1.5733988978986536e+03 + 8 1.3387241605110836e+02 -9.8275697925936129e+01 3.8773060932891792e+02 + 9 7.8389121495727082e+01 7.8858365413426057e+01 3.4347185476758511e+02 + 10 5.2128680605857573e+02 -5.9933944295277558e+02 -1.8148565911030960e+02 + 11 -3.0663895518130402e+00 -5.1690166614639725e+00 -1.0127704831021171e+01 + 12 1.9218490979542565e+01 1.0175625089829989e+01 -6.2912885237383334e+00 + 13 8.3443094714464650e+00 -3.3361880724739623e+00 -3.2980152351128239e-01 + 14 -4.0925411684752673e+00 9.7261482089301243e-01 -9.2160488176079518e+00 + 15 4.0396689631175081e-01 8.8125643989717197e+00 2.0895512608739368e+00 + 16 4.3558458306026108e+02 -3.1347365130054965e+02 -1.1153604445579856e+03 + 17 -4.2831293616595980e+02 3.0256033131579363e+02 1.1274168049543377e+03 + 18 -3.0240289244505925e-01 1.7692205043557692e+00 2.4421829464376694e+00 + 19 -2.6549690010635465e+00 -3.5598277436632562e+00 -6.9536112330149602e-01 + 20 2.2933819335528716e+00 1.6713255394851048e+00 7.9301163390346582e-02 + 21 -7.1399138479900728e+01 -7.8808617837125738e+01 2.2288288096726535e+02 + 22 -1.0872540509179575e+02 -2.7364445523270156e+01 -1.6789056923341974e+02 + 23 1.7970587875020576e+02 1.0659054948727307e+02 -5.4485902397030543e+01 + 24 3.8719492068991073e+01 -2.1018768384060851e+02 1.1276643199107306e+02 + 25 -1.5234502496218383e+02 2.2328379592897981e+01 -1.2741458364942766e+02 + 26 1.1307896673604499e+02 1.8762340967163530e+02 1.4075792400442774e+01 + 27 5.0253213702344411e+01 -2.2292638222448988e+02 8.8474597952361989e+01 + 28 -1.7928804250876811e+02 7.5155358290636585e+01 -1.2061205300179266e+02 + 29 1.2943333640446872e+02 1.4777042443708973e+02 3.2113607053518280e+01 +... diff --git a/unittest/force-styles/tests/mol-pair-lj_switch3_coulgauss_table.yaml b/unittest/force-styles/tests/mol-pair-lj_switch3_coulgauss_table.yaml new file mode 100644 index 0000000000..973ed7051e --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-lj_switch3_coulgauss_table.yaml @@ -0,0 +1,99 @@ +--- +lammps_version: 10 Mar 2021 +date_generated: Thu Apr 1 12:05:32 202 +epsilon: 5e-13 +prerequisites: ! | + atom full + pair lj/switch3/coulgauss/long + kspace ewald +pre_commands: ! "" +post_commands: ! | + pair_modify mix arithmetic + pair_modify table 16 + kspace_style ewald 1.0e-6 + kspace_modify gewald 0.3 + kspace_modify compute no +input_file: in.fourmol +pair_style: lj/switch3/coulgauss/long 8.0 2.0 +pair_coeff: ! | + 1 1 0.02 2.5 1.0 + 2 2 0.005 1.0 0.7 + 2 4 0.005 0.5 0.7 + 3 3 0.02 3.2 1.3 + 4 4 0.015 3.1 1.2 + 5 5 0.015 3.1 1.2 +extract: ! | + epsilon 2 + sigma 2 + gamma 2 + cut_coul 0 +natoms: 29 +init_vdwl: 749.239201392283 +init_coul: 262.631410551483 +init_stress: ! |2- + 2.1905446008358158e+03 2.1830788130354440e+03 4.6581902934947393e+03 -7.4288114980317005e+02 2.6990022323315568e+01 6.7591506205400140e+02 +init_forces: ! |2 + 1 -2.2440986789065228e+01 2.6839510344190973e+02 3.3548778280211798e+02 + 2 1.6014525925595575e+02 1.2916401535280644e+02 -1.9007855755707530e+02 + 3 -1.3523588449321372e+02 -3.8701969643290909e+02 -1.4563951605577458e+02 + 4 -8.1626375642225835e+00 2.0129845605828729e+00 -5.9838235187927911e+00 + 5 -3.2509808748500135e+00 -3.8006487477814463e+00 1.2238094996907998e+01 + 6 -8.3272100512926681e+02 9.6240884941333036e+02 1.1512799862203640e+03 + 7 5.9109223148516158e+01 -3.3613343497406407e+02 -1.7166010203250210e+03 + 8 1.4374025301066052e+02 -1.0687979086260394e+02 3.9897084965667705e+02 + 9 8.0822100084645626e+01 8.1693083424499093e+01 3.5446319827945621e+02 + 10 5.3122611737361080e+02 -6.1057993046376589e+02 -1.8379536902952145e+02 + 11 -3.0599395914956227e+00 -5.2185576282473036e+00 -1.0179624244755713e+01 + 12 1.9237456510724858e+01 1.0181865558167726e+01 -6.1597946782797850e+00 + 13 8.3909904522091470e+00 -3.3718281778746344e+00 -3.3038108557256562e-01 + 14 -4.1292663075103953e+00 9.9336695410995779e-01 -9.3350056582436061e+00 + 15 4.2168780003223016e-01 8.7977952410479840e+00 2.0699996667940117e+00 + 16 4.6411046291217519e+02 -3.3264572037764498e+02 -1.1912223268528312e+03 + 17 -4.5697820745668372e+02 3.2194358895792664e+02 1.2030903912557251e+03 + 18 -2.9720916995537250e-01 1.7565528041526848e+00 2.4294595600637425e+00 + 19 -2.6658359770891962e+00 -3.5543374045750902e+00 -7.0028189781643846e-01 + 20 2.3030721439983917e+00 1.6788097920639553e+00 8.8716903513438167e-02 + 21 -7.2491063802446362e+01 -8.0704358127081790e+01 2.2713112533044830e+02 + 22 -1.1047018068190837e+02 -2.7622196765220032e+01 -1.7106973071745716e+02 + 23 1.8254515931328083e+02 1.0874225209184637e+02 -5.5558583211276250e+01 + 24 3.7139491235265282e+01 -2.1182968640787311e+02 1.1239472233677957e+02 + 25 -1.5173442866720330e+02 2.2482894929853938e+01 -1.2683236039424271e+02 + 26 1.1404997991795076e+02 1.8910942242955088e+02 1.3865308691923977e+01 + 27 5.1263700853661504e+01 -2.2708329750901160e+02 9.0733209165823396e+01 + 28 -1.8280634707113845e+02 7.6676770092406045e+01 -1.2320543608135794e+02 + 29 1.3193901956336219e+02 1.5040612883439849e+02 3.2448966441423750e+01 +run_vdwl: 719.3959430344 +run_coul: 262.577390407319 +run_stress: ! |2- + 2.1439470065972137e+03 2.1388099427650550e+03 4.3901771876285757e+03 -7.2215135528838152e+02 4.3981227731157169e+01 6.3726346514781233e+02 +run_forces: ! |2 + 1 -1.9342112777764044e+01 2.6536047986408227e+02 3.2628112882188066e+02 + 2 1.5478380987853197e+02 1.2483653254176838e+02 -1.8332859191802055e+02 + 3 -1.3348486656752218e+02 -3.7921582829992821e+02 -1.4287155674732023e+02 + 4 -8.1288300595478145e+00 2.0080320707984289e+00 -5.9722560784187575e+00 + 5 -3.2351826602132863e+00 -3.7719418655198664e+00 1.2190139134122882e+01 + 6 -8.0768848338103430e+02 9.2016491733383600e+02 1.0274658351618857e+03 + 7 5.6698550307468736e+01 -3.1122940556308856e+02 -1.5733989002062301e+03 + 8 1.3387241574644310e+02 -9.8275698627583083e+01 3.8773061254696188e+02 + 9 7.8389123166777367e+01 7.8858364582844956e+01 3.4347185682031875e+02 + 10 5.2128680625044581e+02 -5.9933944258147972e+02 -1.8148565985727146e+02 + 11 -3.0663897393660062e+00 -5.1690158790311020e+00 -1.0127704822035417e+01 + 12 1.9218491178640956e+01 1.0175625315025894e+01 -6.2912900026938683e+00 + 13 8.3443096072761875e+00 -3.3361882591914980e+00 -3.2980142478029900e-01 + 14 -4.0925412507338894e+00 9.7261457606495283e-01 -9.2160486509597419e+00 + 15 4.0396659601733209e-01 8.8125640821770475e+00 2.0895518255992327e+00 + 16 4.3558458334132916e+02 -3.1347365174745744e+02 -1.1153604446371062e+03 + 17 -4.2831293628122177e+02 3.0256033223226825e+02 1.1274168046352991e+03 + 18 -3.0240272912362937e-01 1.7692204105371876e+00 2.4421821828695935e+00 + 19 -2.6549708608109603e+00 -3.5598291696654596e+00 -6.9536106786938656e-01 + 20 2.2933837220124476e+00 1.6713266856927325e+00 7.9302040608548133e-02 + 21 -7.1399139014949796e+01 -7.8808617040884513e+01 2.2288288163778361e+02 + 22 -1.0872540740988465e+02 -2.7364447046562592e+01 -1.6789057060588300e+02 + 23 1.7970588157677136e+02 1.0659055047797085e+02 -5.4485901626092641e+01 + 24 3.8719492028250940e+01 -2.1018768371930031e+02 1.1276643093423978e+02 + 25 -1.5234502685835807e+02 2.2328378412375191e+01 -1.2741458439419397e+02 + 26 1.1307896905891306e+02 1.8762341114219453e+02 1.4075794088855011e+01 + 27 5.0253213439313768e+01 -2.2292638208302930e+02 8.8474597770747309e+01 + 28 -1.7928804514846018e+02 7.5155357340410589e+01 -1.2061205423392185e+02 + 29 1.2943333884079848e+02 1.4777042481467481e+02 3.2113608671625300e+01 +... diff --git a/unittest/force-styles/tests/mol-pair-mm3_switch3_coulgauss_long.yaml b/unittest/force-styles/tests/mol-pair-mm3_switch3_coulgauss_long.yaml new file mode 100644 index 0000000000..d74aba7143 --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-mm3_switch3_coulgauss_long.yaml @@ -0,0 +1,99 @@ +--- +lammps_version: 10 Mar 2021 +date_generated: Thu Apr 1 12:40:49 202 +epsilon: 7.5e-14 +prerequisites: ! | + atom full + pair mm3/switch3/coulgauss/long + kspace ewald +pre_commands: ! "" +post_commands: ! | + pair_modify mix arithmetic + pair_modify table 0 + kspace_style ewald 1.0e-6 + kspace_modify gewald 0.3 + kspace_modify compute no +input_file: in.fourmol +pair_style: mm3/switch3/coulgauss/long 8.0 2.0 +pair_coeff: ! | + 1 1 0.02 2.5 1.0 + 2 2 0.005 1.0 0.7 + 2 4 0.005 0.5 0.7 + 3 3 0.02 3.2 1.3 + 4 4 0.015 3.1 1.2 + 5 5 0.015 3.1 1.2 +extract: ! | + epsilon 2 + sigma 2 + gamma 2 + cut_coul 0 +natoms: 29 +init_vdwl: 38.1287498820824 +init_coul: 262.63137433058 +init_stress: ! |- + -9.1891442318066098e+01 -1.3287972066289731e+02 -3.2601698046780012e+02 3.0074181349476991e+01 -4.6650805915669622e+00 -8.2199038214680613e+01 +init_forces: ! |2 + 1 2.0409906927303840e+00 -1.8543276343677643e+01 -3.5869856577020748e+01 + 2 -1.8468129335667530e+01 -1.7027855689261912e+01 2.0713359151753043e+01 + 3 1.0001881298085964e+01 5.9235891506906007e+01 2.4372336208613245e+01 + 4 -4.5761624241138597e+00 -9.8945397153998949e-01 -3.3785801701857485e+00 + 5 -3.6934402656902114e+00 -4.0696606560869748e+00 3.8826787260480975e+00 + 6 7.6754814037515942e+01 -9.5808744511121716e+01 -9.3227045949147495e+01 + 7 -2.1177649780159676e+01 2.8793163914062454e+01 1.2529350681895039e+02 + 8 -2.1450096176689623e+01 1.0356391751725083e+01 -2.8955420955058667e+01 + 9 -8.2497939748793154e+00 -1.3077027567751550e+01 -3.6173491871315754e+01 + 10 -5.3511691146997535e+01 6.0900974965221437e+01 1.8391821307129032e+01 + 11 -1.3170240621133327e+00 -3.2364695484525727e+00 -4.4029422841407655e+00 + 12 2.5797191091185894e+01 -7.5496414014335278e-01 -2.6346161145571760e+00 + 13 3.3781782842360095e+00 -7.7635850626588521e-01 -6.1835215466770443e-01 + 14 -2.5357285341105120e-02 9.3547318559063564e-01 -4.9468893910982210e+00 + 15 4.2707742121454375e+00 4.7941154645598454e+00 -1.2015244265327498e+00 + 16 -3.6573746563916743e+01 1.8565541369425805e+01 1.1446966549457964e+02 + 17 4.3913383545862132e+01 -3.3849656320211224e+01 -9.5337593733730870e+01 + 18 2.6570097579579910e+00 6.2826343323709564e+00 -1.0356872257658154e+00 + 19 -2.6993382209993975e+00 -3.5969189205658059e+00 -6.8072388138355555e-01 + 20 2.3243788182239480e+00 1.6918048474772680e+00 1.0886178998340870e-01 + 21 8.8572294982176594e+00 1.1602893199785523e+01 -3.0057630309158139e+01 + 22 1.2429506519553414e+01 2.1605554971279792e+00 2.1808499086967526e+01 + 23 -2.1432721217228789e+01 -1.3678275101206289e+01 8.4081109687741140e+00 + 24 -3.9016922943010681e+00 2.9074424568745080e+01 -1.3996421656066522e+01 + 25 1.7462841196067998e+01 -4.6818042132561875e+00 1.5548837958928004e+01 + 26 -1.2984517260341663e+01 -2.4211628682033979e+01 -4.8885242451183231e-01 + 27 -7.1989693245110757e+00 3.0862600015720503e+01 -1.2113492397573609e+01 + 28 2.1728885747832702e+01 -1.1241487657358419e+01 1.5185683466068600e+01 + 29 -1.4356735366664552e+01 -1.9712882789785066e+01 -3.0642394558798047e+00 +run_vdwl: 37.7351028273436 +run_coul: 262.634961661768 +run_stress: ! |- + -9.3272108018189712e+01 -1.3382217126586661e+02 -3.2672293936615591e+02 2.9759545957029179e+01 -4.9209094100413031e+00 -8.2642487904188499e+01 +run_forces: ! |2 + 1 2.0020649788635687e+00 -1.8597539511786593e+01 -3.5898845980394640e+01 + 2 -1.8527112215088330e+01 -1.7111766426267462e+01 2.0691354848190322e+01 + 3 1.0099460867786970e+01 5.9365750003142132e+01 2.4423492212473526e+01 + 4 -4.5756546931309785e+00 -9.8171265309239830e-01 -3.3833947541955820e+00 + 5 -3.6935770918861186e+00 -4.0701905608402482e+00 3.8892344342573999e+00 + 6 7.6571694717448139e+01 -9.5745009991872053e+01 -9.3149401161723290e+01 + 7 -2.1146519945476555e+01 2.8805358955193604e+01 1.2508940744689353e+02 + 8 -2.1038405837727929e+01 9.9856756739362105e+00 -2.8916679506818486e+01 + 9 -8.2725059756602182e+00 -1.3032514603603040e+01 -3.6169609418536254e+01 + 10 -5.3760826931047106e+01 6.1170224214358463e+01 1.8495907821099792e+01 + 11 -1.3253792323264064e+00 -3.2541587509559888e+00 -4.4355038136226383e+00 + 12 2.5785718250683153e+01 -7.4878886859791716e-01 -2.6134474044331246e+00 + 13 3.3829109925579108e+00 -7.7854283145617098e-01 -6.1471416338880658e-01 + 14 -4.1269999117458912e-02 9.3253553809356449e-01 -4.9663548861610076e+00 + 15 4.2930245502032669e+00 4.8016878244809185e+00 -1.2067988554549580e+00 + 16 -3.6783956118288792e+01 1.8760442771705005e+01 1.1514035612976591e+02 + 17 4.4141165055486525e+01 -3.4054760176447999e+01 -9.5996384977569576e+01 + 18 2.6593312590300169e+00 6.2866044197349034e+00 -1.0406390620860617e+00 + 19 -2.6868912576483734e+00 -3.5919428389901107e+00 -6.7199629496476021e-01 + 20 2.3122559534773646e+00 1.6848231900639974e+00 1.0223174367536356e-01 + 21 9.0047861017105912e+00 1.1657532054221129e+01 -3.0300252008113389e+01 + 22 1.2602723597354565e+01 2.2333302149108087e+00 2.1993415039821400e+01 + 23 -2.1752703090839589e+01 -1.3807398281546009e+01 8.4647717981317978e+00 + 24 -4.1597044706741348e+00 2.9600068810024190e+01 -1.4377966609809059e+01 + 25 1.8008123772533907e+01 -4.7255601865067156e+00 1.6011744232774660e+01 + 26 -1.3270414090792938e+01 -2.4692000422804888e+01 -5.6774111520305048e-01 + 27 -7.3472295182173077e+00 3.1133794558171346e+01 -1.2191686027733443e+01 + 28 2.2002916813161221e+01 -1.1345147346836630e+01 1.5336216642368582e+01 + 29 -1.4484026442375008e+01 -1.9880794776432037e+01 -3.1367163092441239e+00 +... diff --git a/unittest/force-styles/tests/mol-pair-mm3_switch3_coulgauss_table.yaml b/unittest/force-styles/tests/mol-pair-mm3_switch3_coulgauss_table.yaml new file mode 100644 index 0000000000..e1b11baa5d --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-mm3_switch3_coulgauss_table.yaml @@ -0,0 +1,99 @@ +--- +lammps_version: 10 Mar 2021 +date_generated: Thu Apr 1 12:40:49 202 +epsilon: 5e-13 +prerequisites: ! | + atom full + pair mm3/switch3/coulgauss/long + kspace ewald +pre_commands: ! "" +post_commands: ! | + pair_modify mix arithmetic + pair_modify table 16 + kspace_style ewald 1.0e-6 + kspace_modify gewald 0.3 + kspace_modify compute no +input_file: in.fourmol +pair_style: mm3/switch3/coulgauss/long 8.0 2.0 +pair_coeff: ! | + 1 1 0.02 2.5 1.0 + 2 2 0.005 1.0 0.7 + 2 4 0.005 0.5 0.7 + 3 3 0.02 3.2 1.3 + 4 4 0.015 3.1 1.2 + 5 5 0.015 3.1 1.2 +extract: ! | + epsilon 2 + sigma 2 + gamma 2 + cut_coul 0 +natoms: 29 +init_vdwl: 38.1287498820824 +init_coul: 262.631410551483 +init_stress: ! |- + -9.1891422055344222e+01 -1.3287971490682878e+02 -3.2601696704317601e+02 3.0074184644070325e+01 -4.6650710964193243e+00 -8.2199034124021594e+01 +init_forces: ! |2 + 1 2.0409891887601410e+00 -1.8543276766039128e+01 -3.5869858368636784e+01 + 2 -1.8468129835801221e+01 -1.7027856421838862e+01 2.0713360489903284e+01 + 3 1.0001881406750512e+01 5.9235891391581845e+01 2.4372336084088403e+01 + 4 -4.5761624275299884e+00 -9.8945350885057237e-01 -3.3785799799517919e+00 + 5 -3.6934400978815565e+00 -4.0696597085993824e+00 3.8826789611765924e+00 + 6 7.6754813581654659e+01 -9.5808743568025008e+01 -9.3227047744836440e+01 + 7 -2.1177650577773125e+01 2.8793163867818368e+01 1.2529350475732382e+02 + 8 -2.1450096906263081e+01 1.0356391487008732e+01 -2.8955418913514073e+01 + 9 -8.2497921762950064e+00 -1.3077028158654645e+01 -3.6173489972491325e+01 + 10 -5.3511691030159355e+01 6.0900975401823587e+01 1.8391820698964121e+01 + 11 -1.3170241765068751e+00 -3.2364688471564778e+00 -4.4029421800959856e+00 + 12 2.5797191259942942e+01 -7.5496408222462352e-01 -2.6346170181534139e+00 + 13 3.3781783640778875e+00 -7.7635863919210357e-01 -6.1835202435311720e-01 + 14 -2.5357429751907436e-02 9.3547306506041328e-01 -4.9468892490621892e+00 + 15 4.2707741612200945e+00 4.7941151727292111e+00 -1.2015238312568339e+00 + 16 -3.6573745369001358e+01 1.8565540172135101e+01 1.1446966581907569e+02 + 17 4.3913383313135455e+01 -3.3849656059945403e+01 -9.5337593796166914e+01 + 18 2.6570103088653938e+00 6.2826342874977836e+00 -1.0356880920834588e+00 + 19 -2.6993402231458812e+00 -3.5969203390445723e+00 -6.8072401315458542e-01 + 20 2.3243806398348510e+00 1.6918060433951427e+00 1.0886287880838207e-01 + 21 8.8572291262962786e+00 1.1602893764611768e+01 -3.0057629738908702e+01 + 22 1.2429503818390431e+01 2.1605538409495715e+00 2.1808497451102578e+01 + 23 -2.1432718024616804e+01 -1.3678273926219282e+01 8.4081118535203938e+00 + 24 -3.9016919979164766e+00 2.9074424960765882e+01 -1.3996422102746218e+01 + 25 1.7462839220414320e+01 -4.6818055105547502e+00 1.5548837113535589e+01 + 26 -1.2984514969825625e+01 -2.4211627227692777e+01 -4.8885079054435532e-01 + 27 -7.1989694398744213e+00 3.0862600181437756e+01 -1.2113492591495778e+01 + 28 2.1728883036290242e+01 -1.1241488592261051e+01 1.5185682250007966e+01 + 29 -1.4356732743290538e+01 -1.9712882280516450e+01 -3.0642379500547996e+00 +run_vdwl: 37.735102831577 +run_coul: 262.634996567417 +run_stress: ! |- + -9.3272087816450096e+01 -1.3382216892660497e+02 -3.2672292496064199e+02 2.9759550012391575e+01 -4.9209020012813669e+00 -8.2642482482441096e+01 +run_forces: ! |2 + 1 2.0020633315697571e+00 -1.8597540312576371e+01 -3.5898847150887825e+01 + 2 -1.8527112685977595e+01 -1.7111767435468980e+01 2.0691356245503808e+01 + 3 1.0099461000123771e+01 5.9365749899001820e+01 2.4423492074447349e+01 + 4 -4.5756545930134305e+00 -9.8171217238369679e-01 -3.3833945796207656e+00 + 5 -3.6935769629718820e+00 -4.0701894718259650e+00 3.8892346120926988e+00 + 6 7.6571693742405060e+01 -9.5745009619986718e+01 -9.3149402824851791e+01 + 7 -2.1146520723115522e+01 2.8805359357005347e+01 1.2508940510400312e+02 + 8 -2.1038406658511651e+01 9.9856753020536395e+00 -2.8916677199745425e+01 + 9 -8.2725040661224440e+00 -1.3032515389877304e+01 -3.6169607187530971e+01 + 10 -5.3760826866916233e+01 6.1170224662661617e+01 1.8495907188455345e+01 + 11 -1.3253793686585611e+00 -3.2541579724226799e+00 -4.4355037885599886e+00 + 12 2.5785718921609639e+01 -7.4878876652861359e-01 -2.6134482478760357e+00 + 13 3.3829110641517599e+00 -7.7854300168776425e-01 -6.1471395974905052e-01 + 14 -4.1270221660368221e-02 9.3253524130353482e-01 -4.9663546372704301e+00 + 15 4.2930244204525003e+00 4.8016875903370053e+00 -1.2067983339497499e+00 + 16 -3.6783955303667234e+01 1.8760441796324653e+01 1.1514035663250905e+02 + 17 4.4141164796979076e+01 -3.4054759175778408e+01 -9.5996385613193283e+01 + 18 2.6593320216432965e+00 6.2866046080770897e+00 -1.0406402388907743e+00 + 19 -2.6868932719674365e+00 -3.5919446222505456e+00 -6.7199643833073341e-01 + 20 2.3122579672731871e+00 1.6848245740968735e+00 1.0223265461108680e-01 + 21 9.0047857933168434e+00 1.1657532538116142e+01 -3.0300251561127794e+01 + 22 1.2602721079420199e+01 2.2333285795234898e+00 2.1993413545558095e+01 + 23 -2.1752700027690018e+01 -1.3807397168507773e+01 8.4647725463156984e+00 + 24 -4.1597043845955195e+00 2.9600069115788433e+01 -1.4377967328816560e+01 + 25 1.8008122136440438e+01 -4.7255613901672264e+00 1.6011743726111732e+01 + 26 -1.3270411937489305e+01 -2.4691999045812377e+01 -5.6773953378636655e-01 + 27 -7.3472299042491755e+00 3.1133794605717583e+01 -1.2191686159483819e+01 + 28 2.2002914561082278e+01 -1.1345148097691201e+01 1.5336215539418586e+01 + 29 -1.4484023859861420e+01 -1.9880794227041598e+01 -3.1367150853552728e+00 +... From 2dfafe4adb8eb7646f1587c59410681538adabb4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 2 Apr 2021 12:07:43 -0400 Subject: [PATCH 216/257] add is_file() special variable function and unit tests for it --- doc/src/variable.rst | 8 ++++++-- src/variable.cpp | 24 ++++++++++++++++++++++-- unittest/commands/test_variables.cpp | 14 +++++++++++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/doc/src/variable.rst b/doc/src/variable.rst index 6a6cdf9a6d..af324c180f 100644 --- a/doc/src/variable.rst +++ b/doc/src/variable.rst @@ -65,8 +65,8 @@ Syntax bound(group,dir,region), gyration(group,region), ke(group,reigon), angmom(group,dim,region), torque(group,dim,region), inertia(group,dimdim,region), omega(group,dim,region) - special functions = sum(x), min(x), max(x), ave(x), trap(x), slope(x), gmask(x), rmask(x), grmask(x,y), next(x) - feature functions = is_active(category,feature,exact), is_defined(category,id,exact) + special functions = sum(x), min(x), max(x), ave(x), trap(x), slope(x), gmask(x), rmask(x), grmask(x,y), next(x), is_file(name) + feature functions = is_available(category,feature), is_active(category,feature), is_defined(category,id) atom value = id[i], mass[i], type[i], mol[i], x[i], y[i], z[i], vx[i], vy[i], vz[i], fx[i], fy[i], fz[i], q[i] atom vector = id, mass, type, mol, x, y, z, vx, vy, vz, fx, fy, fz, q compute references = c_ID, c_ID[i], c_ID[i][j], C_ID, C_ID[i] @@ -821,6 +821,10 @@ Special Functions Special functions take specific kinds of arguments, meaning their arguments cannot be formulas themselves. +The is_file(x) function is a test whether 'x' is a (readable) file +and returns 1 in this case, otherwise it returns 0. For that 'x' +is taken as a literal string and must not have any blanks in it. + The sum(x), min(x), max(x), ave(x), trap(x), and slope(x) functions each take 1 argument which is of the form "c_ID" or "c_ID[N]" or "f_ID" or "f_ID[N]" or "v_name". The first two are computes and the diff --git a/src/variable.cpp b/src/variable.cpp index 3bf88db55e..1a4feb3573 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -65,7 +65,7 @@ enum{DONE,ADD,SUBTRACT,MULTIPLY,DIVIDE,CARAT,MODULO,UNARY, SQRT,EXP,LN,LOG,ABS,SIN,COS,TAN,ASIN,ACOS,ATAN,ATAN2, RANDOM,NORMAL,CEIL,FLOOR,ROUND,RAMP,STAGGER,LOGFREQ,LOGFREQ2, LOGFREQ3,STRIDE,STRIDE2,VDISPLACE,SWIGGLE,CWIGGLE,GMASK,RMASK, - GRMASK,IS_ACTIVE,IS_DEFINED,IS_AVAILABLE, + GRMASK,IS_ACTIVE,IS_DEFINED,IS_AVAILABLE,IS_FILE, VALUE,ATOMARRAY,TYPEARRAY,INTARRAY,BIGINTARRAY,VECTORARRAY}; // customize by adding a special function @@ -4079,7 +4079,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree, strcmp(word,"gmask") && strcmp(word,"rmask") && strcmp(word,"grmask") && strcmp(word,"next") && strcmp(word,"is_active") && strcmp(word,"is_defined") && - strcmp(word,"is_available")) + strcmp(word,"is_available") && strcmp(word,"is_file")) return 0; // parse contents for comma-separated args @@ -4488,6 +4488,26 @@ int Variable::special_function(char *word, char *contents, Tree **tree, // save value in tree or on argstack + if (tree) { + Tree *newtree = new Tree(); + newtree->type = VALUE; + newtree->value = value; + newtree->first = newtree->second = nullptr; + newtree->nextra = 0; + treestack[ntreestack++] = newtree; + } else argstack[nargstack++] = value; + + } else if (strcmp(word,"is_file") == 0) { + if (narg != 1) + print_var_error(FLERR,"Invalid is_file() function in " + "variable formula",ivar); + + FILE *fp = fopen(args[0],"r"); + value = (fp == nullptr) ? 0.0 : 1.0; + if (fp) fclose(fp); + + // save value in tree or on argstack + if (tree) { Tree *newtree = new Tree(); newtree->type = VALUE; diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index eb533aee86..97f874a856 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -142,12 +142,13 @@ TEST_F(VariableTest, CreateDelete) command("variable ten2 uloop 4"); command("variable ten3 uloop 4 pad"); command("variable dummy index 0"); + command("variable file equal is_file(MYFILE)"); END_HIDE_OUTPUT(); - ASSERT_EQ(variable->nvar, 17); + ASSERT_EQ(variable->nvar, 18); BEGIN_HIDE_OUTPUT(); command("variable dummy delete"); END_HIDE_OUTPUT(); - ASSERT_EQ(variable->nvar, 16); + ASSERT_EQ(variable->nvar, 17); ASSERT_THAT(variable->retrieve("three"), StrEq("three")); variable->set_string("three", "four"); ASSERT_THAT(variable->retrieve("three"), StrEq("four")); @@ -158,6 +159,13 @@ TEST_F(VariableTest, CreateDelete) ASSERT_THAT(variable->retrieve("eight"), StrEq("")); variable->internal_set(variable->find("ten"), 2.5); ASSERT_THAT(variable->retrieve("ten"), StrEq("2.5")); + ASSERT_THAT(variable->retrieve("file"), StrEq("0")); + FILE *fp = fopen("MYFILE","w"); + fputs(" ",fp); + fclose(fp); + ASSERT_THAT(variable->retrieve("file"), StrEq("1")); + unlink("MYFILE"); + ASSERT_THAT(variable->retrieve("file"), StrEq("0")); ASSERT_EQ(variable->equalstyle(variable->find("one")), 0); ASSERT_EQ(variable->equalstyle(variable->find("two")), 1); @@ -200,7 +208,7 @@ TEST_F(VariableTest, CreateDelete) TEST_F(VariableTest, AtomicSystem) { - command("atom_modify map array"); + HIDE_OUTPUT([&] { command("atom_modify map array"); }); atomic_system(); file_vars(); From 887eb40ad493eedf61f21ca9c19186c8181fb7a1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 2 Apr 2021 12:07:59 -0400 Subject: [PATCH 217/257] fix crash when requesting verbose output. --- unittest/testing/core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/testing/core.h b/unittest/testing/core.h index deab845573..75b0564d02 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -60,7 +60,7 @@ public: } void BEGIN_CAPTURE_OUTPUT() { - if (!verbose) ::testing::internal::CaptureStdout(); + ::testing::internal::CaptureStdout(); } std::string END_CAPTURE_OUTPUT() { From d24f74b582408a308bc0fd37fda06e175239b1d8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 2 Apr 2021 12:31:46 -0400 Subject: [PATCH 218/257] add stop on file example to fix halt docs --- doc/src/fix_halt.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/src/fix_halt.rst b/doc/src/fix_halt.rst index 964132518d..06f068bb7d 100644 --- a/doc/src/fix_halt.rst +++ b/doc/src/fix_halt.rst @@ -115,6 +115,18 @@ The version with "bondmax" will just run somewhat faster, due to less overhead in computing bond lengths and not storing them in a separate compute. +A variable can be used to implement a large variety of conditions, +including to stop when a specific file exists. Example: + +.. code-block:: LAMMPS + + variable exit equal is_file(EXIT) + fix 10 all halt 100 v_exit != 0 error soft + +Will stop the current run command when a file ``EXIT`` is created +in the current working directory. The condition can be cleared +by removing the file through the :doc:`shell ` command. + The choice of operators listed above are the usual comparison operators. The XOR operation (exclusive or) is also included as "\|\^". In this context, XOR means that if either the attribute or avalue is From c4f59764d43e36b5caa87939c2185e579f5e45fb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 2 Apr 2021 15:28:09 -0400 Subject: [PATCH 219/257] reformat pair_coeff section that got misformatted as string --- .../force-styles/tests/mol-pair-born.yaml | 36 +++++++++---------- .../tests/mol-pair-born_coul_dsf.yaml | 36 +++++++++---------- .../tests/mol-pair-born_coul_long.yaml | 36 +++++++++---------- .../tests/mol-pair-born_coul_msm.yaml | 36 +++++++++---------- .../tests/mol-pair-born_coul_msm_table.yaml | 36 +++++++++---------- .../tests/mol-pair-born_coul_wolf.yaml | 36 +++++++++---------- .../force-styles/tests/mol-pair-morse.yaml | 31 +++++++++------- .../tests/mol-pair-morse_smooth_linear.yaml | 31 +++++++++------- 8 files changed, 144 insertions(+), 134 deletions(-) diff --git a/unittest/force-styles/tests/mol-pair-born.yaml b/unittest/force-styles/tests/mol-pair-born.yaml index 05e77a49b5..f411505f74 100644 --- a/unittest/force-styles/tests/mol-pair-born.yaml +++ b/unittest/force-styles/tests/mol-pair-born.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 24 Aug 2020 -date_generated: Tue Sep 15 09:44:10 202 +lammps_version: 10 Mar 2021 +date_generated: Fri Apr 2 15:14:43 202 epsilon: 5e-14 prerequisites: ! | atom full @@ -9,22 +9,22 @@ pre_commands: ! "" post_commands: ! "" input_file: in.fourmol pair_style: born 8.0 -pair_coeff: ! "1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 - 141.547923828784 \n1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 - 4.09225030876458 \n1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 - 403.51858739517 \n1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 - 303.336540547726 \n1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 - 303.336540547726 \n2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 - 0.177172207445923 \n2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 - 17.5662073921955 \n2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 - 0.000703093129207124 \n2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 - 12.548008396489 \n3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 - 1019.38354056979 \n3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 - 778.254162800904 \n3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 - 778.254162800904 \n4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722\n" +pair_coeff: ! | + 1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 141.547923828784 + 1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 4.09225030876458 + 1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 403.51858739517 + 1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 0.177172207445923 + 2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 17.5662073921955 + 2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 0.000703093129207124 + 2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 12.548008396489 + 3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 1019.38354056979 + 3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 extract: ! | a 2 c 2 diff --git a/unittest/force-styles/tests/mol-pair-born_coul_dsf.yaml b/unittest/force-styles/tests/mol-pair-born_coul_dsf.yaml index c139bd0bc2..a3bacb3f7c 100644 --- a/unittest/force-styles/tests/mol-pair-born_coul_dsf.yaml +++ b/unittest/force-styles/tests/mol-pair-born_coul_dsf.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 24 Aug 2020 -date_generated: Tue Sep 15 09:44:10 202 +lammps_version: 10 Mar 2021 +date_generated: Fri Apr 2 15:14:43 202 epsilon: 5e-14 prerequisites: ! | atom full @@ -9,22 +9,22 @@ pre_commands: ! "" post_commands: ! "" input_file: in.fourmol pair_style: born/coul/dsf 0.25 8.0 -pair_coeff: ! "1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 - 141.547923828784 \n1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 - 4.09225030876458 \n1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 - 403.51858739517 \n1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 - 303.336540547726 \n1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 - 303.336540547726 \n2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 - 0.177172207445923 \n2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 - 17.5662073921955 \n2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 - 0.000703093129207124 \n2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 - 12.548008396489 \n3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 - 1019.38354056979 \n3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 - 778.254162800904 \n3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 - 778.254162800904 \n4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722\n" +pair_coeff: ! | + 1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 141.547923828784 + 1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 4.09225030876458 + 1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 403.51858739517 + 1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 0.177172207445923 + 2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 17.5662073921955 + 2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 0.000703093129207124 + 2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 12.548008396489 + 3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 1019.38354056979 + 3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 extract: ! "" natoms: 29 init_vdwl: 225.01325775005 diff --git a/unittest/force-styles/tests/mol-pair-born_coul_long.yaml b/unittest/force-styles/tests/mol-pair-born_coul_long.yaml index e831e0da9c..7f99ac0b15 100644 --- a/unittest/force-styles/tests/mol-pair-born_coul_long.yaml +++ b/unittest/force-styles/tests/mol-pair-born_coul_long.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 24 Aug 2020 -date_generated: Tue Sep 15 09:44:10 202 +lammps_version: 10 Mar 2021 +date_generated: Fri Apr 2 15:14:43 202 epsilon: 7.5e-14 prerequisites: ! | atom full @@ -14,22 +14,22 @@ post_commands: ! | kspace_modify compute no input_file: in.fourmol pair_style: born/coul/long 8.0 -pair_coeff: ! "1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 - 141.547923828784 \n1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 - 4.09225030876458 \n1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 - 403.51858739517 \n1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 - 303.336540547726 \n1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 - 303.336540547726 \n2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 - 0.177172207445923 \n2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 - 17.5662073921955 \n2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 - 0.000703093129207124 \n2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 - 12.548008396489 \n3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 - 1019.38354056979 \n3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 - 778.254162800904 \n3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 - 778.254162800904 \n4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n" +pair_coeff: ! | + 1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 141.547923828784 + 1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 4.09225030876458 + 1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 403.51858739517 + 1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 0.177172207445923 + 2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 17.5662073921955 + 2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 0.000703093129207124 + 2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 12.548008396489 + 3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 1019.38354056979 + 3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 extract: ! | cut_coul 0 natoms: 29 diff --git a/unittest/force-styles/tests/mol-pair-born_coul_msm.yaml b/unittest/force-styles/tests/mol-pair-born_coul_msm.yaml index e0def1f392..e805c24b28 100644 --- a/unittest/force-styles/tests/mol-pair-born_coul_msm.yaml +++ b/unittest/force-styles/tests/mol-pair-born_coul_msm.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 24 Aug 2020 -date_generated: Tue Sep 15 09:44:10 202 +lammps_version: 10 Mar 2021 +date_generated: Fri Apr 2 15:14:43 202 epsilon: 5e-14 prerequisites: ! | atom full @@ -15,22 +15,22 @@ post_commands: ! | kspace_modify pressure/scalar no # required for USER-OMP with msm input_file: in.fourmol pair_style: born/coul/msm 12.0 -pair_coeff: ! "1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 - 141.547923828784 \n1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 - 4.09225030876458 \n1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 - 403.51858739517 \n1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 - 303.336540547726 \n1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 - 303.336540547726 \n2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 - 0.177172207445923 \n2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 - 17.5662073921955 \n2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 - 0.000703093129207124 \n2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 - 12.548008396489 \n3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 - 1019.38354056979 \n3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 - 778.254162800904 \n3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 - 778.254162800904 \n4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n" +pair_coeff: ! | + 1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 141.547923828784 + 1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 4.09225030876458 + 1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 403.51858739517 + 1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 0.177172207445923 + 2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 17.5662073921955 + 2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 0.000703093129207124 + 2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 12.548008396489 + 3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 1019.38354056979 + 3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 extract: ! | cut_coul 0 natoms: 29 diff --git a/unittest/force-styles/tests/mol-pair-born_coul_msm_table.yaml b/unittest/force-styles/tests/mol-pair-born_coul_msm_table.yaml index fe6a0faf84..75f0f76a44 100644 --- a/unittest/force-styles/tests/mol-pair-born_coul_msm_table.yaml +++ b/unittest/force-styles/tests/mol-pair-born_coul_msm_table.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 24 Aug 2020 -date_generated: Tue Sep 15 09:44:10 202 +lammps_version: 10 Mar 2021 +date_generated: Fri Apr 2 15:14:43 202 epsilon: 5e-14 prerequisites: ! | atom full @@ -15,22 +15,22 @@ post_commands: ! | kspace_modify pressure/scalar no # required for USER-OMP with msm input_file: in.fourmol pair_style: born/coul/msm 12.0 -pair_coeff: ! "1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 - 141.547923828784 \n1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 - 4.09225030876458 \n1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 - 403.51858739517 \n1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 - 303.336540547726 \n1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 - 303.336540547726 \n2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 - 0.177172207445923 \n2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 - 17.5662073921955 \n2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 - 0.000703093129207124 \n2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 - 12.548008396489 \n3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 - 1019.38354056979 \n3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 - 778.254162800904 \n3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 - 778.254162800904 \n4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n" +pair_coeff: ! | + 1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 141.547923828784 + 1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 4.09225030876458 + 1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 403.51858739517 + 1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 0.177172207445923 + 2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 17.5662073921955 + 2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 0.000703093129207124 + 2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 12.548008396489 + 3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 1019.38354056979 + 3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 extract: ! | cut_coul 0 natoms: 29 diff --git a/unittest/force-styles/tests/mol-pair-born_coul_wolf.yaml b/unittest/force-styles/tests/mol-pair-born_coul_wolf.yaml index f3c37e100a..db4ad73e30 100644 --- a/unittest/force-styles/tests/mol-pair-born_coul_wolf.yaml +++ b/unittest/force-styles/tests/mol-pair-born_coul_wolf.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 24 Aug 2020 -date_generated: Tue Sep 15 09:44:11 202 +lammps_version: 10 Mar 2021 +date_generated: Fri Apr 2 15:14:44 202 epsilon: 5e-14 prerequisites: ! | atom full @@ -9,22 +9,22 @@ pre_commands: ! "" post_commands: ! "" input_file: in.fourmol pair_style: born/coul/wolf 0.25 8.0 -pair_coeff: ! "1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 - 141.547923828784 \n1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 - 4.09225030876458 \n1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 - 403.51858739517 \n1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 - 303.336540547726 \n1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 - 303.336540547726 \n2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 - 0.177172207445923 \n2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 - 17.5662073921955 \n2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 - 0.000703093129207124 \n2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 - 12.548008396489 \n3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 - 1019.38354056979 \n3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 - 778.254162800904 \n3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 - 778.254162800904 \n4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722 \n5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 - 592.979935420722\n" +pair_coeff: ! | + 1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 141.547923828784 + 1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 4.09225030876458 + 1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 403.51858739517 + 1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 0.177172207445923 + 2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 17.5662073921955 + 2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 0.000703093129207124 + 2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 12.548008396489 + 3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 1019.38354056979 + 3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 extract: ! "" natoms: 29 init_vdwl: 225.01325775005 diff --git a/unittest/force-styles/tests/mol-pair-morse.yaml b/unittest/force-styles/tests/mol-pair-morse.yaml index cf75cd6dbd..61a66d8ac5 100644 --- a/unittest/force-styles/tests/mol-pair-morse.yaml +++ b/unittest/force-styles/tests/mol-pair-morse.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 24 Aug 2020 -date_generated: Tue Sep 15 09:44:19 202 +lammps_version: 10 Mar 2021 +date_generated: Fri Apr 2 15:27:01 202 epsilon: 5e-14 prerequisites: ! | atom full @@ -9,17 +9,22 @@ pre_commands: ! "" post_commands: ! "" input_file: in.fourmol pair_style: morse 8.0 -pair_coeff: ! "1 1 0.0202798941614106 2.78203488021395 2.725417159299 \n1 2 0.0101167811264648 - 3.9793050302425 1.90749569018897 \n1 3 0.0202934330695928 2.43948720203264 3.10711749999622 - \n1 4 0.0175731334238374 2.48316585521317 3.05258880102438 \n1 5 0.0175731334238374 - 2.48316585521317 3.05258880102438 \n2 2 0.00503064360487288 6.98433077606902 1.08960295117864 - \n2 3 0.0101296013842819 3.31380153807866 2.28919067558352 \n2 4 0.00497405122588691 - 14.0508902925745 0.544416409093563 \n2 5 0.00877114211614446 3.39491256196178 2.23466262511073 - \n3 3 0.0203039874239943 2.17204344301477 3.48881895084762 \n3 4 0.0175825321440736 - 2.20660439192238 3.43428999287994 \n3 5 0.0175825321440736 2.20660439192238 3.43428999287994 - \n4 4 0.0152259201379927 2.24227873774009 3.37976131582396 \n4 5 0.0152259201379927 - 2.24227873774009 3.37976131582396 \n5 5 0.0152259201379927 2.24227873774009 3.37976131582396 - \n" +pair_coeff: ! | + 1 1 0.0202798941614106 2.78203488021395 2.725417159299 + 1 2 0.0101167811264648 3.9793050302425 1.90749569018897 + 1 3 0.0202934330695928 2.43948720203264 3.10711749999622 + 1 4 0.0175731334238374 2.48316585521317 3.05258880102438 + 1 5 0.0175731334238374 2.48316585521317 3.05258880102438 + 2 2 0.00503064360487288 6.98433077606902 1.08960295117864 + 2 3 0.0101296013842819 3.31380153807866 2.28919067558352 + 2 4 0.00497405122588691 14.0508902925745 0.544416409093563 + 2 5 0.00877114211614446 3.39491256196178 2.23466262511073 + 3 3 0.0203039874239943 2.17204344301477 3.48881895084762 + 3 4 0.0175825321440736 2.20660439192238 3.43428999287994 + 3 5 0.0175825321440736 2.20660439192238 3.43428999287994 + 4 4 0.0152259201379927 2.24227873774009 3.37976131582396 + 4 5 0.0152259201379927 2.24227873774009 3.37976131582396 + 5 5 0.0152259201379927 2.24227873774009 3.37976131582396 extract: ! | d0 2 r0 2 diff --git a/unittest/force-styles/tests/mol-pair-morse_smooth_linear.yaml b/unittest/force-styles/tests/mol-pair-morse_smooth_linear.yaml index e933b47a0b..86d749ba25 100644 --- a/unittest/force-styles/tests/mol-pair-morse_smooth_linear.yaml +++ b/unittest/force-styles/tests/mol-pair-morse_smooth_linear.yaml @@ -1,6 +1,6 @@ --- -lammps_version: 24 Aug 2020 -date_generated: Tue Sep 15 09:44:19 202 +lammps_version: 10 Mar 2021 +date_generated: Fri Apr 2 15:27:01 202 epsilon: 5e-14 prerequisites: ! | atom full @@ -9,17 +9,22 @@ pre_commands: ! "" post_commands: ! "" input_file: in.fourmol pair_style: morse/smooth/linear 8.0 -pair_coeff: ! "1 1 0.0202798941614106 2.78203488021395 2.725417159299 \n1 2 0.0101167811264648 - 3.9793050302425 1.90749569018897 \n1 3 0.0202934330695928 2.43948720203264 3.10711749999622 - \n1 4 0.0175731334238374 2.48316585521317 3.05258880102438 \n1 5 0.0175731334238374 - 2.48316585521317 3.05258880102438 \n2 2 0.00503064360487288 6.98433077606902 1.08960295117864 - \n2 3 0.0101296013842819 3.31380153807866 2.28919067558352 \n2 4 0.00497405122588691 - 14.0508902925745 0.544416409093563 \n2 5 0.00877114211614446 3.39491256196178 2.23466262511073 - \n3 3 0.0203039874239943 2.17204344301477 3.48881895084762 \n3 4 0.0175825321440736 - 2.20660439192238 3.43428999287994 \n3 5 0.0175825321440736 2.20660439192238 3.43428999287994 - \n4 4 0.0152259201379927 2.24227873774009 3.37976131582396 \n4 5 0.0152259201379927 - 2.24227873774009 3.37976131582396 \n5 5 0.0152259201379927 2.24227873774009 3.37976131582396 - \n" +pair_coeff: ! | + 1 1 0.0202798941614106 2.78203488021395 2.725417159299 + 1 2 0.0101167811264648 3.9793050302425 1.90749569018897 + 1 3 0.0202934330695928 2.43948720203264 3.10711749999622 + 1 4 0.0175731334238374 2.48316585521317 3.05258880102438 + 1 5 0.0175731334238374 2.48316585521317 3.05258880102438 + 2 2 0.00503064360487288 6.98433077606902 1.08960295117864 + 2 3 0.0101296013842819 3.31380153807866 2.28919067558352 + 2 4 0.00497405122588691 14.0508902925745 0.544416409093563 + 2 5 0.00877114211614446 3.39491256196178 2.23466262511073 + 3 3 0.0203039874239943 2.17204344301477 3.48881895084762 + 3 4 0.0175825321440736 2.20660439192238 3.43428999287994 + 3 5 0.0175825321440736 2.20660439192238 3.43428999287994 + 4 4 0.0152259201379927 2.24227873774009 3.37976131582396 + 4 5 0.0152259201379927 2.24227873774009 3.37976131582396 + 5 5 0.0152259201379927 2.24227873774009 3.37976131582396 extract: ! | d0 2 r0 2 From 160f2cc6307cb5c7e7b3179ca93e0d01de7b8b9f Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 2 Apr 2021 16:11:23 -0400 Subject: [PATCH 220/257] Update ROCm container definitions --- tools/singularity/ubuntu18.04_amd_rocm.def | 2 +- tools/singularity/ubuntu20.04_amd_rocm.def | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/singularity/ubuntu18.04_amd_rocm.def b/tools/singularity/ubuntu18.04_amd_rocm.def index bb04c738c4..7b06970110 100644 --- a/tools/singularity/ubuntu18.04_amd_rocm.def +++ b/tools/singularity/ubuntu18.04_amd_rocm.def @@ -94,7 +94,7 @@ From: ubuntu:18.04 ########################################################################### export PATH=$PATH:/opt/rocm/bin:/opt/rocm/profiler/bin:/opt/rocm/opencl/bin/x86_64 - git clone -b rocm-3.7.x https://github.com/ROCmSoftwarePlatform/hipCUB.git + git clone -b rocm-4.1.x https://github.com/ROCmSoftwarePlatform/hipCUB.git mkdir hipCUB/build cd hipCUB/build CXX=hipcc cmake -D BUILD_TEST=off .. diff --git a/tools/singularity/ubuntu20.04_amd_rocm.def b/tools/singularity/ubuntu20.04_amd_rocm.def index 28d57be341..4eee97ffec 100644 --- a/tools/singularity/ubuntu20.04_amd_rocm.def +++ b/tools/singularity/ubuntu20.04_amd_rocm.def @@ -2,7 +2,7 @@ BootStrap: docker From: ubuntu:20.04 %environment - export PATH=/usr/lib/ccache:/usr/local/cuda-11.0/bin:${PATH}:/opt/rocm/bin:/opt/rocm/profiler/bin:/opt/rocm/opencl/bin/x86_64 + export PATH=/usr/lib/ccache:${PATH}:/opt/rocm/bin:/opt/rocm/profiler/bin:/opt/rocm/opencl/bin/x86_64 %post export DEBIAN_FRONTEND=noninteractive apt-get update @@ -90,7 +90,7 @@ From: ubuntu:20.04 ########################################################################### export PATH=$PATH:/opt/rocm/bin:/opt/rocm/profiler/bin:/opt/rocm/opencl/bin/x86_64 - git clone -b rocm-3.7.x https://github.com/ROCmSoftwarePlatform/hipCUB.git + git clone -b rocm-4.1.x https://github.com/ROCmSoftwarePlatform/hipCUB.git mkdir hipCUB/build cd hipCUB/build CXX=hipcc cmake -D BUILD_TEST=off .. From 79a413aeea135e0968edc9b8dfc1b73b3f6a5886 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 2 Apr 2021 16:15:28 -0400 Subject: [PATCH 221/257] replace calls to sqrt() in constant initializers with precomputed numbers. this also moves those arrays into a separate file and out of the header --- src/USER-PTM/ptm_constants.cpp | 156 +++++++++++++++++++++++ src/USER-PTM/ptm_constants.h | 220 ++++++++------------------------- 2 files changed, 205 insertions(+), 171 deletions(-) create mode 100644 src/USER-PTM/ptm_constants.cpp diff --git a/src/USER-PTM/ptm_constants.cpp b/src/USER-PTM/ptm_constants.cpp new file mode 100644 index 0000000000..82bead2101 --- /dev/null +++ b/src/USER-PTM/ptm_constants.cpp @@ -0,0 +1,156 @@ +/*Copyright (c) 2016 PM Larsen + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "ptm_constants.h" +#include + +const int ptm_num_nbrs[9] = {0, PTM_NUM_NBRS_FCC, PTM_NUM_NBRS_HCP, PTM_NUM_NBRS_BCC, PTM_NUM_NBRS_ICO, PTM_NUM_NBRS_SC, PTM_NUM_NBRS_DCUB, PTM_NUM_NBRS_DHEX, PTM_NUM_NBRS_GRAPHENE}; + +//------------------------------------ +// template structures +//------------------------------------ + +#define MYSQRT2 1.41421356237309504880 +#define MYSQRT3 1.73205080756887729352 +#define MYSQRT5 2.23606797749978969640 +#define MYSQRT6 2.44948974278317809819 +// sqrt((5.0-sqrt(5.0))/10.0): +#define MY5MINUSSQRT5BY10 0.52573111211913360602 +// sqrt((5.0+sqrt(5.0))/10.0): +#define MY5PLUSSQRT5BY10 0.85065080835203993218 +//these point sets have barycentre {0, 0, 0} and are scaled such that the mean neighbour distance is 1 + +const double ptm_template_fcc[PTM_NUM_POINTS_FCC][3] = { + { 0, 0, 0 }, + { MYSQRT2/2, MYSQRT2/2, 0 }, + { 0, MYSQRT2/2, MYSQRT2/2 }, + { MYSQRT2/2, 0, MYSQRT2/2 }, + { -MYSQRT2/2, -MYSQRT2/2, 0 }, + { 0, -MYSQRT2/2, -MYSQRT2/2 }, + { -MYSQRT2/2, 0, -MYSQRT2/2 }, + { -MYSQRT2/2, MYSQRT2/2, 0 }, + { 0, -MYSQRT2/2, MYSQRT2/2 }, + { -MYSQRT2/2, 0, MYSQRT2/2 }, + { MYSQRT2/2, -MYSQRT2/2, 0 }, + { 0, MYSQRT2/2, -MYSQRT2/2 }, + { MYSQRT2/2, 0, -MYSQRT2/2 }, +}; + +const double ptm_template_hcp[PTM_NUM_POINTS_HCP][3] = { + { 0, 0, 0 }, + { 0.5, -MYSQRT3/2, 0 }, + { -1, 0, 0 }, + { -0.5, MYSQRT3/6, -MYSQRT6/3 }, + { 0.5, MYSQRT3/6, -MYSQRT6/3 }, + { 0, -MYSQRT3/3, -MYSQRT6/3 }, + { -0.5, MYSQRT3/2, 0 }, + { 0.5, MYSQRT3/2, 0 }, + { 1, 0, 0 }, + { -0.5, -MYSQRT3/2, 0 }, + { 0, -MYSQRT3/3, MYSQRT6/3 }, + { 0.5, MYSQRT3/6, MYSQRT6/3 }, + { -0.5, MYSQRT3/6, MYSQRT6/3 }, +}; + +const double ptm_template_bcc[PTM_NUM_POINTS_BCC][3] = { + { 0, 0, 0 }, + { 7*MYSQRT3/3-7./2, 7*MYSQRT3/3-7./2, 7*MYSQRT3/3-7./2 }, + { 7./2-7*MYSQRT3/3, 7*MYSQRT3/3-7./2, 7*MYSQRT3/3-7./2 }, + { 7*MYSQRT3/3-7./2, 7*MYSQRT3/3-7./2, 7./2-7*MYSQRT3/3 }, + { 7./2-7*MYSQRT3/3, 7./2-7*MYSQRT3/3, 7*MYSQRT3/3-7./2 }, + { 7*MYSQRT3/3-7./2, 7./2-7*MYSQRT3/3, 7*MYSQRT3/3-7./2 }, + { 7./2-7*MYSQRT3/3, 7*MYSQRT3/3-7./2, 7./2-7*MYSQRT3/3 }, + { 7./2-7*MYSQRT3/3, 7./2-7*MYSQRT3/3, 7./2-7*MYSQRT3/3 }, + { 7*MYSQRT3/3-7./2, 7./2-7*MYSQRT3/3, 7./2-7*MYSQRT3/3 }, + { 14*MYSQRT3/3-7, 0, 0 }, + { 7-14*MYSQRT3/3, 0, 0 }, + { 0, 14*MYSQRT3/3-7, 0 }, + { 0, 7-14*MYSQRT3/3, 0 }, + { 0, 0, 14*MYSQRT3/3-7 }, + { 0, 0, 7-14*MYSQRT3/3 }, +}; + +const double ptm_template_ico[PTM_NUM_POINTS_ICO][3] = { + { 0, 0, 0 }, + { 0, 0, 1 }, + { 0, 0, -1 }, + { -MY5MINUSSQRT5BY10, (5+MYSQRT5)/10, -MYSQRT5/5 }, + { MY5MINUSSQRT5BY10, -(5+MYSQRT5)/10, MYSQRT5/5 }, + { 0, -2*MYSQRT5/5, -MYSQRT5/5 }, + { 0, 2*MYSQRT5/5, MYSQRT5/5 }, + { MY5PLUSSQRT5BY10, -(5-MYSQRT5)/10, -MYSQRT5/5 }, + { -MY5PLUSSQRT5BY10, (5-MYSQRT5)/10, MYSQRT5/5 }, + { -MY5PLUSSQRT5BY10, -(5-MYSQRT5)/10, -MYSQRT5/5 }, + { MY5PLUSSQRT5BY10, (5-MYSQRT5)/10, MYSQRT5/5 }, + { MY5MINUSSQRT5BY10, (5+MYSQRT5)/10, -MYSQRT5/5 }, + { -MY5MINUSSQRT5BY10, -(5+MYSQRT5)/10, MYSQRT5/5 }, +}; + +const double ptm_template_sc[PTM_NUM_POINTS_SC][3] = { + { 0, 0, 0 }, + { 0, 0, -1 }, + { 0, 0, 1 }, + { 0, -1, 0 }, + { 0, 1, 0 }, + { -1, 0, 0 }, + { 1, 0, 0 }, +}; + +const double ptm_template_dcub[PTM_NUM_POINTS_DCUB][3] = { + { 0, 0, 0 }, + { 4/(MYSQRT3+6*MYSQRT2), 4/(MYSQRT3+6*MYSQRT2), 4/(MYSQRT3+6*MYSQRT2) }, + { 4/(MYSQRT3+6*MYSQRT2), -4/(MYSQRT3+6*MYSQRT2), -4/(MYSQRT3+6*MYSQRT2) }, + { -4/(MYSQRT3+6*MYSQRT2), -4/(MYSQRT3+6*MYSQRT2), 4/(MYSQRT3+6*MYSQRT2) }, + { -4/(MYSQRT3+6*MYSQRT2), 4/(MYSQRT3+6*MYSQRT2), -4/(MYSQRT3+6*MYSQRT2) }, + { 8/(MYSQRT3+6*MYSQRT2), 8/(MYSQRT3+6*MYSQRT2), 0 }, + { 0, 8/(MYSQRT3+6*MYSQRT2), 8/(MYSQRT3+6*MYSQRT2) }, + { 8/(MYSQRT3+6*MYSQRT2), 0, 8/(MYSQRT3+6*MYSQRT2) }, + { 0, -8/(MYSQRT3+6*MYSQRT2), -8/(MYSQRT3+6*MYSQRT2) }, + { 8/(MYSQRT3+6*MYSQRT2), -8/(MYSQRT3+6*MYSQRT2), 0 }, + { 8/(MYSQRT3+6*MYSQRT2), 0, -8/(MYSQRT3+6*MYSQRT2) }, + { -8/(MYSQRT3+6*MYSQRT2), -8/(MYSQRT3+6*MYSQRT2), 0 }, + { 0, -8/(MYSQRT3+6*MYSQRT2), 8/(MYSQRT3+6*MYSQRT2) }, + { -8/(MYSQRT3+6*MYSQRT2), 0, 8/(MYSQRT3+6*MYSQRT2) }, + { -8/(MYSQRT3+6*MYSQRT2), 0, -8/(MYSQRT3+6*MYSQRT2) }, + { -8/(MYSQRT3+6*MYSQRT2), 8/(MYSQRT3+6*MYSQRT2), 0 }, + { 0, 8/(MYSQRT3+6*MYSQRT2), -8/(MYSQRT3+6*MYSQRT2) }, +}; + +const double ptm_template_dhex[PTM_NUM_POINTS_DHEX][3] = { + { 0, 0, 0 }, + { -4*MYSQRT2/(MYSQRT3+6*MYSQRT2), 4*MYSQRT6/(3*(MYSQRT3+6*MYSQRT2)), -4*MYSQRT3/(3*MYSQRT3+18*MYSQRT2) }, + { 0, -8*MYSQRT6/(3*MYSQRT3+18*MYSQRT2), -4*MYSQRT3/(3*MYSQRT3+18*MYSQRT2) }, + { 4*MYSQRT2/(MYSQRT3+6*MYSQRT2), 4*MYSQRT6/(3*(MYSQRT3+6*MYSQRT2)), -4*MYSQRT3/(3*MYSQRT3+18*MYSQRT2) }, + { 0, 0, 4*MYSQRT3/(MYSQRT3+6*MYSQRT2) }, + { -8*MYSQRT2/(MYSQRT3+6*MYSQRT2), 0, 0 }, + { -4*MYSQRT2/(MYSQRT3+6*MYSQRT2), 4*MYSQRT6/(3*(MYSQRT3+6*MYSQRT2)), -16*MYSQRT3/(3*(MYSQRT3+6*MYSQRT2)) }, + { -4*MYSQRT2/(MYSQRT3+6*MYSQRT2), 4*MYSQRT6/(MYSQRT3+6*MYSQRT2), 0 }, + { 4*MYSQRT2/(MYSQRT3+6*MYSQRT2), -4*MYSQRT6/(MYSQRT3+6*MYSQRT2), 0 }, + { 0, -8*MYSQRT6/(3*MYSQRT3+18*MYSQRT2), -16*MYSQRT3/(3*(MYSQRT3+6*MYSQRT2)) }, + { -4*MYSQRT2/(MYSQRT3+6*MYSQRT2), -4*MYSQRT6/(MYSQRT3+6*MYSQRT2), 0 }, + { 4*MYSQRT2/(MYSQRT3+6*MYSQRT2), 4*MYSQRT6/(3*(MYSQRT3+6*MYSQRT2)), -16*MYSQRT3/(3*(MYSQRT3+6*MYSQRT2)) }, + { 4*MYSQRT2/(MYSQRT3+6*MYSQRT2), 4*MYSQRT6/(MYSQRT3+6*MYSQRT2), 0 }, + { 8*MYSQRT2/(MYSQRT3+6*MYSQRT2), 0, 0 }, + { 0, -8*MYSQRT6/(3*MYSQRT3+18*MYSQRT2), 16*MYSQRT3/(3*(MYSQRT3+6*MYSQRT2)) }, + { 4*MYSQRT2/(MYSQRT3+6*MYSQRT2), 4*MYSQRT6/(3*(MYSQRT3+6*MYSQRT2)), 16*MYSQRT3/(3*(MYSQRT3+6*MYSQRT2)) }, + { -4*MYSQRT2/(MYSQRT3+6*MYSQRT2), 4*MYSQRT6/(3*(MYSQRT3+6*MYSQRT2)), 16*MYSQRT3/(3*(MYSQRT3+6*MYSQRT2)) }, +}; + +const double ptm_template_graphene[PTM_NUM_POINTS_GRAPHENE][3] = { + { 0, 0, 0 }, + { 0, -3./11+6*MYSQRT3/11, 0 }, + { -3*MYSQRT3/22+9./11, -3*MYSQRT3/11+3./22, 0 }, + { -9./11+3*MYSQRT3/22, -3*MYSQRT3/11+3./22, 0 }, + { -9./11+3*MYSQRT3/22, -9./22+9*MYSQRT3/11, 0 }, + { -3*MYSQRT3/22+9./11, -9./22+9*MYSQRT3/11, 0 }, + { -3*MYSQRT3/11+18./11, 0, 0 }, + { -3*MYSQRT3/22+9./11, -9*MYSQRT3/11+9./22, 0 }, + { -9./11+3*MYSQRT3/22, -9*MYSQRT3/11+9./22, 0 }, + { -18./11+3*MYSQRT3/11, 0, 0 }, +}; diff --git a/src/USER-PTM/ptm_constants.h b/src/USER-PTM/ptm_constants.h index c3882f622c..898ded6b49 100644 --- a/src/USER-PTM/ptm_constants.h +++ b/src/USER-PTM/ptm_constants.h @@ -10,63 +10,61 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #ifndef PTM_CONSTANTS_H #define PTM_CONSTANTS_H -#include - //------------------------------------ // definitions //------------------------------------ -#define PTM_NO_ERROR 0 +#define PTM_NO_ERROR 0 -#define PTM_CHECK_FCC (1 << 0) -#define PTM_CHECK_HCP (1 << 1) -#define PTM_CHECK_BCC (1 << 2) -#define PTM_CHECK_ICO (1 << 3) -#define PTM_CHECK_SC (1 << 4) -#define PTM_CHECK_DCUB (1 << 5) -#define PTM_CHECK_DHEX (1 << 6) -#define PTM_CHECK_GRAPHENE (1 << 7) -#define PTM_CHECK_DEFAULT (PTM_CHECK_FCC | PTM_CHECK_HCP | PTM_CHECK_ICO | PTM_CHECK_BCC) +#define PTM_CHECK_FCC (1 << 0) +#define PTM_CHECK_HCP (1 << 1) +#define PTM_CHECK_BCC (1 << 2) +#define PTM_CHECK_ICO (1 << 3) +#define PTM_CHECK_SC (1 << 4) +#define PTM_CHECK_DCUB (1 << 5) +#define PTM_CHECK_DHEX (1 << 6) +#define PTM_CHECK_GRAPHENE (1 << 7) +#define PTM_CHECK_DEFAULT (PTM_CHECK_FCC | PTM_CHECK_HCP | PTM_CHECK_ICO | PTM_CHECK_BCC) #define PTM_CHECK_ALL (PTM_CHECK_SC | PTM_CHECK_FCC | PTM_CHECK_HCP | PTM_CHECK_ICO | PTM_CHECK_BCC | PTM_CHECK_DCUB | PTM_CHECK_DHEX | PTM_CHECK_GRAPHENE) -#define PTM_MATCH_NONE 0 -#define PTM_MATCH_FCC 1 -#define PTM_MATCH_HCP 2 -#define PTM_MATCH_BCC 3 -#define PTM_MATCH_ICO 4 -#define PTM_MATCH_SC 5 -#define PTM_MATCH_DCUB 6 -#define PTM_MATCH_DHEX 7 -#define PTM_MATCH_GRAPHENE 8 +#define PTM_MATCH_NONE 0 +#define PTM_MATCH_FCC 1 +#define PTM_MATCH_HCP 2 +#define PTM_MATCH_BCC 3 +#define PTM_MATCH_ICO 4 +#define PTM_MATCH_SC 5 +#define PTM_MATCH_DCUB 6 +#define PTM_MATCH_DHEX 7 +#define PTM_MATCH_GRAPHENE 8 -#define PTM_ALLOY_NONE 0 -#define PTM_ALLOY_PURE 1 -#define PTM_ALLOY_L10 2 -#define PTM_ALLOY_L12_CU 3 -#define PTM_ALLOY_L12_AU 4 -#define PTM_ALLOY_B2 5 -#define PTM_ALLOY_SIC 6 -#define PTM_ALLOY_BN 7 +#define PTM_ALLOY_NONE 0 +#define PTM_ALLOY_PURE 1 +#define PTM_ALLOY_L10 2 +#define PTM_ALLOY_L12_CU 3 +#define PTM_ALLOY_L12_AU 4 +#define PTM_ALLOY_B2 5 +#define PTM_ALLOY_SIC 6 +#define PTM_ALLOY_BN 7 #define PTM_MAX_INPUT_POINTS 19 -#define PTM_MAX_NBRS 16 -#define PTM_MAX_POINTS (PTM_MAX_NBRS + 1) -#define PTM_MAX_FACETS 28 //2 * PTM_MAX_NBRS - 4 -#define PTM_MAX_EDGES 42 //3 * PTM_MAX_NBRS - 6 +#define PTM_MAX_NBRS 16 +#define PTM_MAX_POINTS (PTM_MAX_NBRS + 1) +#define PTM_MAX_FACETS 28 //2 * PTM_MAX_NBRS - 4 +#define PTM_MAX_EDGES 42 //3 * PTM_MAX_NBRS - 6 //------------------------------------ // number of neighbours //------------------------------------ -#define PTM_NUM_NBRS_FCC 12 -#define PTM_NUM_NBRS_HCP 12 -#define PTM_NUM_NBRS_BCC 14 -#define PTM_NUM_NBRS_ICO 12 -#define PTM_NUM_NBRS_SC 6 -#define PTM_NUM_NBRS_DCUB 16 -#define PTM_NUM_NBRS_DHEX 16 -#define PTM_NUM_NBRS_GRAPHENE 9 +#define PTM_NUM_NBRS_FCC 12 +#define PTM_NUM_NBRS_HCP 12 +#define PTM_NUM_NBRS_BCC 14 +#define PTM_NUM_NBRS_ICO 12 +#define PTM_NUM_NBRS_SC 6 +#define PTM_NUM_NBRS_DCUB 16 +#define PTM_NUM_NBRS_DHEX 16 +#define PTM_NUM_NBRS_GRAPHENE 9 #define PTM_NUM_POINTS_FCC (PTM_NUM_NBRS_FCC + 1) #define PTM_NUM_POINTS_HCP (PTM_NUM_NBRS_HCP + 1) @@ -77,142 +75,22 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #define PTM_NUM_POINTS_DHEX (PTM_NUM_NBRS_DHEX + 1) #define PTM_NUM_POINTS_GRAPHENE (PTM_NUM_NBRS_GRAPHENE + 1) -const int ptm_num_nbrs[9] = {0, PTM_NUM_NBRS_FCC, PTM_NUM_NBRS_HCP, PTM_NUM_NBRS_BCC, PTM_NUM_NBRS_ICO, PTM_NUM_NBRS_SC, PTM_NUM_NBRS_DCUB, PTM_NUM_NBRS_DHEX, PTM_NUM_NBRS_GRAPHENE}; +extern const int ptm_num_nbrs[9]; //------------------------------------ // template structures //------------------------------------ -//these point sets have barycentre {0, 0, 0} and are scaled such that the mean neighbour distance is 1 +// these point sets have barycentre {0, 0, 0} and are scaled such that the mean neighbour distance is 1 -const double ptm_template_fcc[PTM_NUM_POINTS_FCC][3] = { - { 0, 0, 0 }, - { sqrt(2)/2, sqrt(2)/2, 0 }, - { 0, sqrt(2)/2, sqrt(2)/2 }, - { sqrt(2)/2, 0, sqrt(2)/2 }, - { -sqrt(2)/2, -sqrt(2)/2, 0 }, - { 0, -sqrt(2)/2, -sqrt(2)/2 }, - { -sqrt(2)/2, 0, -sqrt(2)/2 }, - { -sqrt(2)/2, sqrt(2)/2, 0 }, - { 0, -sqrt(2)/2, sqrt(2)/2 }, - { -sqrt(2)/2, 0, sqrt(2)/2 }, - { sqrt(2)/2, -sqrt(2)/2, 0 }, - { 0, sqrt(2)/2, -sqrt(2)/2 }, - { sqrt(2)/2, 0, -sqrt(2)/2 }, -}; - -const double ptm_template_hcp[PTM_NUM_POINTS_HCP][3] = { - { 0, 0, 0 }, - { 0.5, -sqrt(3)/2, 0 }, - { -1, 0, 0 }, - { -0.5, sqrt(3)/6, -sqrt(6)/3 }, - { 0.5, sqrt(3)/6, -sqrt(6)/3 }, - { 0, -sqrt(3)/3, -sqrt(6)/3 }, - { -0.5, sqrt(3)/2, 0 }, - { 0.5, sqrt(3)/2, 0 }, - { 1, 0, 0 }, - { -0.5, -sqrt(3)/2, 0 }, - { 0, -sqrt(3)/3, sqrt(6)/3 }, - { 0.5, sqrt(3)/6, sqrt(6)/3 }, - { -0.5, sqrt(3)/6, sqrt(6)/3 }, -}; - -const double ptm_template_bcc[PTM_NUM_POINTS_BCC][3] = { - { 0, 0, 0 }, - { 7*sqrt(3)/3-7./2, 7*sqrt(3)/3-7./2, 7*sqrt(3)/3-7./2 }, - { 7./2-7*sqrt(3)/3, 7*sqrt(3)/3-7./2, 7*sqrt(3)/3-7./2 }, - { 7*sqrt(3)/3-7./2, 7*sqrt(3)/3-7./2, 7./2-7*sqrt(3)/3 }, - { 7./2-7*sqrt(3)/3, 7./2-7*sqrt(3)/3, 7*sqrt(3)/3-7./2 }, - { 7*sqrt(3)/3-7./2, 7./2-7*sqrt(3)/3, 7*sqrt(3)/3-7./2 }, - { 7./2-7*sqrt(3)/3, 7*sqrt(3)/3-7./2, 7./2-7*sqrt(3)/3 }, - { 7./2-7*sqrt(3)/3, 7./2-7*sqrt(3)/3, 7./2-7*sqrt(3)/3 }, - { 7*sqrt(3)/3-7./2, 7./2-7*sqrt(3)/3, 7./2-7*sqrt(3)/3 }, - { 14*sqrt(3)/3-7, 0, 0 }, - { 7-14*sqrt(3)/3, 0, 0 }, - { 0, 14*sqrt(3)/3-7, 0 }, - { 0, 7-14*sqrt(3)/3, 0 }, - { 0, 0, 14*sqrt(3)/3-7 }, - { 0, 0, 7-14*sqrt(3)/3 }, -}; - -const double ptm_template_ico[PTM_NUM_POINTS_ICO][3] = { - { 0, 0, 0 }, - { 0, 0, 1 }, - { 0, 0, -1 }, - { -sqrt((5-sqrt(5))/10), (5+sqrt(5))/10, -sqrt(5)/5 }, - { sqrt((5-sqrt(5))/10), -(5+sqrt(5))/10, sqrt(5)/5 }, - { 0, -2*sqrt(5)/5, -sqrt(5)/5 }, - { 0, 2*sqrt(5)/5, sqrt(5)/5 }, - { sqrt((5+sqrt(5))/10), -(5-sqrt(5))/10, -sqrt(5)/5 }, - { -sqrt((5+sqrt(5))/10), (5-sqrt(5))/10, sqrt(5)/5 }, - { -sqrt((5+sqrt(5))/10), -(5-sqrt(5))/10, -sqrt(5)/5 }, - { sqrt((5+sqrt(5))/10), (5-sqrt(5))/10, sqrt(5)/5 }, - { sqrt((5-sqrt(5))/10), (5+sqrt(5))/10, -sqrt(5)/5 }, - { -sqrt((5-sqrt(5))/10), -(5+sqrt(5))/10, sqrt(5)/5 }, -}; - -const double ptm_template_sc[PTM_NUM_POINTS_SC][3] = { - { 0, 0, 0 }, - { 0, 0, -1 }, - { 0, 0, 1 }, - { 0, -1, 0 }, - { 0, 1, 0 }, - { -1, 0, 0 }, - { 1, 0, 0 }, -}; - -const double ptm_template_dcub[PTM_NUM_POINTS_DCUB][3] = { - { 0, 0, 0 }, - { 4/(sqrt(3)+6*sqrt(2)), 4/(sqrt(3)+6*sqrt(2)), 4/(sqrt(3)+6*sqrt(2)) }, - { 4/(sqrt(3)+6*sqrt(2)), -4/(sqrt(3)+6*sqrt(2)), -4/(sqrt(3)+6*sqrt(2)) }, - { -4/(sqrt(3)+6*sqrt(2)), -4/(sqrt(3)+6*sqrt(2)), 4/(sqrt(3)+6*sqrt(2)) }, - { -4/(sqrt(3)+6*sqrt(2)), 4/(sqrt(3)+6*sqrt(2)), -4/(sqrt(3)+6*sqrt(2)) }, - { 8/(sqrt(3)+6*sqrt(2)), 8/(sqrt(3)+6*sqrt(2)), 0 }, - { 0, 8/(sqrt(3)+6*sqrt(2)), 8/(sqrt(3)+6*sqrt(2)) }, - { 8/(sqrt(3)+6*sqrt(2)), 0, 8/(sqrt(3)+6*sqrt(2)) }, - { 0, -8/(sqrt(3)+6*sqrt(2)), -8/(sqrt(3)+6*sqrt(2)) }, - { 8/(sqrt(3)+6*sqrt(2)), -8/(sqrt(3)+6*sqrt(2)), 0 }, - { 8/(sqrt(3)+6*sqrt(2)), 0, -8/(sqrt(3)+6*sqrt(2)) }, - { -8/(sqrt(3)+6*sqrt(2)), -8/(sqrt(3)+6*sqrt(2)), 0 }, - { 0, -8/(sqrt(3)+6*sqrt(2)), 8/(sqrt(3)+6*sqrt(2)) }, - { -8/(sqrt(3)+6*sqrt(2)), 0, 8/(sqrt(3)+6*sqrt(2)) }, - { -8/(sqrt(3)+6*sqrt(2)), 0, -8/(sqrt(3)+6*sqrt(2)) }, - { -8/(sqrt(3)+6*sqrt(2)), 8/(sqrt(3)+6*sqrt(2)), 0 }, - { 0, 8/(sqrt(3)+6*sqrt(2)), -8/(sqrt(3)+6*sqrt(2)) }, -}; - -const double ptm_template_dhex[PTM_NUM_POINTS_DHEX][3] = { - { 0, 0, 0 }, - { -4*sqrt(2)/(sqrt(3)+6*sqrt(2)), 4*sqrt(6)/(3*(sqrt(3)+6*sqrt(2))), -4*sqrt(3)/(3*sqrt(3)+18*sqrt(2)) }, - { 0, -8*sqrt(6)/(3*sqrt(3)+18*sqrt(2)), -4*sqrt(3)/(3*sqrt(3)+18*sqrt(2)) }, - { 4*sqrt(2)/(sqrt(3)+6*sqrt(2)), 4*sqrt(6)/(3*(sqrt(3)+6*sqrt(2))), -4*sqrt(3)/(3*sqrt(3)+18*sqrt(2)) }, - { 0, 0, 4*sqrt(3)/(sqrt(3)+6*sqrt(2)) }, - { -8*sqrt(2)/(sqrt(3)+6*sqrt(2)), 0, 0 }, - { -4*sqrt(2)/(sqrt(3)+6*sqrt(2)), 4*sqrt(6)/(3*(sqrt(3)+6*sqrt(2))), -16*sqrt(3)/(3*(sqrt(3)+6*sqrt(2))) }, - { -4*sqrt(2)/(sqrt(3)+6*sqrt(2)), 4*sqrt(6)/(sqrt(3)+6*sqrt(2)), 0 }, - { 4*sqrt(2)/(sqrt(3)+6*sqrt(2)), -4*sqrt(6)/(sqrt(3)+6*sqrt(2)), 0 }, - { 0, -8*sqrt(6)/(3*sqrt(3)+18*sqrt(2)), -16*sqrt(3)/(3*(sqrt(3)+6*sqrt(2))) }, - { -4*sqrt(2)/(sqrt(3)+6*sqrt(2)), -4*sqrt(6)/(sqrt(3)+6*sqrt(2)), 0 }, - { 4*sqrt(2)/(sqrt(3)+6*sqrt(2)), 4*sqrt(6)/(3*(sqrt(3)+6*sqrt(2))), -16*sqrt(3)/(3*(sqrt(3)+6*sqrt(2))) }, - { 4*sqrt(2)/(sqrt(3)+6*sqrt(2)), 4*sqrt(6)/(sqrt(3)+6*sqrt(2)), 0 }, - { 8*sqrt(2)/(sqrt(3)+6*sqrt(2)), 0, 0 }, - { 0, -8*sqrt(6)/(3*sqrt(3)+18*sqrt(2)), 16*sqrt(3)/(3*(sqrt(3)+6*sqrt(2))) }, - { 4*sqrt(2)/(sqrt(3)+6*sqrt(2)), 4*sqrt(6)/(3*(sqrt(3)+6*sqrt(2))), 16*sqrt(3)/(3*(sqrt(3)+6*sqrt(2))) }, - { -4*sqrt(2)/(sqrt(3)+6*sqrt(2)), 4*sqrt(6)/(3*(sqrt(3)+6*sqrt(2))), 16*sqrt(3)/(3*(sqrt(3)+6*sqrt(2))) }, -}; - -const double ptm_template_graphene[PTM_NUM_POINTS_GRAPHENE][3] = { - { 0, 0, 0 }, - { 0, -3./11+6*sqrt(3)/11, 0 }, - { -3*sqrt(3)/22+9./11, -3*sqrt(3)/11+3./22, 0 }, - { -9./11+3*sqrt(3)/22, -3*sqrt(3)/11+3./22, 0 }, - { -9./11+3*sqrt(3)/22, -9./22+9*sqrt(3)/11, 0 }, - { -3*sqrt(3)/22+9./11, -9./22+9*sqrt(3)/11, 0 }, - { -3*sqrt(3)/11+18./11, 0, 0 }, - { -3*sqrt(3)/22+9./11, -9*sqrt(3)/11+9./22, 0 }, - { -9./11+3*sqrt(3)/22, -9*sqrt(3)/11+9./22, 0 }, - { -18./11+3*sqrt(3)/11, 0, 0 }, -}; +extern const double ptm_template_fcc[PTM_NUM_POINTS_FCC][3]; +extern const double ptm_template_hcp[PTM_NUM_POINTS_HCP][3]; +extern const double ptm_template_bcc[PTM_NUM_POINTS_BCC][3]; +extern const double ptm_template_ico[PTM_NUM_POINTS_ICO][3]; +extern const double ptm_template_sc[PTM_NUM_POINTS_SC][3]; +extern const double ptm_template_dcub[PTM_NUM_POINTS_DCUB][3]; +extern const double ptm_template_dhex[PTM_NUM_POINTS_DHEX][3]; +extern const double ptm_template_graphene[PTM_NUM_POINTS_GRAPHENE][3]; #endif From 7d85461e9798793bc2ecbc8aaba5175de05fe92b Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 2 Apr 2021 16:32:25 -0400 Subject: [PATCH 222/257] Prevent compilation from breaking with Python 2 --- src/PYTHON/python_impl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PYTHON/python_impl.cpp b/src/PYTHON/python_impl.cpp index 4c43ca3744..c83385410a 100644 --- a/src/PYTHON/python_impl.cpp +++ b/src/PYTHON/python_impl.cpp @@ -56,6 +56,8 @@ PythonImpl::PythonImpl(LAMMPS *lmp) : Pointers(lmp) nfunc = 0; pfuncs = nullptr; +#if PY_MAJOR_VERSION >= 3 +#ifndef Py_LIMITED_API // check for PYTHONUNBUFFERED environment variable const char * PYTHONUNBUFFERED = getenv("PYTHONUNBUFFERED"); @@ -64,6 +66,8 @@ PythonImpl::PythonImpl(LAMMPS *lmp) : Pointers(lmp) // Force the stdout and stderr streams to be unbuffered. Py_UnbufferedStdioFlag = 1; } +#endif +#endif // one-time initialization of Python interpreter // pyMain stores pointer to main module From af6452065fbaa5bedcb3a942115384cf8f88e2e0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 2 Apr 2021 16:48:13 -0400 Subject: [PATCH 223/257] correct URL to XTC file format docs on the gromacs homepage --- doc/src/dump.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/dump.rst b/doc/src/dump.rst index c94d9a8007..a5f11a792a 100644 --- a/doc/src/dump.rst +++ b/doc/src/dump.rst @@ -349,7 +349,7 @@ the box size stored with the snapshot. The *xtc* style writes XTC files, a compressed trajectory format used by the GROMACS molecular dynamics package, and described -`here `_. +`here `_. The precision used in XTC files can be adjusted via the :doc:`dump_modify ` command. The default value of 1000 means that coordinates are stored to 1/1000 nanometer accuracy. XTC From 2a10b5ba69010cb7df3901876273984a9ff1bbd7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 2 Apr 2021 17:21:34 -0400 Subject: [PATCH 224/257] fix bug causing segfaults --- src/domain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domain.cpp b/src/domain.cpp index abf0d70079..8e666f2a45 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -1826,7 +1826,7 @@ void Domain::delete_region(int iregion) // delete and move other Regions down in list one slot delete regions[iregion]; - for (int i = iregion+1; iregion < nregion; ++i) + for (int i = iregion+1; i < nregion; ++i) regions[i-1] = regions[i]; nregion--; } From abfe8bab5915d833fa88c274ce221dbc8612f7dc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 2 Apr 2021 17:32:29 -0400 Subject: [PATCH 225/257] fix uninitialized memory access issues. consolidate enumerators. --- src/GRANULAR/fix_wall_gran.cpp | 45 ++++++++++++++------------- src/GRANULAR/fix_wall_gran.h | 4 +++ src/GRANULAR/fix_wall_gran_region.cpp | 33 +++++++++----------- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/GRANULAR/fix_wall_gran.cpp b/src/GRANULAR/fix_wall_gran.cpp index 5e8d568b7a..2efc189e6d 100644 --- a/src/GRANULAR/fix_wall_gran.cpp +++ b/src/GRANULAR/fix_wall_gran.cpp @@ -17,29 +17,25 @@ ------------------------------------------------------------------------- */ #include "fix_wall_gran.h" -#include -#include + #include "atom.h" #include "domain.h" -#include "update.h" +#include "error.h" #include "force.h" -#include "modify.h" -#include "respa.h" #include "math_const.h" #include "memory.h" -#include "error.h" +#include "modify.h" #include "neighbor.h" +#include "respa.h" +#include "update.h" + +#include +#include using namespace LAMMPS_NS; using namespace FixConst; using namespace MathConst; -// XYZ PLANE need to be 0,1,2 - -enum{XPLANE=0,YPLANE=1,ZPLANE=2,ZCYLINDER,REGION}; -enum{HOOKE,HOOKE_HISTORY,HERTZ_HISTORY,GRANULAR}; -enum{NONE,CONSTANT,EQUAL}; - #define PI27SQ 266.47931882941264802866 // 27*PI**2 #define THREEROOT3 5.19615242270663202362 // 3*sqrt(3) #define SIXROOT6 14.69693845669906728801 // 6*sqrt(6) @@ -48,18 +44,20 @@ enum{NONE,CONSTANT,EQUAL}; #define THREEQUARTERS 0.75 // 3/4 #define TWOPI 6.28318530717959 // 2*PI -#define EPSILON 1e-10 - -enum {NORMAL_HOOKE, NORMAL_HERTZ, HERTZ_MATERIAL, DMT, JKR}; -enum {VELOCITY, MASS_VELOCITY, VISCOELASTIC, TSUJI}; -enum {TANGENTIAL_NOHISTORY, TANGENTIAL_HISTORY, - TANGENTIAL_MINDLIN, TANGENTIAL_MINDLIN_RESCALE}; -enum {TWIST_NONE, TWIST_SDS, TWIST_MARSHALL}; -enum {ROLL_NONE, ROLL_SDS}; - #define BIG 1.0e20 #define EPSILON 1e-10 +// XYZ PLANE need to be 0,1,2 + +enum {XPLANE=0,YPLANE=1,ZPLANE=2,ZCYLINDER,REGION}; + +enum {NONE,CONSTANT,EQUAL}; +enum {DAMPING_NONE, VELOCITY, MASS_VELOCITY, VISCOELASTIC, TSUJI}; +enum {TANGENTIAL_NONE, TANGENTIAL_NOHISTORY, TANGENTIAL_HISTORY, + TANGENTIAL_MINDLIN, TANGENTIAL_MINDLIN_RESCALE}; +enum {TWIST_NONE, TWIST_SDS, TWIST_MARSHALL}; +enum {ROLL_NONE, ROLL_SDS}; + /* ---------------------------------------------------------------------- */ FixWallGran::FixWallGran(LAMMPS *lmp, int narg, char **arg) : @@ -84,6 +82,10 @@ FixWallGran::FixWallGran(LAMMPS *lmp, int narg, char **arg) : use_history = restart_peratom = 1; if (pairstyle == HOOKE) use_history = restart_peratom = 0; + tangential_history = roll_history = twist_history = 0; + normal_model = NORMAL_NONE; + tangential_model = TANGENTIAL_NONE; + damping_model = DAMPING_NONE; // wall/particle coefficients @@ -120,7 +122,6 @@ FixWallGran::FixWallGran(LAMMPS *lmp, int narg, char **arg) : iarg = 4; damping_model = VISCOELASTIC; roll_model = twist_model = NONE; - tangential_history = roll_history = twist_history = 0; while (iarg < narg) { if (strcmp(arg[iarg], "hooke") == 0) { if (iarg + 2 >= narg) diff --git a/src/GRANULAR/fix_wall_gran.h b/src/GRANULAR/fix_wall_gran.h index a81a4c787c..bf4797e960 100644 --- a/src/GRANULAR/fix_wall_gran.h +++ b/src/GRANULAR/fix_wall_gran.h @@ -26,6 +26,10 @@ namespace LAMMPS_NS { class FixWallGran : public Fix { public: + + enum {HOOKE,HOOKE_HISTORY,HERTZ_HISTORY,GRANULAR}; + enum {NORMAL_NONE, NORMAL_HOOKE, NORMAL_HERTZ, HERTZ_MATERIAL, DMT, JKR}; + FixWallGran(class LAMMPS *, int, char **); virtual ~FixWallGran(); int setmask(); diff --git a/src/GRANULAR/fix_wall_gran_region.cpp b/src/GRANULAR/fix_wall_gran_region.cpp index 5e670a0a07..b051fbea57 100644 --- a/src/GRANULAR/fix_wall_gran_region.cpp +++ b/src/GRANULAR/fix_wall_gran_region.cpp @@ -16,26 +16,21 @@ ------------------------------------------------------------------------- */ #include "fix_wall_gran_region.h" -#include -#include "region.h" + #include "atom.h" -#include "domain.h" -#include "update.h" -#include "memory.h" -#include "error.h" #include "comm.h" +#include "domain.h" +#include "error.h" +#include "memory.h" #include "neighbor.h" +#include "region.h" +#include "update.h" + +#include using namespace LAMMPS_NS; using namespace FixConst; -// same as FixWallGran - -enum{HOOKE,HOOKE_HISTORY,HERTZ_HISTORY,GRANULAR}; -enum {NORMAL_HOOKE, NORMAL_HERTZ, HERTZ_MATERIAL, DMT, JKR}; - -#define BIG 1.0e20 - /* ---------------------------------------------------------------------- */ FixWallGranRegion::FixWallGranRegion(LAMMPS *lmp, int narg, char **arg) : @@ -186,7 +181,7 @@ void FixWallGranRegion::post_force(int /*vflag*/) if (mask[i] & groupbit) { if (!region->match(x[i][0],x[i][1],x[i][2])) continue; - if (pairstyle == GRANULAR && normal_model == JKR) { + if (pairstyle == FixWallGran::GRANULAR && normal_model == FixWallGran::JKR) { nc = region->surface(x[i][0],x[i][1],x[i][2], radius[i]+pulloff_distance(radius[i])); } @@ -228,7 +223,7 @@ void FixWallGranRegion::post_force(int /*vflag*/) rsq = region->contact[ic].r*region->contact[ic].r; - if (pairstyle == GRANULAR && normal_model == JKR) { + if (pairstyle == FixWallGran::GRANULAR && normal_model == FixWallGran::JKR) { if (history_many[i][c2r[ic]][0] == 0.0 && rsq > radius[i]*radius[i]) { for (m = 0; m < size_history; m++) history_many[i][0][m] = 0.0; @@ -264,18 +259,18 @@ void FixWallGranRegion::post_force(int /*vflag*/) else contact = nullptr; - if (pairstyle == HOOKE) + if (pairstyle == FixWallGran::HOOKE) hooke(rsq,dx,dy,dz,vwall,v[i],f[i], omega[i],torque[i],radius[i],meff, contact); - else if (pairstyle == HOOKE_HISTORY) + else if (pairstyle == FixWallGran::HOOKE_HISTORY) hooke_history(rsq,dx,dy,dz,vwall,v[i],f[i], omega[i],torque[i],radius[i],meff, history_many[i][c2r[ic]], contact); - else if (pairstyle == HERTZ_HISTORY) + else if (pairstyle == FixWallGran::HERTZ_HISTORY) hertz_history(rsq,dx,dy,dz,vwall,region->contact[ic].radius, v[i],f[i],omega[i],torque[i], radius[i],meff,history_many[i][c2r[ic]], contact); - else if (pairstyle == GRANULAR) + else if (pairstyle == FixWallGran::GRANULAR) granular(rsq,dx,dy,dz,vwall,region->contact[ic].radius, v[i],f[i],omega[i],torque[i], radius[i],meff,history_many[i][c2r[ic]],contact); From 2c00136f2219760e961baaa2604cc1f3bab849b2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 2 Apr 2021 17:49:15 -0400 Subject: [PATCH 226/257] used correct suffix when installing plugin binaries for testing --- unittest/commands/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/unittest/commands/CMakeLists.txt b/unittest/commands/CMakeLists.txt index a658c8a25d..7cd2687fb7 100644 --- a/unittest/commands/CMakeLists.txt +++ b/unittest/commands/CMakeLists.txt @@ -11,13 +11,13 @@ if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND PKG_PLUGIN) -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} - BUILD_BYPRODUCTS /morse2plugin${CMAKE_SHARED_LIBRARY_SUFFIX} - /nve2plugin${CMAKE_SHARED_LIBRARY_SUFFIX} - /helloplugin${CMAKE_SHARED_LIBRARY_SUFFIX} + BUILD_BYPRODUCTS /morse2plugin${CMAKE_SHARED_MODULE_SUFFIX} + /nve2plugin${CMAKE_SHARED_MODULE_SUFFIX} + /helloplugin${CMAKE_SHARED_MODULE_SUFFIX} INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different - /morse2plugin${CMAKE_SHARED_LIBRARY_SUFFIX} - /nve2plugin${CMAKE_SHARED_LIBRARY_SUFFIX} - /helloplugin${CMAKE_SHARED_LIBRARY_SUFFIX} + /morse2plugin${CMAKE_SHARED_MODULE_SUFFIX} + /nve2plugin${CMAKE_SHARED_MODULE_SUFFIX} + /helloplugin${CMAKE_SHARED_MODULE_SUFFIX} ${CMAKE_CURRENT_BINARY_DIR} TEST_COMMAND "") endif() From 678302bfcb33486ea6cf1320538b203796e02306 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 2 Apr 2021 22:08:39 -0400 Subject: [PATCH 227/257] avoid a floating point exception in RanMars::rayleigh() from taking log(0) --- src/random_mars.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/random_mars.cpp b/src/random_mars.cpp index 621d7d3008..78c6f93ba4 100644 --- a/src/random_mars.cpp +++ b/src/random_mars.cpp @@ -136,13 +136,16 @@ double RanMars::gaussian(double mu, double sigma) double RanMars::rayleigh(double sigma) { - double first,v1; + double v1; - if (sigma <= 0) error->all(FLERR,"Invalid Rayleigh parameter"); + if (sigma <= 0.0) error->all(FLERR,"Invalid Rayleigh parameter"); v1 = uniform(); - first = sigma*sqrt(-2.0*log(v1)); - return first; + // avoid a floating point exception due to log(0.0) + // and just return a very big number + if (v1 == 0.0) return 1.0e300; + + return sigma*sqrt(-2.0*log(v1)); } /* ---------------------------------------------------------------------- From b2e9ffa67371f340ebae59e1285b26e1945b8f07 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 3 Apr 2021 11:15:00 -0400 Subject: [PATCH 228/257] add missing entry to standard packages list --- doc/src/Packages_standard.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/src/Packages_standard.rst b/doc/src/Packages_standard.rst index ab9be69ab3..81623c8d4a 100644 --- a/doc/src/Packages_standard.rst +++ b/doc/src/Packages_standard.rst @@ -71,6 +71,8 @@ package: +----------------------------------+--------------------------------------+----------------------------------------------------+------------------------------------------------------+---------+ | :ref:`PERI ` | Peridynamics models | :doc:`pair_style peri ` | peri | no | +----------------------------------+--------------------------------------+----------------------------------------------------+------------------------------------------------------+---------+ +| :ref:`PLUGIN ` | Plugin loader command | :doc:`plugin ` | plugins | no | ++----------------------------------+--------------------------------------+----------------------------------------------------+------------------------------------------------------+---------+ | :ref:`POEMS ` | coupled rigid body motion | :doc:`fix poems ` | rigid | int | +----------------------------------+--------------------------------------+----------------------------------------------------+------------------------------------------------------+---------+ | :ref:`PYTHON ` | embed Python code in an input script | :doc:`python ` | python | sys | From 5e0b017d30281b7fb94e23a4c53d84defb7467d2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 4 Apr 2021 20:51:58 -0400 Subject: [PATCH 229/257] update information about adding unit tests to reflect recent changes --- doc/src/Developer_unittest.rst | 45 ++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/doc/src/Developer_unittest.rst b/doc/src/Developer_unittest.rst index 4487dff11c..52753ee1b4 100644 --- a/doc/src/Developer_unittest.rst +++ b/doc/src/Developer_unittest.rst @@ -4,10 +4,10 @@ Adding tests for unit testing This section discusses adding or expanding tests for the unit test infrastructure included into the LAMMPS source code distribution. Unlike example inputs, unit tests focus on testing the "local" behavior -of individual features, tend to run very fast, and should be set up to -cover as much of the added code as possible. When contributing code to -the distribution, the LAMMPS developers will appreciate if additions -to the integrated unit test facility are included. +of individual features, tend to run fast, and should be set up to cover +as much of the added code as possible. When contributing code to the +distribution, the LAMMPS developers will appreciate if additions to the +integrated unit test facility are included. Given the complex nature of MD simulations where many operations can only be performed when suitable "real" simulation environment has been @@ -50,6 +50,9 @@ available: * - File name: - Test name: - Description: + * - ``test_argutils.cpp`` + - ArgInfo + - Tests for ``ArgInfo`` class used by LAMMPS * - ``test_fmtlib.cpp`` - FmtLib - Tests for ``fmtlib::`` functions used by LAMMPS @@ -155,23 +158,27 @@ have the desired effect: { ASSERT_EQ(lmp->update->ntimestep, 0); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("reset_timestep 10"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + BEGIN_HIDE_OUTPUT(); + command("reset_timestep 10"); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->update->ntimestep, 10); - if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("reset_timestep 0"); - if (!verbose) ::testing::internal::GetCapturedStdout(); + BEGIN_HIDE_OUTPUT(); + command("reset_timestep 0"); + END_HIDE_OUTPUT(); ASSERT_EQ(lmp->update->ntimestep, 0); + + TEST_FAILURE(".*ERROR: Timestep must be >= 0.*", command("reset_timestep -10");); + TEST_FAILURE(".*ERROR: Illegal reset_timestep .*", command("reset_timestep");); + TEST_FAILURE(".*ERROR: Illegal reset_timestep .*", command("reset_timestep 10 10");); + TEST_FAILURE(".*ERROR: Expected integer .*", command("reset_timestep xxx");); } -Please note the use of the (global) verbose variable to control whether -the LAMMPS command will be silent by capturing the output or not. In -the default case, verbose == false, the test output will be compact and -not mixed with LAMMPS output. However setting the verbose flag (via -setting the ``TEST_ARGS`` environment variable, ``TEST_ARGS=-v``) can be -helpful to understand why tests fail unexpectedly. +Please note the use of the ``BEGIN_HIDE_OUTPUT`` and ``END_HIDE_OUTPUT`` +functions that will capture output from running LAMMPS. This is normally +discarded but by setting the verbose flag (via setting the ``TEST_ARGS`` +environment variable, ``TEST_ARGS=-v``) it can be printed and used to +understand why tests fail unexpectedly. Another complexity of these tests stems from the need to capture situations where LAMMPS will stop with an error, i.e. handle so-called @@ -210,6 +217,12 @@ The following test programs are currently available: * - ``test_lattice_region.cpp`` - LatticeRegion - Tests to validate the :doc:`lattice ` and :doc:`region ` commands + * - ``test_groups.cpp`` + - GroupTest + - Tests to validate the :doc:`group ` command + * - ``test_variables.cpp`` + - VariableTest + - Tests to validate the :doc:`variable ` command * - ``test_kim_commands.cpp`` - KimCommands - Tests for several commands from the :ref:`KIM package ` From d1b6aaa3f3a6e1524864c6d582b9a0220ea5980c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 4 Apr 2021 20:57:29 -0400 Subject: [PATCH 230/257] plugins also have a .so suffix on MacOS (unlike shared libs) --- unittest/commands/test_simple_commands.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index 9173909806..9bd6e74c9b 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -328,11 +328,7 @@ TEST_F(SimpleCommandsTest, Units) #if defined(LMP_PLUGIN) TEST_F(SimpleCommandsTest, Plugin) { -#if defined(__APPLE__) - std::string loadfmt("plugin load {}plugin.dylib"); -#else std::string loadfmt("plugin load {}plugin.so"); -#endif ::testing::internal::CaptureStdout(); lmp->input->one(fmt::format(loadfmt, "hello")); auto text = ::testing::internal::GetCapturedStdout(); From 36c6410fd8fff5a583b8429f4a1c78cecdb87772 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 4 Apr 2021 21:14:12 -0400 Subject: [PATCH 231/257] make skip() function argument optional and default to 1 --- src/tokenizer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tokenizer.h b/src/tokenizer.h index 2db9870866..b3bbf05296 100644 --- a/src/tokenizer.h +++ b/src/tokenizer.h @@ -41,7 +41,7 @@ public: Tokenizer& operator=(Tokenizer&&) = default; void reset(); - void skip(int n); + void skip(int n=1); bool has_next() const; bool contains(const std::string &str) const; std::string next(); @@ -104,7 +104,7 @@ public: bool has_next() const; bool contains(const std::string &value) const; - void skip(int ntokens); + void skip(int ntokens=1); size_t count(); }; From 1e7e930d55ca27103cdc601860c6c53fbfaeef8f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 4 Apr 2021 21:14:40 -0400 Subject: [PATCH 232/257] generalize match to fit all rigid/small derived fixes --- src/velocity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/velocity.cpp b/src/velocity.cpp index b8d2e5229a..f4483074aa 100644 --- a/src/velocity.cpp +++ b/src/velocity.cpp @@ -108,7 +108,7 @@ void Velocity::command(int narg, char **arg) int initcomm = 0; if (style == ZERO && rfix >= 0 && - utils::strmatch(modify->fix[rfix]->style,"^rigid/small")) initcomm = 1; + utils::strmatch(modify->fix[rfix]->style,"^rigid.*/small.*")) initcomm = 1; if ((style == CREATE || style == SET) && temperature && strcmp(temperature->style,"temp/cs") == 0) initcomm = 1; From 67d4302fc7befe67ff157b4e1584067efabea171 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 4 Apr 2021 21:51:06 -0400 Subject: [PATCH 233/257] add tests for tokenizer skip() function and throwing an exception --- unittest/utils/test_tokenizer.cpp | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/unittest/utils/test_tokenizer.cpp b/unittest/utils/test_tokenizer.cpp index 69ec7a55d2..ec097abf62 100644 --- a/unittest/utils/test_tokenizer.cpp +++ b/unittest/utils/test_tokenizer.cpp @@ -43,6 +43,18 @@ TEST(Tokenizer, two_words) ASSERT_EQ(t.count(), 2); } +TEST(Tokenizer, skip) +{ + Tokenizer t("test word", " "); + ASSERT_TRUE(t.has_next()); + t.skip(); + ASSERT_TRUE(t.has_next()); + t.skip(1); + ASSERT_FALSE(t.has_next()); + ASSERT_EQ(t.count(), 2); + ASSERT_THROW(t.skip(), TokenizerException); +} + TEST(Tokenizer, prefix_separators) { Tokenizer t(" test word", " "); @@ -63,6 +75,18 @@ TEST(Tokenizer, iterate_words) ASSERT_EQ(t.count(), 2); } +TEST(Tokenizer, copy_constructor) +{ + Tokenizer t(" test word ", " "); + ASSERT_THAT(t.next(), Eq("test")); + ASSERT_THAT(t.next(), Eq("word")); + ASSERT_EQ(t.count(), 2); + Tokenizer u(t); + ASSERT_THAT(u.next(), Eq("test")); + ASSERT_THAT(u.next(), Eq("word")); + ASSERT_EQ(u.count(), 2); +} + TEST(Tokenizer, no_separator_path) { Tokenizer t("one", ":"); @@ -139,6 +163,26 @@ TEST(ValueTokenizer, empty_string) ASSERT_FALSE(values.has_next()); } +TEST(ValueTokenizer, two_words) +{ + ValueTokenizer t("test word", " "); + ASSERT_THAT(t.next_string(), Eq("test")); + ASSERT_THAT(t.next_string(), Eq("word")); + ASSERT_THROW(t.next_string(), TokenizerException); +} + +TEST(ValueTokenizer, skip) +{ + ValueTokenizer t("test word", " "); + ASSERT_TRUE(t.has_next()); + t.skip(); + ASSERT_TRUE(t.has_next()); + t.skip(1); + ASSERT_FALSE(t.has_next()); + ASSERT_EQ(t.count(), 2); + ASSERT_THROW(t.skip(), TokenizerException); +} + TEST(ValueTokenizer, bad_integer) { ValueTokenizer values("f10"); From a858c07e8a7ff8c11a939fbb6a9c3e9430634ca9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 4 Apr 2021 21:51:48 -0400 Subject: [PATCH 234/257] add unit tests for empty id, invalid timespecs, and merge sort --- unittest/utils/test_utils.cpp | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/unittest/utils/test_utils.cpp b/unittest/utils/test_utils.cpp index 81dda11615..0c6e38e342 100644 --- a/unittest/utils/test_utils.cpp +++ b/unittest/utils/test_utils.cpp @@ -331,6 +331,11 @@ TEST(Utils, valid_id7) ASSERT_TRUE(utils::is_id("___")); } +TEST(Utils, empty_id) +{ + ASSERT_FALSE(utils::is_id("")); +} + TEST(Utils, invalid_id1) { ASSERT_FALSE(utils::is_id("+abc")); @@ -780,6 +785,11 @@ TEST(Utils, unit_conversion) ASSERT_DOUBLE_EQ(factor, 1.0 / 23.060549); } +TEST(Utils, timespec2seconds_off) +{ + ASSERT_DOUBLE_EQ(utils::timespec2seconds("off"), -1.0); +} + TEST(Utils, timespec2seconds_ss) { ASSERT_DOUBLE_EQ(utils::timespec2seconds("45"), 45.0); @@ -795,6 +805,11 @@ TEST(Utils, timespec2seconds_hhmmss) ASSERT_DOUBLE_EQ(utils::timespec2seconds("2:10:45"), 7845.0); } +TEST(Utils, timespec2seconds_invalid) +{ + ASSERT_DOUBLE_EQ(utils::timespec2seconds("2:aa:45"), -1.0); +} + TEST(Utils, date2num) { ASSERT_EQ(utils::date2num("1Jan05"), 20050101); @@ -810,3 +825,32 @@ TEST(Utils, date2num) ASSERT_EQ(utils::date2num("30November 02"), 20021130); ASSERT_EQ(utils::date2num("31December100"), 1001231); } + +static int compare(int a, int b, void *) +{ + if (a < b) + return -1; + else if (a > b) + return 1; + else + return 0; +} + +TEST(Utils, merge_sort) +{ + int data[] = {773, 405, 490, 830, 632, 96, 428, 728, 912, 840, 878, 745, 213, 219, 249, 380, + 894, 758, 575, 690, 61, 849, 19, 577, 338, 569, 898, 873, 448, 940, 431, 780, + 472, 289, 65, 491, 641, 37, 367, 33, 407, 854, 594, 611, 845, 136, 107, 592, + 275, 865, 158, 626, 399, 703, 686, 734, 188, 559, 781, 558, 737, 281, 638, 664, + 533, 529, 62, 969, 595, 661, 837, 463, 624, 568, 615, 936, 206, 637, 91, 694, + 214, 872, 468, 66, 775, 949, 486, 576, 255, 961, 480, 138, 177, 509, 333, 705, + 10, 375, 321, 952, 210, 111, 475, 268, 708, 864, 244, 121, 988, 540, 942, 682, + 750, 473, 478, 714, 955, 911, 482, 384, 144, 757, 697, 791, 420, 605, 447, 320}; + + const int num = sizeof(data) / sizeof(int); + utils::merge_sort(data, num, nullptr, &compare); + bool sorted = true; + for (int i = 1; i < num; ++i) + if (data[i - 1] > data[i]) sorted = false; + ASSERT_TRUE(sorted); +} From e00e2676fca98a56f87775fa7820aab19a6019b3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 4 Apr 2021 22:23:13 -0400 Subject: [PATCH 235/257] add tests for utils::open_potential() --- .../formats/test_potential_file_reader.cpp | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/unittest/formats/test_potential_file_reader.cpp b/unittest/formats/test_potential_file_reader.cpp index 1e3d96d6d7..f270f6e1f1 100644 --- a/unittest/formats/test_potential_file_reader.cpp +++ b/unittest/formats/test_potential_file_reader.cpp @@ -28,6 +28,7 @@ #include "potential_file_reader.h" #include "gmock/gmock.h" #include "gtest/gtest.h" + #include "../testing/core.h" #include @@ -257,6 +258,67 @@ TEST_F(PotentialFileReaderTest, UnitConvert) delete reader; } +class OpenPotentialTest : public LAMMPSTest { +}; + +// open for native units +TEST_F(OpenPotentialTest, Sw_native) +{ + int convert_flag = utils::get_supported_conversions(utils::ENERGY); + BEGIN_CAPTURE_OUTPUT(); + command("units metal"); + FILE *fp = utils::open_potential("Si.sw", lmp, &convert_flag); + auto text = END_CAPTURE_OUTPUT(); + double conv = utils::get_conversion_factor(utils::ENERGY, convert_flag); + + ASSERT_NE(fp, nullptr); + ASSERT_DOUBLE_EQ(conv, 1.0); + fclose(fp); +} + +// open with supported conversion enabled +TEST_F(OpenPotentialTest, Sw_conv) +{ + int convert_flag = utils::get_supported_conversions(utils::ENERGY); + ASSERT_EQ(convert_flag, utils::METAL2REAL | utils::REAL2METAL); + BEGIN_HIDE_OUTPUT(); + command("units real"); + FILE *fp = utils::open_potential("Si.sw", lmp, &convert_flag); + auto text = END_CAPTURE_OUTPUT(); + double conv = utils::get_conversion_factor(utils::ENERGY, convert_flag); + + ASSERT_NE(fp, nullptr); + ASSERT_EQ(convert_flag, utils::METAL2REAL); + ASSERT_DOUBLE_EQ(conv, 23.060549); + fclose(fp); +} + +// open with conversion disabled +TEST_F(OpenPotentialTest, Sw_noconv) +{ + BEGIN_HIDE_OUTPUT(); + command("units real"); + END_HIDE_OUTPUT(); + TEST_FAILURE(".*potential.*requires metal units but real.*", + utils::open_potential("Si.sw", lmp, nullptr);); + BEGIN_HIDE_OUTPUT(); + command("units lj"); + END_HIDE_OUTPUT(); + int convert_flag = utils::get_supported_conversions(utils::UNKNOWN); + ASSERT_EQ(convert_flag, utils::NOCONVERT); +} + +// open non-existing potential +TEST_F(OpenPotentialTest, No_file) +{ + int convert_flag = utils::get_supported_conversions(utils::ENERGY); + BEGIN_HIDE_OUTPUT(); + command("units metal"); + FILE *fp = utils::open_potential("Unknown.sw", lmp, &convert_flag); + END_HIDE_OUTPUT(); + ASSERT_EQ(fp,nullptr); +} + int main(int argc, char **argv) { MPI_Init(&argc, &argv); From 4e4a571dbda05a29dff342d163f4059b0aac5117 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 14:31:13 -0400 Subject: [PATCH 236/257] Add advanced LAMMPS_DOWNLOADS_URL cmake option --- cmake/CMakeLists.txt | 5 +++++ cmake/Modules/LAMMPSUtils.cmake | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 21d965ebba..4c94a5037a 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -22,6 +22,11 @@ set(LAMMPS_TOOLS_DIR ${LAMMPS_DIR}/tools) set(LAMMPS_PYTHON_DIR ${LAMMPS_DIR}/python) set(LAMMPS_POTENTIALS_DIR ${LAMMPS_DIR}/potentials) +set(LAMMPS_DOWNLOADS_URL "https://download.lammps.org" CACHE STRING "Base URL for LAMMPS downloads") +set(LAMMPS_POTENTIALS_URL "${LAMMPS_DOWNLOADS_URL}/potentials") +set(LAMMPS_THIRDPARTY_URL "${LAMMPS_DOWNLOADS_URL}/thirdparty") +mark_as_advanced(LAMMPS_DOWNLOADS_URL) + find_package(Git) # by default, install into $HOME/.local (not /usr/local), so that no root access (and sudo!!) is needed diff --git a/cmake/Modules/LAMMPSUtils.cmake b/cmake/Modules/LAMMPSUtils.cmake index 37275843fa..acaef19498 100644 --- a/cmake/Modules/LAMMPSUtils.cmake +++ b/cmake/Modules/LAMMPSUtils.cmake @@ -86,7 +86,6 @@ endfunction(GenerateBinaryHeader) # fetch missing potential files function(FetchPotentials pkgfolder potfolder) if (EXISTS "${pkgfolder}/potentials.txt") - set(LAMMPS_POTENTIALS_URL "https://download.lammps.org/potentials") file(STRINGS "${pkgfolder}/potentials.txt" linelist REGEX "^[^#].") foreach(line ${linelist}) string(FIND ${line} " " blank) From 8533bb17e7cf3913600f139de54edaab2cf01108 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 14:36:38 -0400 Subject: [PATCH 237/257] Update cmake/Modules/OpenCLLoader.cmake --- cmake/Modules/OpenCLLoader.cmake | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmake/Modules/OpenCLLoader.cmake b/cmake/Modules/OpenCLLoader.cmake index 5ab121f841..54eaab4795 100644 --- a/cmake/Modules/OpenCLLoader.cmake +++ b/cmake/Modules/OpenCLLoader.cmake @@ -1,11 +1,13 @@ message(STATUS "Downloading and building OpenCL loader library") +set(OPENCL_LOADER_URL "${LAMMPS_THIRDPARTY_URL}/opencl-loader-2020.12.18.tar.gz" CACHE STRING "URL for OpenCL loader tarball") +set(OPENCL_LOADER_MD5 "011cdcbd41030be94f3fced6d763a52a" CACHE STRING "MD5 checksum of OpenCL loader tarball") +mark_as_advanced(OPENCL_LOADER_URL) +mark_as_advanced(OPENCL_LOADER_MD5) include(ExternalProject) -set(OPENCL_LOADER_URL "https://download.lammps.org/thirdparty/opencl-loader-2020.12.18.tar.gz" CACHE STRING "URL for OpenCL loader tarball") -mark_as_advanced(OPENCL_LOADER_URL) ExternalProject_Add(opencl_loader - URL ${OPENCL_LOADER_URL} - URL_MD5 011cdcbd41030be94f3fced6d763a52a + URL ${OPENCL_LOADER_URL} + URL_MD5 ${OPENCL_LOADER_MD5} SOURCE_DIR "${CMAKE_BINARY_DIR}/opencl_loader-src" BINARY_DIR "${CMAKE_BINARY_DIR}/opencl_loader-build" CMAKE_ARGS ${CMAKE_REQUEST_PIC} ${CMAKE_EXTRA_OPENCL_LOADER_OPTS} From 3b14606f063f8fa72470697a495a3441df2e00ca Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 14:43:05 -0400 Subject: [PATCH 238/257] Update cmake/Modules/MPI4WIN.cmake --- cmake/Modules/MPI4WIN.cmake | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cmake/Modules/MPI4WIN.cmake b/cmake/Modules/MPI4WIN.cmake index 529cefeab0..aa0c9e1833 100644 --- a/cmake/Modules/MPI4WIN.cmake +++ b/cmake/Modules/MPI4WIN.cmake @@ -1,16 +1,25 @@ # Download and configure custom MPICH files for Windows message(STATUS "Downloading and configuring MPICH-1.4.1 for Windows") +set(MPICH2_WIN64_DEVEL_URL "${LAMMPS_THIRDPARTY_URL}/mpich2-win64-devel.tar.gz" CACHE STRING "URL for MPICH2 (win64) tarball") +set(MPICH2_WIN32_DEVEL_URL "${LAMMPS_THIRDPARTY_URL}/mpich2-win32-devel.tar.gz" CACHE STRING "URL for MPICH2 (win32) tarball") +set(MPICH2_WIN64_DEVEL_MD5 "4939fdb59d13182fd5dd65211e469f14" CACHE STRING "MD5 checksum of MPICH2 (win64) tarball") +set(MPICH2_WIN32_DEVEL_MD5 "a61d153500dce44e21b755ee7257e031" CACHE STRING "MD5 checksum of MPICH2 (win32) tarball") +mark_as_advanced(MPICH2_WIN64_DEVEL_URL) +mark_as_advanced(MPICH2_WIN32_DEVEL_URL) +mark_as_advanced(MPICH2_WIN64_DEVEL_MD5) +mark_as_advanced(MPICH2_WIN32_DEVEL_MD5) + include(ExternalProject) if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") ExternalProject_Add(mpi4win_build - URL https://download.lammps.org/thirdparty/mpich2-win64-devel.tar.gz - URL_MD5 4939fdb59d13182fd5dd65211e469f14 + URL ${MPICH2_WIN64_DEVEL_URL} + URL_MD5 ${MPICH2_WIN64_DEVEL_MD5} CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" BUILD_BYPRODUCTS /lib/libmpi.a) else() ExternalProject_Add(mpi4win_build - URL https://download.lammps.org/thirdparty/mpich2-win32-devel.tar.gz - URL_MD5 a61d153500dce44e21b755ee7257e031 + URL ${MPICH2_WIN32_DEVEL_URL} + URL_MD5 ${MPICH2_WIN32_DEVEL_MD5} CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" BUILD_BYPRODUCTS /lib/libmpi.a) endif() From 614411130b2aa3312b5ab12a02db3132f31a56ec Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 14:44:27 -0400 Subject: [PATCH 239/257] Update cmake/Modules/Documentation.cmake --- cmake/Modules/Documentation.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/Documentation.cmake b/cmake/Modules/Documentation.cmake index 5a42244b9e..c0028676b7 100644 --- a/cmake/Modules/Documentation.cmake +++ b/cmake/Modules/Documentation.cmake @@ -55,11 +55,15 @@ if(BUILD_DOC) COMMAND ${DOCENV_BINARY_DIR}/pip $ENV{PIP_OPTIONS} install -r ${DOC_BUILD_DIR}/requirements.txt --upgrade ) + set(MATHJAX_URL "https://github.com/mathjax/MathJax/archive/3.1.2.tar.gz" CACHE STRING "URL for MathJax tarball") + set(MATHJAX_MD5 "a4a6a093a89bc2ccab1452d766b98e53" CACHE STRING "MD5 checksum of MathJax tarball") + mark_as_advanced(MATHJAX_URL) + # download mathjax distribution and unpack to folder "mathjax" if(NOT EXISTS ${DOC_BUILD_STATIC_DIR}/mathjax/es5) - file(DOWNLOAD "https://github.com/mathjax/MathJax/archive/3.1.2.tar.gz" + file(DOWNLOAD ${MATHJAX_URL} "${CMAKE_CURRENT_BINARY_DIR}/mathjax.tar.gz" - EXPECTED_MD5 a4a6a093a89bc2ccab1452d766b98e53) + EXPECTED_MD5 ${MATHJAX_MD5}) execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf mathjax.tar.gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) file(GLOB MATHJAX_VERSION_DIR ${CMAKE_CURRENT_BINARY_DIR}/MathJax-*) execute_process(COMMAND ${CMAKE_COMMAND} -E rename ${MATHJAX_VERSION_DIR} ${DOC_BUILD_STATIC_DIR}/mathjax) From 192ee276b16c3d67838ce58d50f9a85c41abe141 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 14:46:50 -0400 Subject: [PATCH 240/257] Update cmake/Modules/Packages/KOKKOS.cmake --- cmake/Modules/Packages/KOKKOS.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/Packages/KOKKOS.cmake b/cmake/Modules/Packages/KOKKOS.cmake index 1dfb0bf389..1f00516e08 100644 --- a/cmake/Modules/Packages/KOKKOS.cmake +++ b/cmake/Modules/Packages/KOKKOS.cmake @@ -37,9 +37,13 @@ if(DOWNLOAD_KOKKOS) list(APPEND KOKKOS_LIB_BUILD_ARGS "-DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}") list(APPEND KOKKOS_LIB_BUILD_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") include(ExternalProject) + set(KOKKOS_URL "https://github.com/kokkos/kokkos/archive/3.3.01.tar.gz" CACHE STRING "URL for KOKKOS tarball") + set(KOKKOS_MD5 "08201d1c7cf5bc458ce0f5b44a629d5a" CACHE STRING "MD5 checksum of KOKKOS tarball") + mark_as_advanced(KOKKOS_URL) + mark_as_advanced(KOKKOS_MD5) ExternalProject_Add(kokkos_build - URL https://github.com/kokkos/kokkos/archive/3.3.01.tar.gz - URL_MD5 08201d1c7cf5bc458ce0f5b44a629d5a + URL ${KOKKOS_URL} + URL_MD5 ${KOKKOS_MD5} CMAKE_ARGS ${KOKKOS_LIB_BUILD_ARGS} BUILD_BYPRODUCTS /lib/libkokkoscore.a ) From 42ca8c5ba09762c43602614feee0363a25f9273d Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 14:55:56 -0400 Subject: [PATCH 241/257] Update cmake/Modules/Packages/VORONOI.cmake --- cmake/Modules/Packages/VORONOI.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/Packages/VORONOI.cmake b/cmake/Modules/Packages/VORONOI.cmake index 1d6893a978..7feea4c52e 100644 --- a/cmake/Modules/Packages/VORONOI.cmake +++ b/cmake/Modules/Packages/VORONOI.cmake @@ -7,6 +7,11 @@ endif() option(DOWNLOAD_VORO "Download and compile the Voro++ library instead of using an already installed one" ${DOWNLOAD_VORO_DEFAULT}) if(DOWNLOAD_VORO) message(STATUS "Voro++ download requested - we will build our own") + set(VORO_URL "${LAMMPS_THIRDPARTY_URL}/voro++-0.4.6.tar.gz" CACHE STRING "URL for Voro++ tarball") + set(VORO_MD5 "2338b824c3b7b25590e18e8df5d68af9" CACHE STRING "MD5 checksum for Voro++ tarball") + mark_as_advanced(VORO_URL) + mark_as_advanced(VORO_MD5) + include(ExternalProject) if(BUILD_SHARED_LIBS) @@ -22,8 +27,8 @@ if(DOWNLOAD_VORO) endif() ExternalProject_Add(voro_build - URL https://download.lammps.org/thirdparty/voro++-0.4.6.tar.gz - URL_MD5 2338b824c3b7b25590e18e8df5d68af9 + URL ${VORO_URL} + URL_MD5 ${VORO_MD5} PATCH_COMMAND patch -b -p0 < ${LAMMPS_LIB_SOURCE_DIR}/voronoi/voro-make.patch CONFIGURE_COMMAND "" BUILD_COMMAND make ${VORO_BUILD_OPTIONS} From 725332614a95131a855cfc8bc74edd98dcb5dccd Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 14:56:47 -0400 Subject: [PATCH 242/257] Update cmake/Modules/Packages/MSCG.cmake --- cmake/Modules/Packages/MSCG.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/Packages/MSCG.cmake b/cmake/Modules/Packages/MSCG.cmake index 6cb389fb13..6ac62cb012 100644 --- a/cmake/Modules/Packages/MSCG.cmake +++ b/cmake/Modules/Packages/MSCG.cmake @@ -7,10 +7,15 @@ else() endif() option(DOWNLOAD_MSCG "Download MSCG library instead of using an already installed one)" ${DOWNLOAD_MSCG_DEFAULT}) if(DOWNLOAD_MSCG) + set(MSCG_URL "https://github.com/uchicago-voth/MSCG-release/archive/1.7.3.1.tar.gz" CACHE STRING "URL for MSCG tarball") + set(MSCG_MD5 "8c45e269ee13f60b303edd7823866a91" CACHE STRING "MD5 checksum of MSCG tarball") + mark_as_advanced(MSCG_URL) + mark_as_advanced(MSCG_MD5) + include(ExternalProject) ExternalProject_Add(mscg_build - URL https://github.com/uchicago-voth/MSCG-release/archive/1.7.3.1.tar.gz - URL_MD5 8c45e269ee13f60b303edd7823866a91 + URL ${MSCG_URL} + URL_MD5 ${MSCG_MD5} SOURCE_SUBDIR src/CMake CMAKE_ARGS ${CMAKE_REQUEST_PIC} ${EXTRA_MSCG_OPTS} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} From 0277883fb2271a31ed0d07f4b64098ee4655b436 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 15:00:06 -0400 Subject: [PATCH 243/257] Update cmake/Modules/Packages/USER-SCAFACOS.cmake --- cmake/Modules/Packages/USER-SCAFACOS.cmake | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmake/Modules/Packages/USER-SCAFACOS.cmake b/cmake/Modules/Packages/USER-SCAFACOS.cmake index dc5c400c36..fd355420c3 100644 --- a/cmake/Modules/Packages/USER-SCAFACOS.cmake +++ b/cmake/Modules/Packages/USER-SCAFACOS.cmake @@ -14,15 +14,19 @@ endif() option(DOWNLOAD_SCAFACOS "Download ScaFaCoS library instead of using an already installed one" ${DOWNLOAD_SCAFACOS_DEFAULT}) if(DOWNLOAD_SCAFACOS) message(STATUS "ScaFaCoS download requested - we will build our own") + set(SCAFACOS_URL "https://github.com/scafacos/scafacos/releases/download/v1.0.1/scafacos-1.0.1.tar.gz" CACHE STRING "URL for SCAFACOS tarball") + set(SCAFACOS_MD5 "bd46d74e3296bd8a444d731bb10c1738" CACHE STRING "MD5 checksum of SCAFACOS tarball") + mark_as_advanced(SCAFACOS_URL) + mark_as_advanced(SCAFACOS_MD5) # version 1.0.1 needs a patch to compile and linke cleanly with GCC 10 and later. - file(DOWNLOAD https://download.lammps.org/thirdparty/scafacos-1.0.1-fix.diff ${CMAKE_CURRENT_BINARY_DIR}/scafacos-1.0.1.fix.diff + file(DOWNLOAD ${LAMMPS_THIRDPARTY_URL}/scafacos-1.0.1-fix.diff ${CMAKE_CURRENT_BINARY_DIR}/scafacos-1.0.1.fix.diff EXPECTED_HASH MD5=4baa1333bb28fcce102d505e1992d032) include(ExternalProject) ExternalProject_Add(scafacos_build - URL https://github.com/scafacos/scafacos/releases/download/v1.0.1/scafacos-1.0.1.tar.gz - URL_MD5 bd46d74e3296bd8a444d731bb10c1738 + URL ${SCAFACOS_URL} + URL_MD5 ${SCAFACOS_MD5} PATCH_COMMAND patch -p1 < ${CMAKE_CURRENT_BINARY_DIR}/scafacos-1.0.1.fix.diff CONFIGURE_COMMAND /configure --prefix= --disable-doc --enable-fcs-solvers=fmm,p2nfft,direct,ewald,p3m From 8ccc19bb2a272ec593da61515a1a313e1ff6d35f Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 15:03:05 -0400 Subject: [PATCH 244/257] Update cmake/Modules/Packages/LATTE.cmake --- cmake/Modules/Packages/LATTE.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/Packages/LATTE.cmake b/cmake/Modules/Packages/LATTE.cmake index e66f83fa43..ddf31a68ed 100644 --- a/cmake/Modules/Packages/LATTE.cmake +++ b/cmake/Modules/Packages/LATTE.cmake @@ -15,10 +15,14 @@ endif() option(DOWNLOAD_LATTE "Download the LATTE library instead of using an already installed one" ${DOWNLOAD_LATTE_DEFAULT}) if(DOWNLOAD_LATTE) message(STATUS "LATTE download requested - we will build our own") + set(LATTE_URL "https://github.com/lanl/LATTE/archive/v1.2.2.tar.gz" CACHE STRING "URL for LATTE tarball") + set(LATTE_MD5 "820e73a457ced178c08c71389a385de7" CACHE STRING "MD5 checksum of LATTE tarball") + mark_as_advanced(LATTE_URL) + mark_as_advanced(LATTE_MD5) include(ExternalProject) ExternalProject_Add(latte_build - URL https://github.com/lanl/LATTE/archive/v1.2.2.tar.gz - URL_MD5 820e73a457ced178c08c71389a385de7 + URL ${LATTE_URL} + URL_MD5 ${LATTE_MD5} SOURCE_SUBDIR cmake CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= ${CMAKE_REQUEST_PIC} -DCMAKE_INSTALL_LIBDIR=lib -DBLAS_LIBRARIES=${BLAS_LIBRARIES} -DLAPACK_LIBRARIES=${LAPACK_LIBRARIES} From b718903efc36ce9d15218f425cc74a4f180170d6 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 15:10:01 -0400 Subject: [PATCH 245/257] Update cmake/Modules/Packages/USER-PLUMED.cmake --- cmake/Modules/Packages/USER-PLUMED.cmake | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/Packages/USER-PLUMED.cmake b/cmake/Modules/Packages/USER-PLUMED.cmake index 53abf5771a..8719e8179d 100644 --- a/cmake/Modules/Packages/USER-PLUMED.cmake +++ b/cmake/Modules/Packages/USER-PLUMED.cmake @@ -53,10 +53,16 @@ if(DOWNLOAD_PLUMED) elseif(PLUMED_MODE STREQUAL "RUNTIME") set(PLUMED_BUILD_BYPRODUCTS "/lib/libplumedWrapper.a") endif() + + set(PLUMED_URL "https://github.com/plumed/plumed2/releases/download/v2.7.0/plumed-src-2.7.0.tgz" CACHE STRING "URL for PLUMED tarball") + set(PLUMED_MD5 "95f29dd0c067577f11972ff90dfc7d12" CACHE STRING "MD5 checksum of PLUMED tarball") + mark_as_advanced(PLUMED_URL) + mark_as_advanced(PLUMED_MD5) + include(ExternalProject) ExternalProject_Add(plumed_build - URL https://github.com/plumed/plumed2/releases/download/v2.7.0/plumed-src-2.7.0.tgz - URL_MD5 95f29dd0c067577f11972ff90dfc7d12 + URL ${PLUMED_URL} + URL_MD5 ${PLUMED_MD5} BUILD_IN_SOURCE 1 CONFIGURE_COMMAND /configure --prefix= ${CONFIGURE_REQUEST_PIC} From 88b9e99707c95bd6ede9f47672536ded23fe66d0 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 15:26:58 -0400 Subject: [PATCH 246/257] Update cmake/Modules/Packages/GPU.cmake --- cmake/Modules/Packages/GPU.cmake | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmake/Modules/Packages/GPU.cmake b/cmake/Modules/Packages/GPU.cmake index 9aa917144b..115d81af2a 100644 --- a/cmake/Modules/Packages/GPU.cmake +++ b/cmake/Modules/Packages/GPU.cmake @@ -338,11 +338,16 @@ elseif(GPU_API STREQUAL "HIP") if(DOWNLOAD_CUB) message(STATUS "CUB download requested") + set(CUB_URL "https://github.com/NVlabs/cub/archive/1.12.0.tar.gz" CACHE STRING "URL for CUB tarball") + set(CUB_MD5 "1cf595beacafff104700921bac8519f3" CACHE STRING "MD5 checksum of CUB tarball") + mark_as_advanced(CUB_URL) + mark_as_advanced(CUB_MD5) + include(ExternalProject) ExternalProject_Add(CUB - GIT_REPOSITORY https://github.com/NVlabs/cub - TIMEOUT 5 + URL ${CUB_URL} + URL_MD5 ${CUB_MD5} PREFIX "${CMAKE_CURRENT_BINARY_DIR}" CONFIGURE_COMMAND "" BUILD_COMMAND "" @@ -354,7 +359,7 @@ elseif(GPU_API STREQUAL "HIP") else() find_package(CUB) if(NOT CUB_FOUND) - message(FATAL_ERROR "CUB library not found. Help CMake to find it by setting CUB_INCLUDE_DIR, or set DOWNLOAD_VORO=ON to download it") + message(FATAL_ERROR "CUB library not found. Help CMake to find it by setting CUB_INCLUDE_DIR, or set DOWNLOAD_CUB=ON to download it") endif() endif() From 2509190daec63d7942334ed5556ff72abc175574 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 15:29:33 -0400 Subject: [PATCH 247/257] Update cmake/Modules/YAML.cmake --- cmake/Modules/YAML.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/YAML.cmake b/cmake/Modules/YAML.cmake index f2ba34e1b6..c50773568c 100644 --- a/cmake/Modules/YAML.cmake +++ b/cmake/Modules/YAML.cmake @@ -2,10 +2,13 @@ message(STATUS "Downloading and building YAML library") include(ExternalProject) set(YAML_URL "https://pyyaml.org/download/libyaml/yaml-0.2.5.tar.gz" CACHE STRING "URL for libyaml tarball") +set(YAML_MD5 "bb15429d8fb787e7d3f1c83ae129a999" CACHE STRING "MD5 checksum of libyaml tarball") mark_as_advanced(YAML_URL) +mark_as_advanced(YAML_MD5) + ExternalProject_Add(libyaml URL ${YAML_URL} - URL_MD5 bb15429d8fb787e7d3f1c83ae129a999 + URL_MD5 ${YAML_MD5} SOURCE_DIR "${CMAKE_BINARY_DIR}/yaml-src" BINARY_DIR "${CMAKE_BINARY_DIR}/yaml-build" CONFIGURE_COMMAND /configure ${CONFIGURE_REQUEST_PIC} From d4550dbb4b218541af2754bba41db856ad227f6e Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 15:32:18 -0400 Subject: [PATCH 248/257] Update cmake/Modules/Packages/USER-SMD.cmake --- cmake/Modules/Packages/USER-SMD.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/Packages/USER-SMD.cmake b/cmake/Modules/Packages/USER-SMD.cmake index 67f4aae99d..6d941f9798 100644 --- a/cmake/Modules/Packages/USER-SMD.cmake +++ b/cmake/Modules/Packages/USER-SMD.cmake @@ -7,10 +7,14 @@ endif() option(DOWNLOAD_EIGEN3 "Download Eigen3 instead of using an already installed one)" ${DOWNLOAD_EIGEN3_DEFAULT}) if(DOWNLOAD_EIGEN3) message(STATUS "Eigen3 download requested - we will build our own") + set(EIGEN3_URL "https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz" CACHE STRING "URL for Eigen3 tarball") + set(EIGEN3_MD5 "9e30f67e8531477de4117506fe44669b" CACHE STRING "MD5 checksum of Eigen3 tarball") + mark_as_advanced(EIGEN3_URL) + mark_as_advanced(EIGEN3_MD5) include(ExternalProject) ExternalProject_Add(Eigen3_build - URL https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz - URL_MD5 9e30f67e8531477de4117506fe44669b + URL ${EIGEN3_URL} + URL_MD5 ${EIGEN3_MD5} CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" ) ExternalProject_get_property(Eigen3_build SOURCE_DIR) From cbd439692ebfb2c070ed307998471b4e15523849 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 15:36:14 -0400 Subject: [PATCH 249/257] Update cmake/Modules/Packages/KIM.cmake --- cmake/Modules/Packages/KIM.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/Packages/KIM.cmake b/cmake/Modules/Packages/KIM.cmake index 5482d3071c..2a2a1cde78 100644 --- a/cmake/Modules/Packages/KIM.cmake +++ b/cmake/Modules/Packages/KIM.cmake @@ -35,9 +35,13 @@ if(DOWNLOAD_KIM) include(ExternalProject) enable_language(C) enable_language(Fortran) + set(KIM_URL "https://s3.openkim.org/kim-api/kim-api-2.2.1.txz" CACHE STRING "URL for KIM tarball") + set(KIM_MD5 "ae1ddda2ef7017ea07934e519d023dca" CACHE STRING "MD5 checksum of KIM tarball") + mark_as_advanced(KIM_URL) + mark_as_advanced(KIM_MD5) ExternalProject_Add(kim_build - URL https://s3.openkim.org/kim-api/kim-api-2.2.1.txz - URL_MD5 ae1ddda2ef7017ea07934e519d023dca + URL ${KIM_URL} + URL_MD5 ${KIM_MD5} BINARY_DIR build CMAKE_ARGS ${CMAKE_REQUEST_PIC} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} From fc6e10921d26c5c9e0a446cec7246dad005324f6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 5 Apr 2021 15:38:59 -0400 Subject: [PATCH 250/257] add post yes/no keyword to rerun commmand (with default to no) --- doc/src/rerun.rst | 9 +++++++-- src/rerun.cpp | 12 +++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/doc/src/rerun.rst b/doc/src/rerun.rst index 7d51fba868..e9e23afba8 100644 --- a/doc/src/rerun.rst +++ b/doc/src/rerun.rst @@ -15,7 +15,7 @@ Syntax .. parsed-literal:: - keyword = *first* or *last* or *every* or *skip* or *start* or *stop* or *dump* + keyword = *first* or *last* or *every* or *skip* or *start* or *stop* or *post* or *dump* *first* args = Nfirst Nfirst = dump timestep to start on *last* args = Nlast @@ -28,6 +28,7 @@ Syntax Nstart = timestep on which pseudo run will start *stop* args = Nstop Nstop = timestep to which pseudo run will end + *post* value = *yes* or *no* *dump* args = same as :doc:`read_dump ` command starting with its field arguments Examples @@ -154,6 +155,10 @@ Also note that an error will occur if you read a snapshot from the dump file with a timestep value larger than the *stop* setting you have specified. +The *post* keyword can be used to minimize the output to the screen that +happens after a *rerun* command, similar to the post keyword of the +:doc:`run command `. It is set to *no* by default. + The *dump* keyword is required and must be the last keyword specified. Its arguments are passed internally to the :doc:`read_dump ` command. The first argument following the *dump* keyword should be @@ -226,4 +231,4 @@ Default The option defaults are first = 0, last = a huge value (effectively infinity), start = same as first, stop = same as last, every = 0, skip -= 1; += 1, post = no; diff --git a/src/rerun.cpp b/src/rerun.cpp index 648874420a..8615b02d95 100644 --- a/src/rerun.cpp +++ b/src/rerun.cpp @@ -51,6 +51,7 @@ void Rerun::command(int narg, char **arg) if (strcmp(arg[iarg],"start") == 0) break; if (strcmp(arg[iarg],"stop") == 0) break; if (strcmp(arg[iarg],"dump") == 0) break; + if (strcmp(arg[iarg],"post") == 0) break; iarg++; } int nfile = iarg; @@ -65,6 +66,7 @@ void Rerun::command(int narg, char **arg) int nskip = 1; int startflag = 0; int stopflag = 0; + int postflag = 0; bigint start = -1; bigint stop = -1; @@ -101,6 +103,14 @@ void Rerun::command(int narg, char **arg) stop = utils::bnumeric(FLERR,arg[iarg+1],false,lmp); if (stop < 0) error->all(FLERR,"Illegal rerun command"); iarg += 2; + } else if (strcmp(arg[iarg],"post") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal rerun command"); + if (strcmp(arg[iarg+1],"yes") == 0) { + postflag = 1; + } else if (strcmp(arg[iarg+1],"no") == 0) { + postflag = 0; + } else error->all(FLERR,"Illegal rerun command"); + iarg += 2; } else if (strcmp(arg[iarg],"dump") == 0) { break; } else error->all(FLERR,"Illegal rerun command"); @@ -182,7 +192,7 @@ void Rerun::command(int narg, char **arg) update->nsteps = ndump; Finish finish(lmp); - finish.end(1); + finish.end(postflag); update->whichflag = 0; update->firststep = update->laststep = 0; From 7e57d6a334b0493698827f4a78b204ec5e064de9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 5 Apr 2021 15:39:31 -0400 Subject: [PATCH 251/257] add tests for "rerun" --- unittest/formats/test_dump_atom.cpp | 50 ++++++++++++++++-- unittest/formats/test_dump_custom.cpp | 73 +++++++++++++++++++++++++-- 2 files changed, 115 insertions(+), 8 deletions(-) diff --git a/unittest/formats/test_dump_atom.cpp b/unittest/formats/test_dump_atom.cpp index 46c6b7dfa7..5161eece3e 100644 --- a/unittest/formats/test_dump_atom.cpp +++ b/unittest/formats/test_dump_atom.cpp @@ -15,6 +15,8 @@ #include "../testing/systems/melt.h" #include "../testing/utils.h" #include "fmt/format.h" +#include "output.h" +#include "thermo.h" #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -24,7 +26,7 @@ using ::testing::Eq; char *BINARY2TXT_BINARY = nullptr; -bool verbose = false; +bool verbose = false; class DumpAtomTest : public MeltTest { std::string dump_style = "atom"; @@ -46,7 +48,14 @@ public: command(fmt::format("dump_modify id {}", dump_modify_options)); } - command(fmt::format("run {}", ntimesteps)); + command(fmt::format("run {} post no", ntimesteps)); + END_HIDE_OUTPUT(); + } + + void continue_dump(int ntimesteps) + { + BEGIN_HIDE_OUTPUT(); + command(fmt::format("run {} pre no post no", ntimesteps)); END_HIDE_OUTPUT(); } @@ -62,7 +71,7 @@ public: command(fmt::format("dump_modify id1 {}", dump_modify_options)); } - command(fmt::format("run {}", ntimesteps)); + command(fmt::format("run {} post no", ntimesteps)); END_HIDE_OUTPUT(); } @@ -446,13 +455,16 @@ TEST_F(DumpAtomTest, binary_triclinic_with_image_run0) delete_file(converted_file); } -TEST_F(DumpAtomTest, run1) +TEST_F(DumpAtomTest, run1plus1) { - auto dump_file = "dump_run1.melt"; + auto dump_file = "dump_run1plus1.melt"; generate_dump(dump_file, "", 1); ASSERT_FILE_EXISTS(dump_file); ASSERT_EQ(count_lines(dump_file), 82); + continue_dump(1); + ASSERT_FILE_EXISTS(dump_file); + ASSERT_EQ(count_lines(dump_file), 123); delete_file(dump_file); } @@ -466,6 +478,34 @@ TEST_F(DumpAtomTest, run2) delete_file(dump_file); } +TEST_F(DumpAtomTest, rerun) +{ + auto dump_file = "dump_rerun.melt"; + HIDE_OUTPUT([&] { + command("fix 1 all nve"); + }); + generate_dump(dump_file, "format line \"%d %d %20.15g %20.15g %20.15g\"", 1); + double pe_1, pe_2, pe_rerun; + lmp->output->thermo->evaluate_keyword("pe", &pe_1); + ASSERT_FILE_EXISTS(dump_file); + ASSERT_EQ(count_lines(dump_file), 82); + continue_dump(1); + lmp->output->thermo->evaluate_keyword("pe", &pe_2); + ASSERT_FILE_EXISTS(dump_file); + ASSERT_EQ(count_lines(dump_file), 123); + HIDE_OUTPUT([&] { + command(fmt::format("rerun {} first 1 last 1 every 1 post no dump x y z", dump_file)); + }); + lmp->output->thermo->evaluate_keyword("pe", &pe_rerun); + ASSERT_DOUBLE_EQ(pe_1, pe_rerun); + HIDE_OUTPUT([&] { + command(fmt::format("rerun {} first 2 last 2 every 1 post yes dump x y z", dump_file)); + }); + lmp->output->thermo->evaluate_keyword("pe", &pe_rerun); + ASSERT_DOUBLE_EQ(pe_2, pe_rerun); + delete_file(dump_file); +} + TEST_F(DumpAtomTest, multi_file_run1) { auto dump_file = "dump_run1_*.melt"; diff --git a/unittest/formats/test_dump_custom.cpp b/unittest/formats/test_dump_custom.cpp index b90d77e966..f8a55bb2fb 100644 --- a/unittest/formats/test_dump_custom.cpp +++ b/unittest/formats/test_dump_custom.cpp @@ -15,6 +15,8 @@ #include "../testing/systems/melt.h" #include "../testing/utils.h" #include "fmt/format.h" +#include "output.h" +#include "thermo.h" #include "utils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -22,7 +24,7 @@ using ::testing::Eq; char *BINARY2TXT_BINARY = nullptr; -bool verbose = false; +bool verbose = false; class DumpCustomTest : public MeltTest { std::string dump_style = "custom"; @@ -45,7 +47,14 @@ public: command(fmt::format("dump_modify id {}", dump_modify_options)); } - command(fmt::format("run {}", ntimesteps)); + command(fmt::format("run {} post no", ntimesteps)); + END_HIDE_OUTPUT(); + } + + void continue_dump(int ntimesteps) + { + BEGIN_HIDE_OUTPUT(); + command(fmt::format("run {} pre no post no", ntimesteps)); END_HIDE_OUTPUT(); } @@ -62,7 +71,7 @@ public: command(fmt::format("dump_modify id1 {}", dump_modify_options)); } - command(fmt::format("run {}", ntimesteps)); + command(fmt::format("run {} post no", ntimesteps)); END_HIDE_OUTPUT(); } @@ -262,6 +271,64 @@ TEST_F(DumpCustomTest, with_variable_run1) delete_file(dump_file); } +TEST_F(DumpCustomTest, run1plus1) +{ + auto dump_file = "dump_custom_run1plus1.melt"; + auto fields = "id type x y z"; + + generate_dump(dump_file, fields, "units yes", 1); + + ASSERT_FILE_EXISTS(dump_file); + auto lines = read_lines(dump_file); + ASSERT_EQ(lines.size(), 84); + continue_dump(1); + ASSERT_FILE_EXISTS(dump_file); + lines = read_lines(dump_file); + ASSERT_EQ(lines.size(), 125); + delete_file(dump_file); +} + +TEST_F(DumpCustomTest, run2) +{ + auto dump_file = "dump_custom_run2.melt"; + auto fields = "id type x y z"; + generate_dump(dump_file, fields, "", 2); + + ASSERT_FILE_EXISTS(dump_file); + ASSERT_EQ(count_lines(dump_file), 123); + delete_file(dump_file); +} + +TEST_F(DumpCustomTest, rerun) +{ + auto dump_file = "dump_rerun.melt"; + auto fields = "id type xs ys zs"; + + HIDE_OUTPUT([&] { + command("fix 1 all nve"); + }); + generate_dump(dump_file, fields, "format float %20.15g", 1); + double pe_1, pe_2, pe_rerun; + lmp->output->thermo->evaluate_keyword("pe", &pe_1); + ASSERT_FILE_EXISTS(dump_file); + ASSERT_EQ(count_lines(dump_file), 82); + continue_dump(1); + lmp->output->thermo->evaluate_keyword("pe", &pe_2); + ASSERT_FILE_EXISTS(dump_file); + ASSERT_EQ(count_lines(dump_file), 123); + HIDE_OUTPUT([&] { + command(fmt::format("rerun {} first 1 last 1 every 1 post no dump x y z", dump_file)); + }); + lmp->output->thermo->evaluate_keyword("pe", &pe_rerun); + ASSERT_DOUBLE_EQ(pe_1, pe_rerun); + HIDE_OUTPUT([&] { + command(fmt::format("rerun {} first 2 last 2 every 1 post yes dump x y z", dump_file)); + }); + lmp->output->thermo->evaluate_keyword("pe", &pe_rerun); + ASSERT_DOUBLE_EQ(pe_2, pe_rerun); + delete_file(dump_file); +} + int main(int argc, char **argv) { MPI_Init(&argc, &argv); From 94068cc4c7b8465dc3beb91dde1eecfc0cbeb33e Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 5 Apr 2021 16:17:41 -0400 Subject: [PATCH 252/257] Add missing GTEST_MD5 --- cmake/Modules/GTest.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/GTest.cmake b/cmake/Modules/GTest.cmake index 0c62291d5e..677ed5f4af 100644 --- a/cmake/Modules/GTest.cmake +++ b/cmake/Modules/GTest.cmake @@ -8,10 +8,12 @@ endif() include(ExternalProject) set(GTEST_URL "https://github.com/google/googletest/archive/release-1.10.0.tar.gz" CACHE STRING "URL for GTest tarball") +set(GTEST_MD5 "ecd1fa65e7de707cd5c00bdac56022cd" CACHE STRING "MD5 checksum of GTest tarball") mark_as_advanced(GTEST_URL) +mark_as_advanced(GTEST_MD5) ExternalProject_Add(googletest - URL ${GTEST_URL} - URL_MD5 ecd1fa65e7de707cd5c00bdac56022cd + URL ${GTEST_URL} + URL_MD5 ${GTEST_MD5} SOURCE_DIR "${CMAKE_BINARY_DIR}/gtest-src" BINARY_DIR "${CMAKE_BINARY_DIR}/gtest-build" CMAKE_ARGS ${CMAKE_REQUEST_PIC} ${CMAKE_EXTRA_GTEST_OPTS} From 11d62b71c382ef202cee84602e35984b3e0b98a7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 6 Apr 2021 11:11:01 -0400 Subject: [PATCH 253/257] use clang preset when compiling on MacOS --- .github/workflows/unittest-macos.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unittest-macos.yml b/.github/workflows/unittest-macos.yml index a65db7636b..f62b3046c9 100644 --- a/.github/workflows/unittest-macos.yml +++ b/.github/workflows/unittest-macos.yml @@ -24,7 +24,9 @@ jobs: shell: bash working-directory: ${{github.workspace}}/build run: | - cmake -C $GITHUB_WORKSPACE/cmake/presets/most.cmake $GITHUB_WORKSPACE/cmake \ + cmake -C $GITHUB_WORKSPACE/cmake/presets/clang.cmake \ + -C $GITHUB_WORKSPACE/cmake/presets/most.cmake \ + $GITHUB_WORKSPACE/cmake \ -DENABLE_TESTING=ON -DBUILD_SHARED_LIBS=ON -DLAMMPS_EXCEPTIONS=ON cmake --build . --parallel 2 From d346c539147ae666741494657646a8d885741312 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 6 Apr 2021 11:28:19 -0400 Subject: [PATCH 254/257] silence compiler warnings about formats --- src/USER-REAXC/reaxc_tool_box.cpp | 45 +++++++++++++++---------------- src/USER-REAXC/reaxc_traj.h | 16 ++++++----- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/USER-REAXC/reaxc_tool_box.cpp b/src/USER-REAXC/reaxc_tool_box.cpp index f0171d2108..abab3f2b43 100644 --- a/src/USER-REAXC/reaxc_tool_box.cpp +++ b/src/USER-REAXC/reaxc_tool_box.cpp @@ -25,10 +25,11 @@ ----------------------------------------------------------------------*/ #include "reaxc_tool_box.h" +#include "reaxc_defs.h" + #include #include #include -#include "reaxc_defs.h" #include "error.h" @@ -49,62 +50,58 @@ int Tokenize( char* s, char*** tok ) return count; } - - /* safe malloc */ void *smalloc( LAMMPS_NS::Error *error_ptr, rc_bigint n, const char *name ) { void *ptr; - char errmsg[256]; if (n <= 0) { - snprintf(errmsg, 256, "Trying to allocate %ld bytes for array %s. " - "returning NULL.", n, name); + auto errmsg = fmt::format("Trying to allocate {} bytes for array {}. " + "returning NULL.", n, name); if (error_ptr) error_ptr->one(FLERR,errmsg); - else fputs(errmsg,stderr); + else fputs(errmsg.c_str(),stderr); return nullptr; } ptr = malloc( n ); if (ptr == nullptr) { - snprintf(errmsg, 256, "Failed to allocate %ld bytes for array %s", n, name); + auto errmsg = fmt::format("Failed to allocate {} bytes for array {}", + n, name); if (error_ptr) error_ptr->one(FLERR,errmsg); - else fputs(errmsg,stderr); + else fputs(errmsg.c_str(),stderr); } return ptr; } - /* safe calloc */ void *scalloc( LAMMPS_NS::Error *error_ptr, rc_bigint n, rc_bigint size, const char *name ) { void *ptr; - char errmsg[256]; if (n <= 0) { - snprintf(errmsg, 256, "Trying to allocate %ld elements for array %s. " - "returning NULL.\n", n, name ); + auto errmsg = fmt::format("Trying to allocate {} elements for array {}. " + "returning NULL.\n", n, name); if (error_ptr) error_ptr->one(FLERR,errmsg); - else fputs(errmsg,stderr); + else fputs(errmsg.c_str(),stderr); return nullptr; } if (size <= 0) { - snprintf(errmsg, 256, "Elements size for array %s is %ld. " - "returning NULL", name, size ); + auto errmsg = fmt::format("Elements size for array {} is {}. " + "returning NULL", name, size); if (error_ptr) error_ptr->one(FLERR,errmsg); - else fputs(errmsg,stderr); + else fputs(errmsg.c_str(),stderr); return nullptr; } ptr = calloc( n, size ); if (ptr == nullptr) { - char errmsg[256]; - snprintf(errmsg, 256, "Failed to allocate %ld bytes for array %s", n*size, name); + auto errmsg = fmt::format("Failed to allocate {} bytes for array {}", + n*size, name); if (error_ptr) error_ptr->one(FLERR,errmsg); - else fputs(errmsg,stderr); + else fputs(errmsg.c_str(),stderr); } return ptr; @@ -115,14 +112,14 @@ void *scalloc( LAMMPS_NS::Error *error_ptr, rc_bigint n, rc_bigint size, const c void sfree( LAMMPS_NS::Error* error_ptr, void *ptr, const char *name ) { if (ptr == nullptr) { - char errmsg[256]; - snprintf(errmsg, 256, "Trying to free the already NULL pointer %s", name ); + auto errmsg = fmt::format("Trying to free the already free()'d pointer {}", + name); if (error_ptr) error_ptr->one(FLERR,errmsg); - else fputs(errmsg,stderr); + else fputs(errmsg.c_str(),stderr); return; } - free( ptr ); + free(ptr); ptr = nullptr; } diff --git a/src/USER-REAXC/reaxc_traj.h b/src/USER-REAXC/reaxc_traj.h index 4966bf11d8..2ff5995204 100644 --- a/src/USER-REAXC/reaxc_traj.h +++ b/src/USER-REAXC/reaxc_traj.h @@ -36,14 +36,18 @@ #define HEADER_LINE_LEN 62 #define STR_LINE "%-37s%-24s\n" #define INT_LINE "%-37s%-24d\n" -#define BIGINT_LINE "%-37s%-24ld\n" +#if defined(LAMMPS_SMALLSMALL) +#define BIGINT_LINE "%-37s%-24d\n" +#else +#define BIGINT_LINE "%-37s%-24lld\n" +#endif #define INT2_LINE "%-36s%-12d,%-12d\n" #define REAL_LINE "%-37s%-24.3f\n" #define SCI_LINE "%-37s%-24g\n" #define REAL3_LINE "%-32s%9.3f,%9.3f,%9.3f\n" #if defined(LAMMPS_BIGBIG) -#define INIT_DESC "%9ld%3d%9s%10.3f\n" //AtomID - AtomType, AtomName, AtomMass +#define INIT_DESC "%9lld%3d%9s%10.3f\n" //AtomID - AtomType, AtomName, AtomMass #else #define INIT_DESC "%9d%3d%9s%10.3f\n" //AtomID - AtomType, AtomName, AtomMass #endif @@ -56,7 +60,7 @@ #define SIZE_INFO_LEN3 31 #if defined(LAMMPS_BIGBIG) -#define ATOM_BASIC "%9ld%10.3f%10.3f%10.3f%10.3f\n" //AtomID AtomType (X Y Z) Charge +#define ATOM_BASIC "%9lld%10.3f%10.3f%10.3f%10.3f\n" //AtomID AtomType (X Y Z) Charge #define ATOM_wV "%9ld%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n" //AtomID (X Y Z) (Vx Vy Vz) Charge #define ATOM_wF "%9ld%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n" //AtomID (X Y Z) (Fx Fy Fz) Charge #define ATOM_FULL "%9ld%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f%10.3f\n" //AtomID (X Y Z) (Vx Vy Vz) (Fx Fy Fz) Charge @@ -72,9 +76,9 @@ #define ATOM_FULL_LEN 110 #if defined(LAMMPS_BIGBIG) -#define BOND_BASIC "%9ld%9ld%10.3f%10.3f\n" // Atom1 Atom2 Dist Total_BO -#define BOND_FULL "%9ld%9ld%10.3f%10.3f%10.3f%10.3f%10.3f\n" // Atom1 Atom2 Dist Total_BO BOs BOpi BOpi2 -#define ANGLE_BASIC "%9ld%9ld%9ld%10.3f\n" // Atom1 Atom2 Atom3 Theta +#define BOND_BASIC "%9lld%9lld%10.3f%10.3f\n" // Atom1 Atom2 Dist Total_BO +#define BOND_FULL "%9lld%9lld%10.3f%10.3f%10.3f%10.3f%10.3f\n" // Atom1 Atom2 Dist Total_BO BOs BOpi BOpi2 +#define ANGLE_BASIC "%9lld%9lld%9lld%10.3f\n" // Atom1 Atom2 Atom3 Theta #else #define BOND_BASIC "%9d%9d%10.3f%10.3f\n" // Atom1 Atom2 Dist Total_BO #define BOND_FULL "%9d%9d%10.3f%10.3f%10.3f%10.3f%10.3f\n" // Atom1 Atom2 Dist Total_BO BOs BOpi BOpi2 From db400c91aec560f8b04a83c8de4141724d1df89e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 6 Apr 2021 11:37:59 -0400 Subject: [PATCH 255/257] relax error a little bit to avoid failure on macos --- unittest/force-styles/tests/fix-timestep-adapt_coul.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/fix-timestep-adapt_coul.yaml b/unittest/force-styles/tests/fix-timestep-adapt_coul.yaml index 4bf25f3b33..cd7f9aa87d 100644 --- a/unittest/force-styles/tests/fix-timestep-adapt_coul.yaml +++ b/unittest/force-styles/tests/fix-timestep-adapt_coul.yaml @@ -1,7 +1,7 @@ --- lammps_version: 10 Mar 2021 date_generated: Thu Mar 25 14:07:45 202 -epsilon: 1e-14 +epsilon: 7.5e-14 prerequisites: ! | atom full fix adapt From e01e0298cb9587cac513face286643ff1e7d6b07 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 6 Apr 2021 13:25:24 -0400 Subject: [PATCH 256/257] fix uninitialized data access after restart bug in USER-YAFF pair styles also fix some source formatting issues --- src/KSPACE/pair_lj_cut_coul_long.cpp | 16 +++++++------- .../pair_lj_switch3_coulgauss_long.cpp | 22 ++++++++++--------- .../pair_mm3_switch3_coulgauss_long.cpp | 20 +++++++++-------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/KSPACE/pair_lj_cut_coul_long.cpp b/src/KSPACE/pair_lj_cut_coul_long.cpp index fcb39b8c6e..5d04fd1cfb 100644 --- a/src/KSPACE/pair_lj_cut_coul_long.cpp +++ b/src/KSPACE/pair_lj_cut_coul_long.cpp @@ -17,21 +17,21 @@ #include "pair_lj_cut_coul_long.h" -#include -#include #include "atom.h" #include "comm.h" +#include "error.h" #include "force.h" #include "kspace.h" -#include "update.h" -#include "respa.h" -#include "neighbor.h" -#include "neigh_list.h" -#include "neigh_request.h" #include "math_const.h" #include "memory.h" -#include "error.h" +#include "neigh_list.h" +#include "neigh_request.h" +#include "neighbor.h" +#include "respa.h" +#include "update.h" +#include +#include using namespace LAMMPS_NS; using namespace MathConst; diff --git a/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp b/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp index 6e4c0587f7..2247a9467c 100644 --- a/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp +++ b/src/USER-YAFF/pair_lj_switch3_coulgauss_long.cpp @@ -106,6 +106,7 @@ void PairLJSwitch3CoulGaussLong::compute(int eflag, int vflag) firstneigh = list->firstneigh; // loop over neighbors of my atoms + for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; @@ -193,7 +194,7 @@ void PairLJSwitch3CoulGaussLong::compute(int eflag, int vflag) offset[itype][jtype]; } else evdwl = 0.0; - // Truncation, see Yaff Switch33 + // Truncation, see Yaff Switch3 if (truncw>0) { if (rsq < cut_ljsq[itype][jtype]) { if (r>cut_lj[itype][jtype]-truncw) { @@ -262,19 +263,18 @@ void PairLJSwitch3CoulGaussLong::allocate() void PairLJSwitch3CoulGaussLong::settings(int narg, char **arg) { - if (narg < 2 || narg > 3) error->all(FLERR,"Illegal pair_style command"); + if (narg < 2 || narg > 3) error->all(FLERR,"Illegal pair_style command"); cut_lj_global = utils::numeric(FLERR,arg[0],false,lmp); + if (narg == 2) { cut_coul = cut_lj_global; truncw = utils::numeric(FLERR,arg[1],false,lmp); - } - else { + } else { cut_coul = utils::numeric(FLERR,arg[1],false,lmp); truncw = utils::numeric(FLERR,arg[2],false,lmp); } - if (truncw>0.0) truncwi = 1.0/truncw; - else truncwi = 0.0; + // reset cutoffs that have been explicitly set if (allocated) { @@ -332,6 +332,9 @@ void PairLJSwitch3CoulGaussLong::init_style() cut_coulsq = cut_coul * cut_coul; + if (truncw>0.0) truncwi = 1.0/truncw; + else truncwi = 0.0; + // insure use of KSpace long-range solver, set g_ewald if (force->kspace == nullptr) @@ -375,8 +378,7 @@ double PairLJSwitch3CoulGaussLong::init_one(int i, int j) double r6inv = r2inv*r2inv*r2inv; double r12inv = r6inv*r6inv; offset[i][j] = lj3[i][j]*r12inv-lj4[i][j]*r6inv; - } - else {offset[i][j] = 0.0;} + } else {offset[i][j] = 0.0;} } else offset[i][j] = 0.0; cut_ljsq[j][i] = cut_ljsq[i][j]; @@ -431,8 +433,7 @@ double PairLJSwitch3CoulGaussLong::init_one(int i, int j) double t71 = -0.4e1 * cg * (0.2e1 * t10 * t11 - 0.2e1 * t10 * t14 + (cg5 - 0.2e1 * cg1) * t58 * cg5) * t26 / t4 / t41 / t9; etail_ij = 2.0*MY_PI*all[0]*all[1]*t71; ptail_ij = 2.0*MY_PI*all[0]*all[1]*t71; - } - else { + } else { double t1 = pow(cg3, 0.2e1); double t2 = t1 * t1; double t3 = t2 * t1; @@ -618,6 +619,7 @@ double PairLJSwitch3CoulGaussLong::single(int i, int j, int itype, int jtype, expn2 = 0.0; erfc2 = 0.0; forcecoul2 = 0.0; + prefactor2 = 0.0; } else { r = sqrt(rsq); rrij = lj2[itype][jtype]*r; diff --git a/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp b/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp index 67a322ca24..c7fcac855a 100644 --- a/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp +++ b/src/USER-YAFF/pair_mm3_switch3_coulgauss_long.cpp @@ -106,6 +106,7 @@ void PairMM3Switch3CoulGaussLong::compute(int eflag, int vflag) firstneigh = list->firstneigh; // loop over neighbors of my atoms + for (ii = 0; ii < inum; ii++) { i = ilist[ii]; qtmp = q[i]; @@ -170,6 +171,7 @@ void PairMM3Switch3CoulGaussLong::compute(int eflag, int vflag) expn2 = 0.0; erfc2 = 0.0; forcecoul2 = 0.0; + prefactor2 = 0.0; } else { rrij = lj2[itype][jtype]*r; expn2 = exp(-rrij*rrij); @@ -263,19 +265,18 @@ void PairMM3Switch3CoulGaussLong::allocate() void PairMM3Switch3CoulGaussLong::settings(int narg, char **arg) { - if (narg < 2 || narg > 3) error->all(FLERR,"Illegal pair_style command"); + if (narg < 2 || narg > 3) error->all(FLERR,"Illegal pair_style command"); cut_lj_global = utils::numeric(FLERR,arg[0],false,lmp); + if (narg == 2) { cut_coul = cut_lj_global; truncw = utils::numeric(FLERR,arg[1],false,lmp); - } - else { + } else { cut_coul = utils::numeric(FLERR,arg[1],false,lmp); truncw = utils::numeric(FLERR,arg[2],false,lmp); } - if (truncw>0.0) truncwi = 1.0/truncw; - else truncwi = 0.0; + // reset cutoffs that have been explicitly set if (allocated) { @@ -333,6 +334,9 @@ void PairMM3Switch3CoulGaussLong::init_style() cut_coulsq = cut_coul * cut_coul; + if (truncw>0.0) truncwi = 1.0/truncw; + else truncwi = 0.0; + // insure use of KSpace long-range solver, set g_ewald if (force->kspace == nullptr) @@ -375,8 +379,7 @@ double PairMM3Switch3CoulGaussLong::init_one(int i, int j) double r6inv = r2inv*r2inv*r2inv; double expb = lj3[i][j]*exp(-lj1[i][j]*r); offset[i][j] = expb-lj4[i][j]*r6inv; - } - else {offset[i][j] = 0.0;} + } else {offset[i][j] = 0.0;} } else offset[i][j] = 0.0; cut_ljsq[j][i] = cut_ljsq[i][j]; @@ -426,8 +429,7 @@ double PairMM3Switch3CoulGaussLong::init_one(int i, int j) double t64 = cg * (0.6388888889e3 * ((-t3 + (0.7e1 / 0.36e2 * cg5 - t5) * t1 - 0.2e1 / 0.3e1 * t8 * (cg5 - cg1 / 0.4e1) * cg3 + cg5 * t14) * t20 + t3 + (cg5 / 0.12e2 + t5) * t1 + (cg5 + cg1 / 0.3e1) * cg1 * cg3 / 0.2e1 + t30 * cg5) * t2 * t36 * t39 - 0.225e1 * (0.2e1 * t43 * t44 - 0.2e1 * t43 * t47 + cg5 * (cg5 - 0.2e1 * cg1)) * t54 * t1 / cg1 / t8 * t39); etail_ij = 2.0*MY_PI*all[0]*all[1]*t64; ptail_ij = 2.0*MY_PI*all[0]*all[1]*t64; - } - else { + } else { double t2 = pow(cg3, 0.2e1); double t3 = t2 * t2; double t7 = 0.12e2 / cg3 * cg1; From 698b9b9519000b8976084714a977a6ce25a880d3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 6 Apr 2021 13:36:27 -0400 Subject: [PATCH 257/257] relax epsilon some more --- unittest/force-styles/tests/fix-timestep-adapt_coul.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/force-styles/tests/fix-timestep-adapt_coul.yaml b/unittest/force-styles/tests/fix-timestep-adapt_coul.yaml index cd7f9aa87d..f0ec2f1292 100644 --- a/unittest/force-styles/tests/fix-timestep-adapt_coul.yaml +++ b/unittest/force-styles/tests/fix-timestep-adapt_coul.yaml @@ -1,7 +1,7 @@ --- lammps_version: 10 Mar 2021 date_generated: Thu Mar 25 14:07:45 202 -epsilon: 7.5e-14 +epsilon: 5e-13 prerequisites: ! | atom full fix adapt