avoid replicated code, consolidate variables and element mapping
This commit is contained in:
@ -23,18 +23,18 @@
|
||||
|
||||
#include "pair_edip.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cfloat>
|
||||
|
||||
#include <cstring>
|
||||
#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 <cmath>
|
||||
#include <cfloat>
|
||||
#include <cstring>
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user