Merge branch 'master' of https://github.com/lammps/lammps into lammps-master

This commit is contained in:
Jacob Gissinger
2021-04-27 14:46:33 -04:00
4905 changed files with 257534 additions and 191333 deletions

View File

@ -35,12 +35,17 @@
#include "library.h"
#include <algorithm>
#include <cmath>
#include <cstring>
#ifdef LMP_USER_INTEL
#include "neigh_request.h"
#endif
#ifdef LMP_GPU
#include "fix_gpu.h"
#endif
using namespace LAMMPS_NS;
using namespace MathConst;
@ -348,11 +353,8 @@ void Atom::settings(Atom *old)
map_style = old->map_style;
sortfreq = old->sortfreq;
userbinsize = old->userbinsize;
if (old->firstgroupname) {
int n = strlen(old->firstgroupname) + 1;
firstgroupname = new char[n];
strcpy(firstgroupname,old->firstgroupname);
}
if (old->firstgroupname)
firstgroupname = utils::strdup(old->firstgroupname);
}
/* ----------------------------------------------------------------------
@ -539,9 +541,7 @@ void Atom::add_peratom(const char *name, void *address,
memory->srealloc(peratom,maxperatom*sizeof(PerAtom),"atom:peratom");
}
int n = strlen(name) + 1;
peratom[nperatom].name = new char[n];
strcpy(peratom[nperatom].name,name);
peratom[nperatom].name = utils::strdup(name);
peratom[nperatom].address = address;
peratom[nperatom].datatype = datatype;
peratom[nperatom].cols = cols;
@ -589,9 +589,7 @@ void Atom::add_peratom_vary(const char *name, void *address,
memory->srealloc(peratom,maxperatom*sizeof(PerAtom),"atom:peratom");
}
int n = strlen(name) + 1;
peratom[nperatom].name = new char[n];
strcpy(peratom[nperatom].name,name);
peratom[nperatom].name = utils::strdup(name);
peratom[nperatom].address = address;
peratom[nperatom].datatype = datatype;
peratom[nperatom].cols = -1;
@ -678,7 +676,7 @@ void Atom::create_avec(const std::string &style, int narg, char **arg, int trysu
// map style will be reset to array vs hash to by map_init()
molecular = avec->molecular;
if (molecular && tag_enable == 0)
if ((molecular != Atom::ATOMIC) && (tag_enable == 0))
error->all(FLERR,"Atom IDs must be used for molecular systems");
if (molecular != Atom::ATOMIC) map_style = MAP_YES;
}
@ -823,9 +821,7 @@ void Atom::modify_params(int narg, char **arg)
delete [] firstgroupname;
firstgroupname = nullptr;
} else {
int n = strlen(arg[iarg+1]) + 1;
firstgroupname = new char[n];
strcpy(firstgroupname,arg[iarg+1]);
firstgroupname = utils::strdup(arg[iarg+1]);
sortfreq = 0;
}
iarg += 2;
@ -1123,13 +1119,13 @@ void Atom::data_atoms(int n, char *buf, tagint id_offset, tagint mol_offset,
for (int i = 0; i < n; i++) {
next = strchr(buf,'\n');
values[0] = strtok(buf," \t\n\r\f");
if (values[0] == nullptr)
error->all(FLERR,"Incorrect atom format in data file");
for (m = 1; m < nwords; m++) {
values[m] = strtok(nullptr," \t\n\r\f");
if (values[m] == nullptr)
for (m = 0; m < nwords; m++) {
buf += strspn(buf," \t\n\r\f");
buf[strcspn(buf," \t\n\r\f")] = '\0';
if (strlen(buf) == 0)
error->all(FLERR,"Incorrect atom format in data file");
values[m] = buf;
buf += strlen(buf)+1;
}
int imx = 0, imy = 0, imz = 0;
@ -1227,9 +1223,12 @@ void Atom::data_vels(int n, char *buf, tagint id_offset)
for (int i = 0; i < n; i++) {
next = strchr(buf,'\n');
values[0] = strtok(buf," \t\n\r\f");
for (j = 1; j < nwords; j++)
values[j] = strtok(nullptr," \t\n\r\f");
for (j = 0; j < nwords; j++) {
buf += strspn(buf," \t\n\r\f");
buf[strcspn(buf," \t\n\r\f")] = '\0';
values[j] = buf;
buf += strlen(buf)+1;
}
tagdata = ATOTAGINT(values[0]) + id_offset;
if (tagdata <= 0 || tagdata > map_tag_max)
@ -1583,9 +1582,12 @@ void Atom::data_bonus(int n, char *buf, AtomVec *avec_bonus, tagint id_offset)
for (int i = 0; i < n; i++) {
next = strchr(buf,'\n');
values[0] = strtok(buf," \t\n\r\f");
for (j = 1; j < nwords; j++)
values[j] = strtok(nullptr," \t\n\r\f");
for (j = 0; j < nwords; j++) {
buf += strspn(buf," \t\n\r\f");
buf[strcspn(buf," \t\n\r\f")] = '\0';
values[j] = buf;
buf += strlen(buf)+1;
}
tagdata = ATOTAGINT(values[0]) + id_offset;
if (tagdata <= 0 || tagdata > map_tag_max)
@ -1625,8 +1627,10 @@ void Atom::data_bodies(int n, char *buf, AtomVec *avec_body, tagint id_offset)
// else skip values
for (int i = 0; i < n; i++) {
if (i == 0) tagdata = ATOTAGINT(strtok(buf," \t\n\r\f")) + id_offset;
else tagdata = ATOTAGINT(strtok(nullptr," \t\n\r\f")) + id_offset;
buf += strspn(buf," \t\n\r\f");
buf[strcspn(buf," \t\n\r\f")] = '\0';
tagdata = utils::tnumeric(FLERR,buf,false,lmp) + id_offset;
buf += strlen(buf)+1;
if (tagdata <= 0 || tagdata > map_tag_max)
error->one(FLERR,"Invalid atom ID in Bodies section of data file");
@ -1636,8 +1640,15 @@ void Atom::data_bodies(int n, char *buf, AtomVec *avec_body, tagint id_offset)
else
error->one(FLERR,"Duplicate atom ID in Bodies section of data file");
ninteger = utils::inumeric(FLERR,strtok(nullptr," \t\n\r\f"),false,lmp);
ndouble = utils::inumeric(FLERR,strtok(nullptr," \t\n\r\f"),false,lmp);
buf += strspn(buf," \t\n\r\f");
buf[strcspn(buf," \t\n\r\f")] = '\0';
ninteger = utils::inumeric(FLERR,buf,false,lmp);
buf += strlen(buf)+1;
buf += strspn(buf," \t\n\r\f");
buf[strcspn(buf," \t\n\r\f")] = '\0';
ndouble = utils::inumeric(FLERR,buf,false,lmp);
buf += strlen(buf)+1;
if ((m = map(tagdata)) >= 0) {
if (ninteger > maxint) {
@ -1651,17 +1662,29 @@ void Atom::data_bodies(int n, char *buf, AtomVec *avec_body, tagint id_offset)
dvalues = new double[maxdouble];
}
for (j = 0; j < ninteger; j++)
ivalues[j] = utils::inumeric(FLERR,strtok(nullptr," \t\n\r\f"),false,lmp);
for (j = 0; j < ndouble; j++)
dvalues[j] = utils::numeric(FLERR,strtok(nullptr," \t\n\r\f"),false,lmp);
for (j = 0; j < ninteger; j++) {
buf += strspn(buf," \t\n\r\f");
buf[strcspn(buf," \t\n\r\f")] = '\0';
ivalues[j] = utils::inumeric(FLERR,buf,false,lmp);
buf += strlen(buf)+1;
}
for (j = 0; j < ndouble; j++) {
buf += strspn(buf," \t\n\r\f");
buf[strcspn(buf," \t\n\r\f")] = '\0';
dvalues[j] = utils::numeric(FLERR,buf,false,lmp);
buf += strlen(buf)+1;
}
avec_body->data_body(m,ninteger,ndouble,ivalues,dvalues);
} else {
nvalues = ninteger + ndouble; // number of values to skip
for (j = 0; j < nvalues; j++)
strtok(nullptr," \t\n\r\f");
for (j = 0; j < nvalues; j++) {
buf += strspn(buf," \t\n\r\f");
buf[strcspn(buf," \t\n\r\f")] = '\0';
buf += strlen(buf)+1;
}
}
}
@ -1768,7 +1791,7 @@ void Atom::set_mass(const char *file, int line, int /*narg*/, char **arg)
if (lo < 1 || hi > ntypes) error->all(file,line,"Invalid type for mass set");
for (int itype = lo; itype <= hi; itype++) {
mass[itype] = atof(arg[1]);
mass[itype] = utils::numeric(FLERR,arg[1],false,lmp);
mass_setflag[itype] = 1;
if (mass[itype] <= 0.0) error->all(file,line,"Invalid mass value");
@ -1904,7 +1927,7 @@ void Atom::add_molecule(int narg, char **arg)
int Atom::find_molecule(char *id)
{
if(id == nullptr) return -1;
if (id == nullptr) return -1;
int imol;
for (imol = 0; imol < nmolecule; imol++)
if (strcmp(id,molecules[imol]->id) == 0) return imol;
@ -2225,7 +2248,7 @@ void Atom::setup_sort_bins()
bininvy = nbiny / (bboxhi[1]-bboxlo[1]);
bininvz = nbinz / (bboxhi[2]-bboxlo[2]);
#ifdef LMP_USER_INTEL
#ifdef LMP_USER_INTEL
int intel_neigh = 0;
if (neighbor->nrequest) {
if (neighbor->requests[0]->intel) intel_neigh = 1;
@ -2270,7 +2293,36 @@ void Atom::setup_sort_bins()
bboxhi[1] = bboxlo[1] + static_cast<double>(nbiny) / bininvy;
bboxhi[2] = bboxlo[2] + static_cast<double>(nbinz) / bininvz;
}
#endif
#endif
#ifdef LMP_GPU
if (userbinsize == 0.0) {
int ifix = modify->find_fix("package_gpu");
if (ifix >= 0) {
const double subx = domain->subhi[0] - domain->sublo[0];
const double suby = domain->subhi[1] - domain->sublo[1];
const double subz = domain->subhi[2] - domain->sublo[2];
FixGPU *fix = static_cast<FixGPU *>(modify->fix[ifix]);
binsize = fix->binsize(subx, suby, subz, atom->nlocal,
neighbor->cutneighmax);
bininv = 1.0 / binsize;
nbinx = static_cast<int> (ceil(subx * bininv));
nbiny = static_cast<int> (ceil(suby * bininv));
nbinz = static_cast<int> (ceil(subz * bininv));
if (domain->dimension == 2) nbinz = 1;
if (nbinx == 0) nbinx = 1;
if (nbiny == 0) nbiny = 1;
if (nbinz == 0) nbinz = 1;
bininvx = bininv;
bininvy = bininv;
bininvz = bininv;
}
}
#endif
if (1.0*nbinx*nbiny*nbinz > INT_MAX)
error->one(FLERR,"Too many atom sorting bins");
@ -2406,7 +2458,7 @@ void Atom::update_callback(int ifix)
int Atom::find_custom(const char *name, int &flag)
{
if(name == nullptr) return -1;
if (name == nullptr) return -1;
for (int i = 0; i < nivector; i++)
if (iname[i] && strcmp(iname[i],name) == 0) {
@ -2443,9 +2495,7 @@ int Atom::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");
@ -2454,9 +2504,7 @@ int Atom::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);
dvector = (double **) memory->srealloc(dvector,ndvector*sizeof(double *),
"atom:dvector");
memory->create(dvector[index],nmax,"atom:dvector");
@ -2776,12 +2824,12 @@ double Atom::memory_usage()
{
double bytes = avec->memory_usage();
bytes += max_same*sizeof(int);
bytes += (double)max_same*sizeof(int);
if (map_style == MAP_ARRAY)
bytes += memory->usage(map_array,map_maxarray);
else if (map_style == MAP_HASH) {
bytes += map_nbucket*sizeof(int);
bytes += map_nhash*sizeof(HashElem);
bytes += (double)map_nbucket*sizeof(int);
bytes += (double)map_nhash*sizeof(HashElem);
}
if (maxnext) {
bytes += memory->usage(next,maxnext);