diff --git a/src/pair_table.cpp b/src/pair_table.cpp index c6bf50cef9..60272b5276 100644 --- a/src/pair_table.cpp +++ b/src/pair_table.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -18,24 +17,21 @@ #include "pair_table.h" -#include - -#include - #include "atom.h" -#include "force.h" #include "comm.h" -#include "neigh_list.h" -#include "memory.h" #include "error.h" - -#include "tokenizer.h" +#include "force.h" +#include "memory.h" +#include "neigh_list.h" #include "table_file_reader.h" +#include "tokenizer.h" +#include +#include using namespace LAMMPS_NS; -enum{NONE,RLINEAR,RSQ,BMP}; +enum { NONE, RLINEAR, RSQ, BMP }; #define EPSILONR 1.0e-6 @@ -68,17 +64,17 @@ PairTable::~PairTable() void PairTable::compute(int eflag, int vflag) { - int i,j,ii,jj,inum,jnum,itype,jtype,itable; - double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; - double rsq,factor_lj,fraction,value,a,b; - int *ilist,*jlist,*numneigh,**firstneigh; + int i, j, ii, jj, inum, jnum, itype, jtype, itable; + double xtmp, ytmp, ztmp, delx, dely, delz, evdwl, fpair; + double rsq, factor_lj, fraction, value, a, b; + int *ilist, *jlist, *numneigh, **firstneigh; Table *tb; union_int_float_t rsq_lookup; int tlm1 = tablength - 1; evdwl = 0.0; - ev_init(eflag,vflag); + ev_init(eflag, vflag); double **x = atom->x; double **f = atom->f; @@ -111,71 +107,70 @@ void PairTable::compute(int eflag, int vflag) delx = xtmp - x[j][0]; dely = ytmp - x[j][1]; delz = ztmp - x[j][2]; - rsq = delx*delx + dely*dely + delz*delz; + rsq = delx * delx + dely * dely + delz * delz; jtype = type[j]; if (rsq < cutsq[itype][jtype]) { tb = &tables[tabindex[itype][jtype]]; if (rsq < tb->innersq) - error->one(FLERR,"Pair distance < table inner cutoff: " - "ijtype {} {} dist {}",itype,jtype,sqrt(rsq)); + error->one(FLERR, "Pair distance < table inner cutoff: ijtype {} {} dist {}", itype, + jtype, sqrt(rsq)); if (tabstyle == LOOKUP) { - itable = static_cast ((rsq - tb->innersq) * tb->invdelta); + itable = static_cast((rsq - tb->innersq) * tb->invdelta); if (itable >= tlm1) - error->one(FLERR,"Pair distance > table outer cutoff: " - "ijtype {} {} dist {}",itype,jtype,sqrt(rsq)); + error->one(FLERR, "Pair distance > table outer cutoff: ijtype {} {} dist {}", itype, + jtype, sqrt(rsq)); fpair = factor_lj * tb->f[itable]; } else if (tabstyle == LINEAR) { - itable = static_cast ((rsq - tb->innersq) * tb->invdelta); + itable = static_cast((rsq - tb->innersq) * tb->invdelta); if (itable >= tlm1) - error->one(FLERR,"Pair distance > table outer cutoff: " - "ijtype {} {} dist {}",itype,jtype,sqrt(rsq)); + error->one(FLERR, "Pair distance > table outer cutoff: ijtype {} {} dist {}", itype, + jtype, sqrt(rsq)); fraction = (rsq - tb->rsq[itable]) * tb->invdelta; - value = tb->f[itable] + fraction*tb->df[itable]; + value = tb->f[itable] + fraction * tb->df[itable]; fpair = factor_lj * value; } else if (tabstyle == SPLINE) { - itable = static_cast ((rsq - tb->innersq) * tb->invdelta); + itable = static_cast((rsq - tb->innersq) * tb->invdelta); if (itable >= tlm1) - error->one(FLERR,"Pair distance > table outer cutoff: " - "ijtype {} {} dist {}",itype,jtype,sqrt(rsq)); + error->one(FLERR, "Pair distance > table outer cutoff: ijtype {} {} dist {}", itype, + jtype, sqrt(rsq)); b = (rsq - tb->rsq[itable]) * tb->invdelta; a = 1.0 - b; - value = a * tb->f[itable] + b * tb->f[itable+1] + - ((a*a*a-a)*tb->f2[itable] + (b*b*b-b)*tb->f2[itable+1]) * - tb->deltasq6; + value = a * tb->f[itable] + b * tb->f[itable + 1] + + ((a * a * a - a) * tb->f2[itable] + (b * b * b - b) * tb->f2[itable + 1]) * + tb->deltasq6; fpair = factor_lj * value; } else { rsq_lookup.f = rsq; itable = rsq_lookup.i & tb->nmask; itable >>= tb->nshiftbits; fraction = (rsq_lookup.f - tb->rsq[itable]) * tb->drsq[itable]; - value = tb->f[itable] + fraction*tb->df[itable]; + value = tb->f[itable] + fraction * tb->df[itable]; fpair = factor_lj * value; } - f[i][0] += delx*fpair; - f[i][1] += dely*fpair; - f[i][2] += delz*fpair; + 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; + f[j][0] -= delx * fpair; + f[j][1] -= dely * fpair; + f[j][2] -= delz * fpair; } if (eflag) { if (tabstyle == LOOKUP) evdwl = tb->e[itable]; else if (tabstyle == LINEAR || tabstyle == BITMAP) - evdwl = tb->e[itable] + fraction*tb->de[itable]; + evdwl = tb->e[itable] + fraction * tb->de[itable]; else - evdwl = a * tb->e[itable] + b * tb->e[itable+1] + - ((a*a*a-a)*tb->e2[itable] + (b*b*b-b)*tb->e2[itable+1]) * - tb->deltasq6; + evdwl = a * tb->e[itable] + b * tb->e[itable + 1] + + ((a * a * a - a) * tb->e2[itable] + (b * b * b - b) * tb->e2[itable + 1]) * + tb->deltasq6; evdwl *= factor_lj; } - if (evflag) ev_tally(i,j,nlocal,newton_pair, - evdwl,0.0,fpair,delx,dely,delz); + if (evflag) ev_tally(i, j, nlocal, newton_pair, evdwl, 0.0, fpair, delx, dely, delz); } } } @@ -192,13 +187,13 @@ void PairTable::allocate() allocated = 1; const int nt = atom->ntypes + 1; - memory->create(setflag,nt,nt,"pair:setflag"); - memory->create(cutsq,nt,nt,"pair:cutsq"); - memory->create(tabindex,nt,nt,"pair:tabindex"); + memory->create(setflag, nt, nt, "pair:setflag"); + memory->create(cutsq, nt, nt, "pair:cutsq"); + memory->create(tabindex, nt, nt, "pair:tabindex"); - memset(&setflag[0][0],0,sizeof(int)*nt*nt); - memset(&cutsq[0][0],0,sizeof(double)*nt*nt); - memset(&tabindex[0][0],0,sizeof(int)*nt*nt); + memset(&setflag[0][0], 0, sizeof(int) * nt * nt); + memset(&cutsq[0][0], 0, sizeof(double) * nt * nt); + memset(&tabindex[0][0], 0, sizeof(int) * nt * nt); } /* ---------------------------------------------------------------------- @@ -207,30 +202,41 @@ void PairTable::allocate() void PairTable::settings(int narg, char **arg) { - if (narg < 2) error->all(FLERR,"Illegal pair_style command"); + if (narg < 2) error->all(FLERR, "Illegal pair_style command"); // new settings - if (strcmp(arg[0],"lookup") == 0) tabstyle = LOOKUP; - else if (strcmp(arg[0],"linear") == 0) tabstyle = LINEAR; - else if (strcmp(arg[0],"spline") == 0) tabstyle = SPLINE; - else if (strcmp(arg[0],"bitmap") == 0) tabstyle = BITMAP; - else error->all(FLERR,"Unknown table style in pair_style command: {}", arg[0]); + if (strcmp(arg[0], "lookup") == 0) + tabstyle = LOOKUP; + else if (strcmp(arg[0], "linear") == 0) + tabstyle = LINEAR; + else if (strcmp(arg[0], "spline") == 0) + tabstyle = SPLINE; + else if (strcmp(arg[0], "bitmap") == 0) + tabstyle = BITMAP; + else + error->all(FLERR, "Unknown table style in pair_style command: {}", arg[0]); - tablength = utils::inumeric(FLERR,arg[1],false,lmp); - if (tablength < 2) error->all(FLERR,"Illegal number of pair table entries"); + tablength = utils::inumeric(FLERR, arg[1], false, lmp); + if (tablength < 2) error->all(FLERR, "Illegal number of pair table entries"); // optional keywords // assert the tabulation is compatible with a specific long-range solver int iarg = 2; while (iarg < narg) { - if (strcmp(arg[iarg],"ewald") == 0) ewaldflag = 1; - else if (strcmp(arg[iarg],"pppm") == 0) pppmflag = 1; - else if (strcmp(arg[iarg],"msm") == 0) msmflag = 1; - else if (strcmp(arg[iarg],"dispersion") == 0) dispersionflag = 1; - else if (strcmp(arg[iarg],"tip4p") == 0) tip4pflag = 1; - else error->all(FLERR,"Illegal pair_style command"); + if (strcmp(arg[iarg], "ewald") == 0) + ewaldflag = 1; + else if (strcmp(arg[iarg], "pppm") == 0) + pppmflag = 1; + else if (strcmp(arg[iarg], "msm") == 0) + msmflag = 1; + else if (strcmp(arg[iarg], "dispersion") == 0) + dispersionflag = 1; + else if (strcmp(arg[iarg], "tip4p") == 0) + tip4pflag = 1; + else + error->all(FLERR, "Illegal pair_style command"); iarg++; } @@ -256,37 +262,39 @@ void PairTable::settings(int narg, char **arg) void PairTable::coeff(int narg, char **arg) { - if (narg != 4 && narg != 5) error->all(FLERR,"Illegal pair_coeff command"); + if (narg != 4 && narg != 5) error->all(FLERR, "Illegal pair_coeff command"); 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); + 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); int me; - MPI_Comm_rank(world,&me); - tables = (Table *) - memory->srealloc(tables,(ntables+1)*sizeof(Table),"pair:tables"); + MPI_Comm_rank(world, &me); + tables = (Table *) memory->srealloc(tables, (ntables + 1) * sizeof(Table), "pair:tables"); Table *tb = &tables[ntables]; null_table(tb); - if (me == 0) read_table(tb,arg[2],arg[3]); + if (me == 0) read_table(tb, arg[2], arg[3]); bcast_table(tb); // set table cutoff - if (narg == 5) tb->cut = utils::numeric(FLERR,arg[4],false,lmp); - else if (tb->rflag) tb->cut = tb->rhi; - else tb->cut = tb->rfile[tb->ninput-1]; + if (narg == 5) + tb->cut = utils::numeric(FLERR, arg[4], false, lmp); + else if (tb->rflag) + tb->cut = tb->rhi; + else + tb->cut = tb->rfile[tb->ninput - 1]; // error check on table parameters // insure cutoff is within table // for BITMAP tables, file values can be in non-ascending order - if (tb->ninput <= 1) error->one(FLERR,"Invalid pair table length"); - double rlo,rhi; + if (tb->ninput <= 1) error->one(FLERR, "Invalid pair table length"); + double rlo, rhi; if (tb->rflag == 0) { rlo = tb->rfile[0]; - rhi = tb->rfile[tb->ninput-1]; + rhi = tb->rfile[tb->ninput - 1]; } else { rlo = tb->rlo; rhi = tb->rhi; @@ -300,12 +308,12 @@ void PairTable::coeff(int narg, char **arg) // for tabstyle SPLINE, always need to build spline tables tb->match = 0; - if (tabstyle == LINEAR && tb->ninput == tablength && - tb->rflag == RSQ && tb->rhi == tb->cut) tb->match = 1; - if (tabstyle == BITMAP && tb->ninput == 1 << tablength && - tb->rflag == BMP && tb->rhi == tb->cut) tb->match = 1; + if (tabstyle == LINEAR && tb->ninput == tablength && tb->rflag == RSQ && tb->rhi == tb->cut) + tb->match = 1; + if (tabstyle == BITMAP && tb->ninput == 1 << tablength && tb->rflag == BMP && tb->rhi == tb->cut) + tb->match = 1; if (tb->rflag == BMP && tb->match == 0) - error->all(FLERR,"Bitmapped table in file does not match requested table"); + error->all(FLERR, "Bitmapped table in file does not match requested table"); // spline read-in values and compute r,e,f vectors within table @@ -316,14 +324,14 @@ void PairTable::coeff(int narg, char **arg) int count = 0; for (int i = ilo; i <= ihi; i++) { - for (int j = MAX(jlo,i); j <= jhi; j++) { + for (int j = MAX(jlo, i); j <= jhi; j++) { tabindex[i][j] = ntables; setflag[i][j] = 1; count++; } } - if (count == 0) error->all(FLERR,"Illegal pair_coeff command"); + if (count == 0) error->all(FLERR, "Illegal pair_coeff command"); ntables++; } @@ -333,7 +341,7 @@ void PairTable::coeff(int narg, char **arg) double PairTable::init_one(int i, int j) { - if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set"); + if (setflag[i][j] == 0) error->all(FLERR, "All pair coeffs are not set"); tabindex[j][i] = tabindex[i][j]; @@ -354,39 +362,36 @@ void PairTable::read_table(Table *tb, char *file, char *keyword) // transparently convert units for supported conversions int unit_convert = reader.get_unit_convert(); - double conversion_factor = utils::get_conversion_factor(utils::ENERGY, - unit_convert); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, unit_convert); char *line = reader.find_section_start(keyword); - if (!line) { - error->one(FLERR,"Did not find keyword in table file"); - } + if (!line) { error->one(FLERR, "Did not find keyword in table file"); } // read args on 2nd line of section // allocate table arrays for file values line = reader.next_line(); param_extract(tb, line); - memory->create(tb->rfile,tb->ninput,"pair:rfile"); - memory->create(tb->efile,tb->ninput,"pair:efile"); - memory->create(tb->ffile,tb->ninput,"pair:ffile"); + memory->create(tb->rfile, tb->ninput, "pair:rfile"); + memory->create(tb->efile, tb->ninput, "pair:efile"); + memory->create(tb->ffile, tb->ninput, "pair:ffile"); // setup bitmap parameters for table to read in tb->ntablebits = 0; - int masklo,maskhi,nmask,nshiftbits; + int masklo, maskhi, nmask, nshiftbits; if (tb->rflag == BMP) { while (1 << tb->ntablebits < tb->ninput) tb->ntablebits++; if (1 << tb->ntablebits != tb->ninput) - error->one(FLERR,"Bitmapped table is incorrect length in table file"); - init_bitmap(tb->rlo,tb->rhi,tb->ntablebits,masklo,maskhi,nmask,nshiftbits); + error->one(FLERR, "Bitmapped table is incorrect length in table file"); + init_bitmap(tb->rlo, tb->rhi, tb->ntablebits, masklo, maskhi, nmask, nshiftbits); } // read r,e,f table values from file // if rflag set, compute r // if rflag not set, use r from file - double rfile,rnew; + double rfile, rnew; union_int_float_t rsq_lookup; int rerror = 0; @@ -408,22 +413,21 @@ void PairTable::read_table(Table *tb, char *file, char *keyword) rnew = rfile; if (tb->rflag == RLINEAR) - rnew = tb->rlo + (tb->rhi - tb->rlo)*i/(tb->ninput-1); + rnew = tb->rlo + (tb->rhi - tb->rlo) * i / (tb->ninput - 1); else if (tb->rflag == RSQ) { - rnew = tb->rlo*tb->rlo + - (tb->rhi*tb->rhi - tb->rlo*tb->rlo)*i/(tb->ninput-1); + rnew = tb->rlo * tb->rlo + (tb->rhi * tb->rhi - tb->rlo * tb->rlo) * i / (tb->ninput - 1); rnew = sqrt(rnew); } else if (tb->rflag == BMP) { rsq_lookup.i = i << nshiftbits; rsq_lookup.i |= masklo; - if (rsq_lookup.f < tb->rlo*tb->rlo) { + if (rsq_lookup.f < tb->rlo * tb->rlo) { rsq_lookup.i = i << nshiftbits; rsq_lookup.i |= maskhi; } rnew = sqrtf(rsq_lookup.f); } - if (tb->rflag && fabs(rnew-rfile)/rfile > EPSILONR) rerror++; + if (tb->rflag && fabs(rnew - rfile) / rfile > EPSILONR) rerror++; tb->rfile[i] = rnew; } @@ -433,23 +437,23 @@ void PairTable::read_table(Table *tb, char *file, char *keyword) // skip two end points since do not have surrounding secants // inflection point is where curvature changes sign - double r,e,f,rprev,rnext,eprev,enext,fleft,fright; + double r, e, f, rprev, rnext, eprev, enext, fleft, fright; int ferror = 0; // bitmapped tables do not follow regular ordering, so we cannot check them here if (tb->rflag != BMP) { - for (int i = 1; i < tb->ninput-1; i++) { + for (int i = 1; i < tb->ninput - 1; i++) { r = tb->rfile[i]; - rprev = tb->rfile[i-1]; - rnext = tb->rfile[i+1]; + rprev = tb->rfile[i - 1]; + rnext = tb->rfile[i + 1]; e = tb->efile[i]; - eprev = tb->efile[i-1]; - enext = tb->efile[i+1]; + eprev = tb->efile[i - 1]; + enext = tb->efile[i + 1]; f = tb->ffile[i]; - fleft = - (e-eprev) / (r-rprev); - fright = - (enext-e) / (rnext-r); + fleft = -(e - eprev) / (r - rprev); + fright = -(enext - e) / (rnext - r); if (f < fleft && f < fright) ferror++; if (f > fleft && f > fright) ferror++; //printf("Values %d: %g %g %g\n",i,r,e,f); @@ -458,23 +462,26 @@ void PairTable::read_table(Table *tb, char *file, char *keyword) } if (ferror) - error->warning(FLERR,"{} of {} force values in table {} are inconsistent " - "with -dE/dr.\nWARNING: Should only be flagged at " - "inflection points",ferror,tb->ninput,keyword); + error->warning(FLERR, + "{} of {} force values in table {} are inconsistent with -dE/dr.\n" + "WARNING: Should only be flagged at inflection points", + ferror, tb->ninput, keyword); // warn if re-computed distance values differ from file values if (rerror) - error->warning(FLERR,"{} of {} distance values in table {} with relative " - "error\nWARNING: over {} to re-computed values", - rerror,tb->ninput,EPSILONR,keyword); + error->warning(FLERR, + "{} of {} distance values in table {} with relative error\n" + "WARNING: over {} to re-computed values", + rerror, tb->ninput, EPSILONR, keyword); // warn if data was read incompletely, e.g. columns were missing if (cerror) - error->warning(FLERR,"{} of {} lines in table {} were incomplete\n" + error->warning(FLERR, + "{} of {} lines in table {} were incomplete\n" "WARNING: or could not be parsed completely", - cerror,tb->ninput,keyword); + cerror, tb->ninput, keyword); } /* ---------------------------------------------------------------------- @@ -485,29 +492,29 @@ void PairTable::read_table(Table *tb, char *file, char *keyword) void PairTable::bcast_table(Table *tb) { - MPI_Bcast(&tb->ninput,1,MPI_INT,0,world); + MPI_Bcast(&tb->ninput, 1, MPI_INT, 0, world); int me; - MPI_Comm_rank(world,&me); + MPI_Comm_rank(world, &me); if (me > 0) { - memory->create(tb->rfile,tb->ninput,"pair:rfile"); - memory->create(tb->efile,tb->ninput,"pair:efile"); - memory->create(tb->ffile,tb->ninput,"pair:ffile"); + memory->create(tb->rfile, tb->ninput, "pair:rfile"); + memory->create(tb->efile, tb->ninput, "pair:efile"); + memory->create(tb->ffile, tb->ninput, "pair:ffile"); } - MPI_Bcast(tb->rfile,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->rfile, 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->rflag,1,MPI_INT,0,world); + MPI_Bcast(&tb->rflag, 1, MPI_INT, 0, world); if (tb->rflag) { - MPI_Bcast(&tb->rlo,1,MPI_DOUBLE,0,world); - MPI_Bcast(&tb->rhi,1,MPI_DOUBLE,0,world); + MPI_Bcast(&tb->rlo, 1, MPI_DOUBLE, 0, world); + MPI_Bcast(&tb->rhi, 1, MPI_DOUBLE, 0, world); } - MPI_Bcast(&tb->fpflag,1,MPI_INT,0,world); + MPI_Bcast(&tb->fpflag, 1, MPI_INT, 0, world); if (tb->fpflag) { - MPI_Bcast(&tb->fplo,1,MPI_DOUBLE,0,world); - MPI_Bcast(&tb->fphi,1,MPI_DOUBLE,0,world); + MPI_Bcast(&tb->fplo, 1, MPI_DOUBLE, 0, world); + MPI_Bcast(&tb->fphi, 1, MPI_DOUBLE, 0, world); } } @@ -518,22 +525,22 @@ void PairTable::bcast_table(Table *tb) void PairTable::spline_table(Table *tb) { - memory->create(tb->e2file,tb->ninput,"pair:e2file"); - memory->create(tb->f2file,tb->ninput,"pair:f2file"); + memory->create(tb->e2file, tb->ninput, "pair:e2file"); + memory->create(tb->f2file, tb->ninput, "pair:f2file"); - double ep0 = - tb->ffile[0]; - double epn = - tb->ffile[tb->ninput-1]; - spline(tb->rfile,tb->efile,tb->ninput,ep0,epn,tb->e2file); + double ep0 = -tb->ffile[0]; + double epn = -tb->ffile[tb->ninput - 1]; + spline(tb->rfile, tb->efile, tb->ninput, ep0, epn, tb->e2file); if (tb->fpflag == 0) { tb->fplo = (tb->ffile[1] - tb->ffile[0]) / (tb->rfile[1] - tb->rfile[0]); - tb->fphi = (tb->ffile[tb->ninput-1] - tb->ffile[tb->ninput-2]) / - (tb->rfile[tb->ninput-1] - tb->rfile[tb->ninput-2]); + tb->fphi = (tb->ffile[tb->ninput - 1] - tb->ffile[tb->ninput - 2]) / + (tb->rfile[tb->ninput - 1] - tb->rfile[tb->ninput - 2]); } double fp0 = tb->fplo; double fpn = tb->fphi; - spline(tb->rfile,tb->ffile,tb->ninput,fp0,fpn,tb->f2file); + spline(tb->rfile, tb->ffile, tb->ninput, fp0, fpn, tb->f2file); } /* ---------------------------------------------------------------------- @@ -556,9 +563,12 @@ void PairTable::param_extract(Table *tb, char *line) if (word == "N") { tb->ninput = values.next_int(); } else if ((word == "R") || (word == "RSQ") || (word == "BITMAP")) { - if (word == "R") tb->rflag = RLINEAR; - else if (word == "RSQ") tb->rflag = RSQ; - else if (word == "BITMAP") tb->rflag = BMP; + if (word == "R") + tb->rflag = RLINEAR; + else if (word == "RSQ") + tb->rflag = RSQ; + else if (word == "BITMAP") + tb->rflag = BMP; tb->rlo = values.next_double(); tb->rhi = values.next_double(); } else if (word == "FPRIME") { @@ -566,14 +576,14 @@ void PairTable::param_extract(Table *tb, char *line) tb->fplo = values.next_double(); tb->fphi = values.next_double(); } else { - error->one(FLERR,"Invalid keyword {} in pair table parameters", word); + error->one(FLERR, "Invalid keyword {} in pair table parameters", word); } } } catch (TokenizerException &e) { error->one(FLERR, e.what()); } - if (tb->ninput == 0) error->one(FLERR,"Pair table parameters did not set N"); + if (tb->ninput == 0) error->one(FLERR, "Pair table parameters did not set N"); } /* ---------------------------------------------------------------------- @@ -582,18 +592,20 @@ void PairTable::param_extract(Table *tb, char *line) void PairTable::compute_table(Table *tb) { - int tlm1 = tablength-1; + int tlm1 = tablength - 1; // inner = inner table bound // cut = outer table bound // delta = table spacing in rsq for N-1 bins double inner; - if (tb->rflag) inner = tb->rlo; - else inner = tb->rfile[0]; - tb->innersq = inner*inner; - tb->delta = (tb->cut*tb->cut - tb->innersq) / tlm1; - tb->invdelta = 1.0/tb->delta; + if (tb->rflag) + inner = tb->rlo; + else + inner = tb->rfile[0]; + tb->innersq = inner * inner; + tb->delta = (tb->cut * tb->cut - tb->innersq) / tlm1; + tb->invdelta = 1.0 / tb->delta; // direct lookup tables // N-1 evenly spaced bins in rsq from inner to cut @@ -603,15 +615,15 @@ void PairTable::compute_table(Table *tb) // e,f are never a match to read-in values, always computed via spline interp if (tabstyle == LOOKUP) { - memory->create(tb->e,tlm1,"pair:e"); - memory->create(tb->f,tlm1,"pair:f"); + memory->create(tb->e, tlm1, "pair:e"); + memory->create(tb->f, tlm1, "pair:f"); - double r,rsq; + double r, rsq; for (int i = 0; i < tlm1; i++) { - rsq = tb->innersq + (i+0.5)*tb->delta; + rsq = tb->innersq + (i + 0.5) * tb->delta; r = sqrt(rsq); - tb->e[i] = splint(tb->rfile,tb->efile,tb->e2file,tb->ninput,r); - tb->f[i] = splint(tb->rfile,tb->ffile,tb->f2file,tb->ninput,r)/r; + tb->e[i] = splint(tb->rfile, tb->efile, tb->e2file, tb->ninput, r); + tb->f[i] = splint(tb->rfile, tb->ffile, tb->f2file, tb->ninput, r) / r; } } @@ -624,29 +636,29 @@ void PairTable::compute_table(Table *tb) // e,f can match read-in values, else compute via spline interp if (tabstyle == LINEAR) { - memory->create(tb->rsq,tablength,"pair:rsq"); - memory->create(tb->e,tablength,"pair:e"); - memory->create(tb->f,tablength,"pair:f"); - memory->create(tb->de,tlm1,"pair:de"); - memory->create(tb->df,tlm1,"pair:df"); + memory->create(tb->rsq, tablength, "pair:rsq"); + memory->create(tb->e, tablength, "pair:e"); + memory->create(tb->f, tablength, "pair:f"); + memory->create(tb->de, tlm1, "pair:de"); + memory->create(tb->df, tlm1, "pair:df"); - double r,rsq; + double r, rsq; for (int i = 0; i < tablength; i++) { - rsq = tb->innersq + i*tb->delta; + rsq = tb->innersq + i * tb->delta; r = sqrt(rsq); tb->rsq[i] = rsq; if (tb->match) { tb->e[i] = tb->efile[i]; - tb->f[i] = tb->ffile[i]/r; + tb->f[i] = tb->ffile[i] / r; } else { - tb->e[i] = splint(tb->rfile,tb->efile,tb->e2file,tb->ninput,r); - tb->f[i] = splint(tb->rfile,tb->ffile,tb->f2file,tb->ninput,r)/r; + tb->e[i] = splint(tb->rfile, tb->efile, tb->e2file, tb->ninput, r); + tb->f[i] = splint(tb->rfile, tb->ffile, tb->f2file, tb->ninput, r) / r; } } for (int i = 0; i < tlm1; i++) { - tb->de[i] = tb->e[i+1] - tb->e[i]; - tb->df[i] = tb->f[i+1] - tb->f[i]; + tb->de[i] = tb->e[i + 1] - tb->e[i]; + tb->df[i] = tb->f[i + 1] - tb->f[i]; } } @@ -659,25 +671,25 @@ void PairTable::compute_table(Table *tb) // e,f can match read-in values, else compute via spline interp if (tabstyle == SPLINE) { - memory->create(tb->rsq,tablength,"pair:rsq"); - memory->create(tb->e,tablength,"pair:e"); - memory->create(tb->f,tablength,"pair:f"); - memory->create(tb->e2,tablength,"pair:e2"); - memory->create(tb->f2,tablength,"pair:f2"); + memory->create(tb->rsq, tablength, "pair:rsq"); + memory->create(tb->e, tablength, "pair:e"); + memory->create(tb->f, tablength, "pair:f"); + memory->create(tb->e2, tablength, "pair:e2"); + memory->create(tb->f2, tablength, "pair:f2"); - tb->deltasq6 = tb->delta*tb->delta / 6.0; + tb->deltasq6 = tb->delta * tb->delta / 6.0; - double r,rsq; + double r, rsq; for (int i = 0; i < tablength; i++) { - rsq = tb->innersq + i*tb->delta; + rsq = tb->innersq + i * tb->delta; r = sqrt(rsq); tb->rsq[i] = rsq; if (tb->match) { tb->e[i] = tb->efile[i]; - tb->f[i] = tb->ffile[i]/r; + tb->f[i] = tb->ffile[i] / r; } else { - tb->e[i] = splint(tb->rfile,tb->efile,tb->e2file,tb->ninput,r); - tb->f[i] = splint(tb->rfile,tb->ffile,tb->f2file,tb->ninput,r); + tb->e[i] = splint(tb->rfile, tb->efile, tb->e2file, tb->ninput, r); + tb->f[i] = splint(tb->rfile, tb->ffile, tb->f2file, tb->ninput, r); } } @@ -685,38 +697,39 @@ void PairTable::compute_table(Table *tb) // h(r) = e(r) and g(r) = r^2 // dh/dg = (de/dr) / 2r = -f/2r - double ep0 = - tb->f[0] / (2.0 * sqrt(tb->innersq)); - double epn = - tb->f[tlm1] / (2.0 * tb->cut); - spline(tb->rsq,tb->e,tablength,ep0,epn,tb->e2); + double ep0 = -tb->f[0] / (2.0 * sqrt(tb->innersq)); + double epn = -tb->f[tlm1] / (2.0 * tb->cut); + spline(tb->rsq, tb->e, tablength, ep0, epn, tb->e2); // fp0,fpn = dh/dg at inner and at cut // h(r) = f(r)/r and g(r) = r^2 // dh/dg = (1/r df/dr - f/r^2) / 2r // dh/dg in secant approx = (f(r2)/r2 - f(r1)/r1) / (g(r2) - g(r1)) - double fp0,fpn; + double fp0, fpn; double secant_factor = 0.1; - if (tb->fpflag) fp0 = (tb->fplo/sqrt(tb->innersq) - tb->f[0]/tb->innersq) / - (2.0 * sqrt(tb->innersq)); + if (tb->fpflag) + fp0 = (tb->fplo / sqrt(tb->innersq) - tb->f[0] / tb->innersq) / (2.0 * sqrt(tb->innersq)); else { double rsq1 = tb->innersq; - double rsq2 = rsq1 + secant_factor*tb->delta; - fp0 = (splint(tb->rfile,tb->ffile,tb->f2file,tb->ninput,sqrt(rsq2)) / - sqrt(rsq2) - tb->f[0] / sqrt(rsq1)) / (secant_factor*tb->delta); + double rsq2 = rsq1 + secant_factor * tb->delta; + fp0 = (splint(tb->rfile, tb->ffile, tb->f2file, tb->ninput, sqrt(rsq2)) / sqrt(rsq2) - + tb->f[0] / sqrt(rsq1)) / + (secant_factor * tb->delta); } - if (tb->fpflag && tb->cut == tb->rfile[tb->ninput-1]) fpn = - (tb->fphi/tb->cut - tb->f[tlm1]/(tb->cut*tb->cut)) / (2.0 * tb->cut); + if (tb->fpflag && tb->cut == tb->rfile[tb->ninput - 1]) + fpn = (tb->fphi / tb->cut - tb->f[tlm1] / (tb->cut * tb->cut)) / (2.0 * tb->cut); else { double rsq2 = tb->cut * tb->cut; - double rsq1 = rsq2 - secant_factor*tb->delta; + double rsq1 = rsq2 - secant_factor * tb->delta; fpn = (tb->f[tlm1] / sqrt(rsq2) - - splint(tb->rfile,tb->ffile,tb->f2file,tb->ninput,sqrt(rsq1)) / - sqrt(rsq1)) / (secant_factor*tb->delta); + splint(tb->rfile, tb->ffile, tb->f2file, tb->ninput, sqrt(rsq1)) / sqrt(rsq1)) / + (secant_factor * tb->delta); } for (int i = 0; i < tablength; i++) tb->f[i] /= sqrt(tb->rsq[i]); - spline(tb->rsq,tb->f,tablength,fp0,fpn,tb->f2); + spline(tb->rsq, tb->f, tablength, fp0, fpn, tb->f2); } // bitmapped linear tables @@ -727,21 +740,21 @@ void PairTable::compute_table(Table *tb) if (tabstyle == BITMAP) { double r; union_int_float_t rsq_lookup; - int masklo,maskhi; + int masklo, maskhi; // linear lookup tables of length ntable = 2^n // stored value = value at lower edge of bin - init_bitmap(inner,tb->cut,tablength,masklo,maskhi,tb->nmask,tb->nshiftbits); + init_bitmap(inner, tb->cut, tablength, masklo, maskhi, tb->nmask, tb->nshiftbits); int ntable = 1 << tablength; int ntablem1 = ntable - 1; - memory->create(tb->rsq,ntable,"pair:rsq"); - memory->create(tb->e,ntable,"pair:e"); - memory->create(tb->f,ntable,"pair:f"); - memory->create(tb->de,ntable,"pair:de"); - memory->create(tb->df,ntable,"pair:df"); - memory->create(tb->drsq,ntable,"pair:drsq"); + memory->create(tb->rsq, ntable, "pair:rsq"); + memory->create(tb->e, ntable, "pair:e"); + memory->create(tb->f, ntable, "pair:f"); + memory->create(tb->de, ntable, "pair:de"); + memory->create(tb->df, ntable, "pair:df"); + memory->create(tb->drsq, ntable, "pair:drsq"); union_int_float_t minrsq_lookup; minrsq_lookup.i = 0 << tb->nshiftbits; @@ -758,20 +771,20 @@ void PairTable::compute_table(Table *tb) tb->rsq[i] = rsq_lookup.f; if (tb->match) { tb->e[i] = tb->efile[i]; - tb->f[i] = tb->ffile[i]/r; + tb->f[i] = tb->ffile[i] / r; } else { - tb->e[i] = splint(tb->rfile,tb->efile,tb->e2file,tb->ninput,r); - tb->f[i] = splint(tb->rfile,tb->ffile,tb->f2file,tb->ninput,r)/r; + tb->e[i] = splint(tb->rfile, tb->efile, tb->e2file, tb->ninput, r); + tb->f[i] = splint(tb->rfile, tb->ffile, tb->f2file, tb->ninput, r) / r; } - minrsq_lookup.f = MIN(minrsq_lookup.f,rsq_lookup.f); + minrsq_lookup.f = MIN(minrsq_lookup.f, rsq_lookup.f); } tb->innersq = minrsq_lookup.f; for (int i = 0; i < ntablem1; i++) { - tb->de[i] = tb->e[i+1] - tb->e[i]; - tb->df[i] = tb->f[i+1] - tb->f[i]; - tb->drsq[i] = 1.0/(tb->rsq[i+1] - tb->rsq[i]); + tb->de[i] = tb->e[i + 1] - tb->e[i]; + tb->df[i] = tb->f[i + 1] - tb->f[i]; + tb->drsq[i] = 1.0 / (tb->rsq[i + 1] - tb->rsq[i]); } // get the delta values for the last table entries @@ -779,7 +792,7 @@ void PairTable::compute_table(Table *tb) tb->de[ntablem1] = tb->e[0] - tb->e[ntablem1]; tb->df[ntablem1] = tb->f[0] - tb->f[ntablem1]; - tb->drsq[ntablem1] = 1.0/(tb->rsq[0] - tb->rsq[ntablem1]); + tb->drsq[ntablem1] = 1.0 / (tb->rsq[0] - tb->rsq[ntablem1]); // get the correct delta values at itablemax // smallest r is in bin itablemin @@ -791,7 +804,7 @@ void PairTable::compute_table(Table *tb) // if tb->match, data at cut*cut is unavailable, so we'll take // deltas at itablemax-1 as a good approximation - double e_tmp,f_tmp; + double e_tmp, f_tmp; int itablemin = minrsq_lookup.i & tb->nmask; itablemin >>= tb->nshiftbits; int itablemax = itablemin - 1; @@ -800,19 +813,19 @@ void PairTable::compute_table(Table *tb) if (itablemax == 0) itablemaxm1 = ntablem1; rsq_lookup.i = itablemax << tb->nshiftbits; rsq_lookup.i |= maskhi; - if (rsq_lookup.f < tb->cut*tb->cut) { + if (rsq_lookup.f < tb->cut * tb->cut) { if (tb->match) { tb->de[itablemax] = tb->de[itablemaxm1]; tb->df[itablemax] = tb->df[itablemaxm1]; tb->drsq[itablemax] = tb->drsq[itablemaxm1]; } else { - rsq_lookup.f = tb->cut*tb->cut; + rsq_lookup.f = tb->cut * tb->cut; r = sqrtf(rsq_lookup.f); - e_tmp = splint(tb->rfile,tb->efile,tb->e2file,tb->ninput,r); - f_tmp = splint(tb->rfile,tb->ffile,tb->f2file,tb->ninput,r)/r; + e_tmp = splint(tb->rfile, tb->efile, tb->e2file, tb->ninput, r); + f_tmp = splint(tb->rfile, tb->ffile, tb->f2file, tb->ninput, r) / r; tb->de[itablemax] = e_tmp - tb->e[itablemax]; tb->df[itablemax] = f_tmp - tb->f[itablemax]; - tb->drsq[itablemax] = 1.0/(rsq_lookup.f - tb->rsq[itablemax]); + tb->drsq[itablemax] = 1.0 / (rsq_lookup.f - tb->rsq[itablemax]); } } } @@ -856,55 +869,58 @@ void PairTable::free_table(Table *tb) spline and splint routines modified from Numerical Recipes ------------------------------------------------------------------------- */ -void PairTable::spline(double *x, double *y, int n, - double yp1, double ypn, double *y2) +void PairTable::spline(double *x, double *y, int n, double yp1, double ypn, double *y2) { - int i,k; - double p,qn,sig,un; + int i, k; + double p, qn, sig, un; double *u = new double[n]; - if (yp1 > 0.99e30) y2[0] = u[0] = 0.0; + if (yp1 > 0.99e30) + y2[0] = u[0] = 0.0; else { y2[0] = -0.5; - u[0] = (3.0/(x[1]-x[0])) * ((y[1]-y[0]) / (x[1]-x[0]) - yp1); + u[0] = (3.0 / (x[1] - x[0])) * ((y[1] - y[0]) / (x[1] - x[0]) - yp1); } - for (i = 1; i < n-1; i++) { - sig = (x[i]-x[i-1]) / (x[i+1]-x[i-1]); - p = sig*y2[i-1] + 2.0; - y2[i] = (sig-1.0) / p; - u[i] = (y[i+1]-y[i]) / (x[i+1]-x[i]) - (y[i]-y[i-1]) / (x[i]-x[i-1]); - u[i] = (6.0*u[i] / (x[i+1]-x[i-1]) - sig*u[i-1]) / p; + for (i = 1; i < n - 1; i++) { + sig = (x[i] - x[i - 1]) / (x[i + 1] - x[i - 1]); + p = sig * y2[i - 1] + 2.0; + y2[i] = (sig - 1.0) / p; + u[i] = (y[i + 1] - y[i]) / (x[i + 1] - x[i]) - (y[i] - y[i - 1]) / (x[i] - x[i - 1]); + u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p; } - if (ypn > 0.99e30) qn = un = 0.0; + if (ypn > 0.99e30) + qn = un = 0.0; else { qn = 0.5; - un = (3.0/(x[n-1]-x[n-2])) * (ypn - (y[n-1]-y[n-2]) / (x[n-1]-x[n-2])); + un = (3.0 / (x[n - 1] - x[n - 2])) * (ypn - (y[n - 1] - y[n - 2]) / (x[n - 1] - x[n - 2])); } - y2[n-1] = (un-qn*u[n-2]) / (qn*y2[n-2] + 1.0); - for (k = n-2; k >= 0; k--) y2[k] = y2[k]*y2[k+1] + u[k]; + y2[n - 1] = (un - qn * u[n - 2]) / (qn * y2[n - 2] + 1.0); + for (k = n - 2; k >= 0; k--) y2[k] = y2[k] * y2[k + 1] + u[k]; - delete [] u; + delete[] u; } /* ---------------------------------------------------------------------- */ double PairTable::splint(double *xa, double *ya, double *y2a, int n, double x) { - int klo,khi,k; - double h,b,a,y; + int klo, khi, k; + double h, b, a, y; klo = 0; - khi = n-1; - while (khi-klo > 1) { - k = (khi+klo) >> 1; - if (xa[k] > x) khi = k; - else klo = k; + khi = n - 1; + while (khi - klo > 1) { + k = (khi + klo) >> 1; + if (xa[k] > x) + khi = k; + else + klo = k; } - h = xa[khi]-xa[klo]; - a = (xa[khi]-x) / h; - b = (x-xa[klo]) / h; - y = a*ya[klo] + b*ya[khi] + - ((a*a*a-a)*y2a[klo] + (b*b*b-b)*y2a[khi]) * (h*h)/6.0; + h = xa[khi] - xa[klo]; + a = (xa[khi] - x) / h; + b = (x - xa[klo]) / h; + 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; } @@ -933,13 +949,13 @@ void PairTable::read_restart(FILE *fp) void PairTable::write_restart_settings(FILE *fp) { - fwrite(&tabstyle,sizeof(int),1,fp); - fwrite(&tablength,sizeof(int),1,fp); - fwrite(&ewaldflag,sizeof(int),1,fp); - fwrite(&pppmflag,sizeof(int),1,fp); - fwrite(&msmflag,sizeof(int),1,fp); - fwrite(&dispersionflag,sizeof(int),1,fp); - fwrite(&tip4pflag,sizeof(int),1,fp); + fwrite(&tabstyle, sizeof(int), 1, fp); + fwrite(&tablength, sizeof(int), 1, fp); + fwrite(&ewaldflag, sizeof(int), 1, fp); + fwrite(&pppmflag, sizeof(int), 1, fp); + fwrite(&msmflag, sizeof(int), 1, fp); + fwrite(&dispersionflag, sizeof(int), 1, fp); + fwrite(&tip4pflag, sizeof(int), 1, fp); } /* ---------------------------------------------------------------------- @@ -949,54 +965,52 @@ void PairTable::write_restart_settings(FILE *fp) void PairTable::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); - utils::sfread(FLERR,&ewaldflag,sizeof(int),1,fp,nullptr,error); - utils::sfread(FLERR,&pppmflag,sizeof(int),1,fp,nullptr,error); - utils::sfread(FLERR,&msmflag,sizeof(int),1,fp,nullptr,error); - utils::sfread(FLERR,&dispersionflag,sizeof(int),1,fp,nullptr,error); - utils::sfread(FLERR,&tip4pflag,sizeof(int),1,fp,nullptr,error); + utils::sfread(FLERR, &tabstyle, sizeof(int), 1, fp, nullptr, error); + utils::sfread(FLERR, &tablength, sizeof(int), 1, fp, nullptr, error); + utils::sfread(FLERR, &ewaldflag, sizeof(int), 1, fp, nullptr, error); + utils::sfread(FLERR, &pppmflag, sizeof(int), 1, fp, nullptr, error); + utils::sfread(FLERR, &msmflag, sizeof(int), 1, fp, nullptr, error); + utils::sfread(FLERR, &dispersionflag, sizeof(int), 1, fp, nullptr, error); + utils::sfread(FLERR, &tip4pflag, sizeof(int), 1, fp, nullptr, error); } - MPI_Bcast(&tabstyle,1,MPI_INT,0,world); - MPI_Bcast(&tablength,1,MPI_INT,0,world); - MPI_Bcast(&ewaldflag,1,MPI_INT,0,world); - MPI_Bcast(&pppmflag,1,MPI_INT,0,world); - MPI_Bcast(&msmflag,1,MPI_INT,0,world); - MPI_Bcast(&dispersionflag,1,MPI_INT,0,world); - MPI_Bcast(&tip4pflag,1,MPI_INT,0,world); + MPI_Bcast(&tabstyle, 1, MPI_INT, 0, world); + MPI_Bcast(&tablength, 1, MPI_INT, 0, world); + MPI_Bcast(&ewaldflag, 1, MPI_INT, 0, world); + MPI_Bcast(&pppmflag, 1, MPI_INT, 0, world); + MPI_Bcast(&msmflag, 1, MPI_INT, 0, world); + MPI_Bcast(&dispersionflag, 1, MPI_INT, 0, world); + MPI_Bcast(&tip4pflag, 1, MPI_INT, 0, world); } /* ---------------------------------------------------------------------- */ double PairTable::single(int /*i*/, int /*j*/, int itype, int jtype, double rsq, - double /*factor_coul*/, double factor_lj, - double &fforce) + double /*factor_coul*/, double factor_lj, double &fforce) { int itable; - double fraction,value,a,b,phi; + double fraction, value, a, b, phi; int tlm1 = tablength - 1; Table *tb = &tables[tabindex[itype][jtype]]; - if (rsq < tb->innersq) error->one(FLERR,"Pair distance < table inner cutoff"); + if (rsq < tb->innersq) error->one(FLERR, "Pair distance < table inner cutoff"); if (tabstyle == LOOKUP) { - itable = static_cast ((rsq-tb->innersq) * tb->invdelta); - if (itable >= tlm1) error->one(FLERR,"Pair distance > table outer cutoff"); + itable = static_cast((rsq - tb->innersq) * tb->invdelta); + if (itable >= tlm1) error->one(FLERR, "Pair distance > table outer cutoff"); fforce = factor_lj * tb->f[itable]; } else if (tabstyle == LINEAR) { - itable = static_cast ((rsq-tb->innersq) * tb->invdelta); - if (itable >= tlm1) error->one(FLERR,"Pair distance > table outer cutoff"); + itable = static_cast((rsq - tb->innersq) * tb->invdelta); + if (itable >= tlm1) error->one(FLERR, "Pair distance > table outer cutoff"); fraction = (rsq - tb->rsq[itable]) * tb->invdelta; - value = tb->f[itable] + fraction*tb->df[itable]; + value = tb->f[itable] + fraction * tb->df[itable]; fforce = factor_lj * value; } else if (tabstyle == SPLINE) { - itable = static_cast ((rsq-tb->innersq) * tb->invdelta); - if (itable >= tlm1) error->one(FLERR,"Pair distance > table outer cutoff"); + itable = static_cast((rsq - tb->innersq) * tb->invdelta); + if (itable >= tlm1) error->one(FLERR, "Pair distance > table outer cutoff"); b = (rsq - tb->rsq[itable]) * tb->invdelta; a = 1.0 - b; - value = a * tb->f[itable] + b * tb->f[itable+1] + - ((a*a*a-a)*tb->f2[itable] + (b*b*b-b)*tb->f2[itable+1]) * - tb->deltasq6; + value = a * tb->f[itable] + b * tb->f[itable + 1] + + ((a * a * a - a) * tb->f2[itable] + (b * b * b - b) * tb->f2[itable + 1]) * tb->deltasq6; fforce = factor_lj * value; } else { union_int_float_t rsq_lookup; @@ -1004,18 +1018,18 @@ double PairTable::single(int /*i*/, int /*j*/, int itype, int jtype, double rsq, itable = rsq_lookup.i & tb->nmask; itable >>= tb->nshiftbits; fraction = (rsq_lookup.f - tb->rsq[itable]) * tb->drsq[itable]; - value = tb->f[itable] + fraction*tb->df[itable]; + value = tb->f[itable] + fraction * tb->df[itable]; fforce = factor_lj * value; } if (tabstyle == LOOKUP) phi = tb->e[itable]; else if (tabstyle == LINEAR || tabstyle == BITMAP) - phi = tb->e[itable] + fraction*tb->de[itable]; + phi = tb->e[itable] + fraction * tb->de[itable]; else - phi = a * tb->e[itable] + b * tb->e[itable+1] + - ((a*a*a-a)*tb->e2[itable] + (b*b*b-b)*tb->e2[itable+1]) * tb->deltasq6; - return factor_lj*phi; + phi = a * tb->e[itable] + b * tb->e[itable + 1] + + ((a * a * a - a) * tb->e2[itable] + (b * b * b - b) * tb->e2[itable + 1]) * tb->deltasq6; + return factor_lj * phi; } /* ---------------------------------------------------------------------- @@ -1027,8 +1041,8 @@ double PairTable::single(int /*i*/, int /*j*/, int itype, int jtype, double rsq, void *PairTable::extract(const char *str, int &dim) { - if (strcmp(str,"cut_coul") != 0) return nullptr; - if (ntables == 0) error->all(FLERR,"All pair coeffs are not set"); + if (strcmp(str, "cut_coul") != 0) return nullptr; + if (ntables == 0) error->all(FLERR, "All pair coeffs are not set"); // only check for cutoff consistency if claiming to be KSpace compatible @@ -1036,9 +1050,9 @@ void *PairTable::extract(const char *str, int &dim) double cut_coul = tables[0].cut; for (int m = 1; m < ntables; m++) if (tables[m].cut != cut_coul) - error->all(FLERR, - "Pair table cutoffs must all be equal to use with KSpace"); + error->all(FLERR, "Pair table cutoffs must all be equal to use with KSpace"); dim = 0; return &tables[0].cut; - } else return nullptr; + } else + return nullptr; }