programming style and format updates

This commit is contained in:
Axel Kohlmeyer
2022-04-12 22:52:07 -04:00
parent 467cae9436
commit ef4e41d2a2
28 changed files with 580 additions and 787 deletions

View File

@ -13,7 +13,7 @@
#ifdef ATOM_CLASS
// clang-format off
AtomStyle(bpm/sphere,AtomVecBPMSphere)
AtomStyle(bpm/sphere,AtomVecBPMSphere);
// clang-format on
#else
@ -39,13 +39,12 @@ class AtomVecBPMSphere : public AtomVec {
void pack_data_pre(int) override;
void pack_data_post(int) override;
private:
int *num_bond;
int **bond_type;
int **nspecial;
double *radius,*rmass;
double *radius, *rmass;
double **omega, **torque, **quat;
int any_bond_negative;
@ -53,7 +52,7 @@ class AtomVecBPMSphere : public AtomVec {
int *bond_negative;
int radvary;
double radius_one,rmass_one;
double radius_one, rmass_one;
};
} // namespace LAMMPS_NS

View File

@ -67,7 +67,7 @@ BondBPM::BondBPM(LAMMPS *lmp) : Bond(lmp)
BondBPM::~BondBPM()
{
delete [] pack_choice;
delete[] pack_choice;
if (id_fix_dummy) modify->delete_fix(id_fix_dummy);
if (id_fix_dummy2) modify->delete_fix(id_fix_dummy2);
@ -76,12 +76,12 @@ BondBPM::~BondBPM()
if (id_fix_store_local) modify->delete_fix(id_fix_store_local);
if (id_fix_prop_atom) modify->delete_fix(id_fix_prop_atom);
delete [] id_fix_dummy;
delete [] id_fix_dummy2;
delete [] id_fix_update;
delete [] id_fix_bond_history;
delete [] id_fix_store_local;
delete [] id_fix_prop_atom;
delete[] id_fix_dummy;
delete[] id_fix_dummy2;
delete[] id_fix_update;
delete[] id_fix_bond_history;
delete[] id_fix_store_local;
delete[] id_fix_prop_atom;
memory->destroy(output_data);
}
@ -90,13 +90,12 @@ BondBPM::~BondBPM()
void BondBPM::init_style()
{
int ifix;
if (id_fix_store_local) {
ifix = modify->find_fix(id_fix_store_local);
if (ifix < 0) error->all(FLERR, "Cannot find fix store/local");
if (strcmp(modify->fix[ifix]->style, "STORE_LOCAL") != 0)
auto ifix = modify->get_fix_by_id(id_fix_store_local);
if (!ifix) error->all(FLERR, "Cannot find fix store/local");
if (strcmp(ifix->style, "STORE_LOCAL") != 0)
error->all(FLERR, "Incorrect fix style matched, not store/local");
fix_store_local = (FixStoreLocal *) modify->fix[ifix];
fix_store_local = dynamic_cast<FixStoreLocal *>(ifix);
fix_store_local->nvalues = nvalues;
}
@ -107,7 +106,7 @@ void BondBPM::init_style()
"require special_bonds weight of 1.0 for first neighbors");
if (id_fix_update) {
modify->delete_fix(id_fix_update);
delete [] id_fix_update;
delete[] id_fix_update;
id_fix_update = nullptr;
}
} else {
@ -127,19 +126,17 @@ void BondBPM::init_style()
if (id_fix_dummy) {
id_fix_update = utils::strdup("BPM_UPDATE_SPECIAL_BONDS");
fix_update_special_bonds = (FixUpdateSpecialBonds *) modify->replace_fix(id_fix_dummy,
fmt::format("{} all UPDATE_SPECIAL_BONDS", id_fix_update),1);
delete [] id_fix_dummy;
fix_update_special_bonds = dynamic_cast<FixUpdateSpecialBonds *>(modify->replace_fix(
id_fix_dummy,fmt::format("{} all UPDATE_SPECIAL_BONDS", id_fix_update),1));
delete[] id_fix_dummy;
id_fix_dummy = nullptr;
}
}
if (force->angle || force->dihedral || force->improper)
error->all(FLERR,
"Bond style bpm cannot be used with 3,4-body interactions");
error->all(FLERR,"Bond style bpm cannot be used with 3,4-body interactions");
if (atom->molecular == 2)
error->all(FLERR,
"Bond style bpm cannot be used with atom style template");
error->all(FLERR,"Bond style bpm cannot be used with atom style template");
// special 1-3 and 1-4 weights must be 1 to prevent building 1-3 and 1-4 special bond lists
if (force->special_lj[2] != 1.0 || force->special_lj[3] != 1.0 ||
@ -205,17 +202,15 @@ void BondBPM::settings(int narg, char **arg)
if (id_fix_store_local) {
if (nvalues == 0) error->all(FLERR,
"Storing local data must include at least one value to output");
if (nvalues == 0)
error->all(FLERR, "Storing local data must include at least one value to output");
memory->create(output_data, nvalues, "bond/bpm:output_data");
int ifix = modify->find_fix(id_fix_store_local);
if (ifix < 0) {
modify->add_fix(fmt::format("{} all STORE_LOCAL {} {}",
id_fix_store_local, store_local_freq, nvalues));
ifix = modify->find_fix(id_fix_store_local);
}
fix_store_local = (FixStoreLocal *) modify->fix[ifix];
auto ifix = modify->get_fix_by_id(id_fix_store_local);
if (!ifix)
ifix = modify->add_fix(fmt::format("{} all STORE_LOCAL {} {}",
id_fix_store_local, store_local_freq, nvalues));
fix_store_local = dynamic_cast<FixStoreLocal *>(ifix);
// Use property/atom to save reference positions as it can transfer to ghost atoms
// This won't work for instances where bonds are added (e.g. fix pour) but in those cases
@ -227,12 +222,10 @@ void BondBPM::settings(int narg, char **arg)
char *y_ref_id = utils::strdup("BPM_Y_REF");
char *z_ref_id = utils::strdup("BPM_Z_REF");
ifix = modify->find_fix(id_fix_prop_atom);
if (ifix < 0) {
modify->add_fix(fmt::format("{} all property/atom {} {} {} ghost yes",
id_fix_prop_atom, x_ref_id, y_ref_id, z_ref_id));
ifix = modify->find_fix(id_fix_prop_atom);
}
ifix = modify->get_fix_by_id(id_fix_prop_atom);
if (!ifix)
ifix = modify->add_fix(fmt::format("{} all property/atom {} {} {} ghost yes",
id_fix_prop_atom, x_ref_id, y_ref_id, z_ref_id));
int type_flag;
int col_flag;
@ -240,12 +233,12 @@ void BondBPM::settings(int narg, char **arg)
index_y_ref = atom->find_custom(y_ref_id, type_flag, col_flag);
index_z_ref = atom->find_custom(z_ref_id, type_flag, col_flag);
delete [] x_ref_id;
delete [] y_ref_id;
delete [] z_ref_id;
delete[] x_ref_id;
delete[] y_ref_id;
delete[] z_ref_id;
if (modify->fix[ifix]->restart_reset) {
modify->fix[ifix]->restart_reset = 0;
if (ifix->restart_reset) {
ifix->restart_reset = 0;
} else {
double *x_ref = atom->dvector[index_x_ref];
double *y_ref = atom->dvector[index_y_ref];
@ -266,7 +259,7 @@ void BondBPM::settings(int narg, char **arg)
used to check bond communiction cutoff - not perfect, estimates based on local-local only
------------------------------------------------------------------------- */
double BondBPM::equilibrium_distance(int i)
double BondBPM::equilibrium_distance(int /*i*/)
{
// Ghost atoms may not yet be communicated, this may only be an estimate
if (r0_max_estimate == 0) {
@ -363,7 +356,7 @@ void BondBPM::process_broken(int i, int j)
the atom property is packed into array or vector
------------------------------------------------------------------------- */
void BondBPM::pack_id1(int n, int i, int j)
void BondBPM::pack_id1(int n, int i, int /*j*/)
{
tagint *tag = atom->tag;
output_data[n] = tag[i];
@ -371,7 +364,7 @@ void BondBPM::pack_id1(int n, int i, int j)
/* ---------------------------------------------------------------------- */
void BondBPM::pack_id2(int n, int i, int j)
void BondBPM::pack_id2(int n, int /*i*/, int j)
{
tagint *tag = atom->tag;
output_data[n] = tag[j];
@ -379,7 +372,7 @@ void BondBPM::pack_id2(int n, int i, int j)
/* ---------------------------------------------------------------------- */
void BondBPM::pack_time(int n, int i, int j)
void BondBPM::pack_time(int n, int /*i*/, int /*j*/)
{
bigint time = update->ntimestep;
output_data[n] = time;

View File

@ -23,10 +23,10 @@ namespace LAMMPS_NS {
class BondBPM : public Bond {
public:
BondBPM(class LAMMPS *);
virtual ~BondBPM() override;
virtual void compute(int, int) override = 0;
virtual void coeff(int, char **) override = 0;
virtual void init_style() override;
~BondBPM() override;
void compute(int, int) override = 0;
void coeff(int, char **) override = 0;
void init_style() override;
void settings(int, char **) override;
double equilibrium_distance(int) override;
void write_restart(FILE *) override {};

View File

@ -89,7 +89,6 @@ double BondBPMRotational::acos_limit(double c)
double BondBPMRotational::store_bond(int n,int i,int j)
{
int m,k;
double delx, dely, delz, r, rinv;
double **x = atom->x;
tagint *tag = atom->tag;
@ -114,7 +113,7 @@ double BondBPMRotational::store_bond(int n,int i,int j)
bondstore[n][3] = delz*rinv;
if (i < atom->nlocal) {
for (m = 0; m < atom->num_bond[i]; m ++) {
for (int m = 0; m < atom->num_bond[i]; m ++) {
if (atom->bond_atom[i][m] == tag[j]) {
fix_bond_history->update_atom_value(i, m, 0, r);
fix_bond_history->update_atom_value(i, m, 1, delx*rinv);
@ -125,7 +124,7 @@ double BondBPMRotational::store_bond(int n,int i,int j)
}
if (j < atom->nlocal) {
for (m = 0; m < atom->num_bond[j]; m ++) {
for (int m = 0; m < atom->num_bond[j]; m ++) {
if (atom->bond_atom[j][m] == tag[i]) {
fix_bond_history->update_atom_value(j, m, 0, r);
fix_bond_history->update_atom_value(j, m, 1, delx*rinv);
@ -193,11 +192,11 @@ void BondBPMRotational::store_data()
2) P. Mora & Y. Wang Advances in Geomcomputing 2009
---------------------------------------------------------------------- */
double BondBPMRotational::elastic_forces(int i1, int i2, int type, double& Fr,
double r_mag, double r0_mag, double r_mag_inv, double* rhat, double* r,
double* r0, double* force1on2, double* torque1on2, double* torque2on1)
double BondBPMRotational::elastic_forces(int i1, int i2, int type, double &Fr, double r_mag,
double r0_mag, double r_mag_inv, double * /*rhat*/,
double *r, double *r0, double *force1on2,
double *torque1on2, double *torque2on1)
{
int m;
double breaking, temp, r0_dot_rb, c, gamma;
double psi, theta, cos_phi, sin_phi;
double mag_in_plane, mag_out_plane;
@ -336,7 +335,7 @@ double BondBPMRotational::elastic_forces(int i1, int i2, int type, double& Fr,
MathExtra::quatrotvec(mq, Fsp, Ftmp);
MathExtra::quatrotvec(mq, Tsp, Ttmp);
for (m = 0; m < 3; m++) {
for (int m = 0; m < 3; m++) {
Fs[m] += Ftmp[m];
Ts[m] += Ttmp[m];
}
@ -462,7 +461,7 @@ void BondBPMRotational::compute(int eflag, int vflag)
int i1,i2,itmp,n,type;
double r[3], r0[3], rhat[3];
double delx, dely, delz, rsq, r0_mag, r_mag, r_mag_inv;
double rsq, r0_mag, r_mag, r_mag_inv;
double Fr, breaking, smooth;
double force1on2[3], torque1on2[3], torque2on1[3];
@ -471,7 +470,6 @@ void BondBPMRotational::compute(int eflag, int vflag)
double **x = atom->x;
double **f = atom->f;
double **torque = atom->torque;
double *radius = atom->radius;
tagint *tag = atom->tag;
int **bondlist = neighbor->bondlist;
int nbondlist = neighbor->nbondlist;
@ -657,9 +655,9 @@ void BondBPMRotational::init_style()
if (!id_fix_bond_history) {
id_fix_bond_history = utils::strdup("HISTORY_BPM_ROTATIONAL");
fix_bond_history = (FixBondHistory *) modify->replace_fix(id_fix_dummy2,
fmt::format("{} all BOND_HISTORY 0 4", id_fix_bond_history),1);
delete [] id_fix_dummy2;
fix_bond_history = dynamic_cast<FixBondHistory *>(modify->replace_fix(id_fix_dummy2,
fmt::format("{} all BOND_HISTORY 0 4", id_fix_bond_history),1));
delete[] id_fix_dummy2;
id_fix_dummy2 = nullptr;
}
}
@ -671,7 +669,7 @@ void BondBPMRotational::settings(int narg, char **arg)
BondBPM::settings(narg, arg);
int iarg;
for (int i = 0; i < leftover_iarg.size(); i++) {
for (std::size_t i = 0; i < leftover_iarg.size(); i++) {
iarg = leftover_iarg[i];
if (strcmp(arg[iarg], "smooth") == 0) {
if (iarg+1 > narg) error->all(FLERR,"Illegal bond bpm command");

View File

@ -13,7 +13,7 @@
#ifdef BOND_CLASS
// clang-format off
BondStyle(bpm/rotational,BondBPMRotational)
BondStyle(bpm/rotational,BondBPMRotational);
// clang-format on
#else
@ -27,8 +27,8 @@ namespace LAMMPS_NS {
class BondBPMRotational : public BondBPM {
public:
BondBPMRotational(class LAMMPS *);
virtual ~BondBPMRotational() override;
virtual void compute(int, int) override;
~BondBPMRotational() override;
void compute(int, int) override;
void coeff(int, char **) override;
void init_style() override;
void settings(int, char **) override;
@ -44,10 +44,9 @@ class BondBPMRotational : public BondBPM {
double acos_limit(double);
double elastic_forces(int, int, int, double &, double, double, double,
double*, double*, double*, double*, double*, double*);
void damping_forces(int, int, int, double &, double*, double*, double*,
double*, double*);
double elastic_forces(int, int, int, double &, double, double, double, double *, double *,
double *, double *, double *, double *);
void damping_forces(int, int, int, double &, double *, double *, double *, double *, double *);
void allocate();
void store_data();

View File

@ -57,7 +57,6 @@ BondBPMSpring::~BondBPMSpring()
double BondBPMSpring::store_bond(int n,int i,int j)
{
int m,k;
double delx, dely, delz, r;
double **x = atom->x;
double **bondstore = fix_bond_history->bondstore;
@ -71,7 +70,7 @@ double BondBPMSpring::store_bond(int n,int i,int j)
bondstore[n][0] = r;
if (i < atom->nlocal) {
for (m = 0; m < atom->num_bond[i]; m ++) {
for (int m = 0; m < atom->num_bond[i]; m ++) {
if (atom->bond_atom[i][m] == tag[j]) {
fix_bond_history->update_atom_value(i, m, 0, r);
}
@ -79,7 +78,7 @@ double BondBPMSpring::store_bond(int n,int i,int j)
}
if (j < atom->nlocal) {
for (m = 0; m < atom->num_bond[j]; m ++) {
for (int m = 0; m < atom->num_bond[j]; m ++) {
if (atom->bond_atom[j][m] == tag[i]) {
fix_bond_history->update_atom_value(j, m, 0, r);
}
@ -136,7 +135,7 @@ void BondBPMSpring::compute(int eflag, int vflag)
store_data();
}
int i1,i2,itmp,m,n,type,itype,jtype;
int i1,i2,itmp,n,type;
double delx, dely, delz, delvx, delvy, delvz;
double e, rsq, r, r0, rinv, smooth, fbond, dot;
@ -283,9 +282,9 @@ void BondBPMSpring::init_style()
if (!id_fix_bond_history) {
id_fix_bond_history = utils::strdup("HISTORY_BPM_SPRING");
fix_bond_history = (FixBondHistory *) modify->replace_fix(id_fix_dummy2,
fmt::format("{} all BOND_HISTORY 0 1", id_fix_bond_history),1);
delete [] id_fix_dummy2;
fix_bond_history = dynamic_cast<FixBondHistory *>(modify->replace_fix(id_fix_dummy2,
fmt::format("{} all BOND_HISTORY 0 1", id_fix_bond_history),1));
delete[] id_fix_dummy2;
id_fix_dummy2 = nullptr;
}
}
@ -297,7 +296,7 @@ void BondBPMSpring::settings(int narg, char **arg)
BondBPM::settings(narg, arg);
int iarg;
for (int i = 0; i < leftover_iarg.size(); i++) {
for (std::size_t i = 0; i < leftover_iarg.size(); i++) {
iarg = leftover_iarg[i];
if (strcmp(arg[iarg], "smooth") == 0) {
if (iarg+1 > narg) error->all(FLERR,"Illegal bond bpm command");
@ -366,7 +365,6 @@ double BondBPMSpring::single(int type, double rsq, int i, int j,
double r = sqrt(rsq);
double rinv = 1.0/r;
double e = (r - r0)/r0;
fforce = k[type]*(r0-r);
double **x = atom->x;

View File

@ -13,7 +13,7 @@
#ifdef BOND_CLASS
// clang-format off
BondStyle(bpm/spring,BondBPMSpring)
BondStyle(bpm/spring,BondBPMSpring);
// clang-format on
#else
@ -27,8 +27,8 @@ namespace LAMMPS_NS {
class BondBPMSpring : public BondBPM {
public:
BondBPMSpring(class LAMMPS *);
virtual ~BondBPMSpring() override;
virtual void compute(int, int) override;
~BondBPMSpring() override;
void compute(int, int) override;
void coeff(int, char **) override;
void init_style() override;
void settings(int, char **) override;

View File

@ -13,7 +13,7 @@
#ifdef COMPUTE_CLASS
// clang-format off
ComputeStyle(nbond/atom,ComputeNBondAtom)
ComputeStyle(nbond/atom,ComputeNBondAtom);
// clang-format on
#else

View File

@ -13,7 +13,7 @@
#ifdef FIX_CLASS
// clang-format off
FixStyle(nve/bpm/sphere,FixNVEBPMSphere)
FixStyle(nve/bpm/sphere,FixNVEBPMSphere);
// clang-format on
#else

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -19,8 +18,8 @@
#include "error.h"
#include "force.h"
#include "memory.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "neighbor.h"
using namespace LAMMPS_NS;
@ -49,26 +48,22 @@ PairBPMSpring::~PairBPMSpring()
void PairBPMSpring::compute(int eflag, int vflag)
{
int i,j,m,ii,jj,inum,jnum,itype,jtype;
tagint tagi, tagj;
int bond_flag;
double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair;
double r,rsq,rinv,r2inv,factor_lj;
int *ilist,*jlist,*numneigh,**firstneigh;
double vxtmp,vytmp,vztmp,delvx,delvy,delvz,dot,smooth;
int i, j, ii, jj, inum, jnum, itype, jtype;
double xtmp, ytmp, ztmp, delx, dely, delz, evdwl, fpair;
double r, rsq, rinv, factor_lj;
int *ilist, *jlist, *numneigh, **firstneigh;
double vxtmp, vytmp, vztmp, delvx, delvy, delvz, dot, smooth;
evdwl = 0.0;
if (eflag || vflag) ev_setup(eflag,vflag);
else evflag = vflag_fdotr = 0;
if (eflag || vflag)
ev_setup(eflag, vflag);
else
evflag = vflag_fdotr = 0;
tagint *tag = atom->tag;
double **x = atom->x;
double **v = atom->v;
double **f = atom->f;
int *type = atom->type;
int **bond_type = atom->bond_type;
int *num_bond = atom->num_bond;
tagint **bond_atom = atom->bond_atom;
int nlocal = atom->nlocal;
int newton_pair = force->newton_pair;
double *special_lj = force->special_lj;
@ -82,7 +77,6 @@ void PairBPMSpring::compute(int eflag, int vflag)
for (ii = 0; ii < inum; ii++) {
i = ilist[ii];
tagi = tag[i];
xtmp = x[i][0];
ytmp = x[i][1];
ztmp = x[i][2];
@ -104,40 +98,39 @@ void PairBPMSpring::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]) {
r = sqrt(rsq);
rinv = 1.0/r;
fpair = k[itype][jtype]*(cut[itype][jtype]-r);
rinv = 1.0 / r;
fpair = k[itype][jtype] * (cut[itype][jtype] - r);
smooth = rsq/cutsq[itype][jtype];
smooth = rsq / cutsq[itype][jtype];
smooth *= smooth;
smooth *= smooth;
smooth = 1.0 - smooth;
delvx = vxtmp - v[j][0];
delvy = vytmp - v[j][1];
delvz = vztmp - v[j][2];
dot = delx*delvx + dely*delvy + delz*delvz;
fpair -= gamma[itype][jtype]*dot*smooth*rinv;
dot = delx * delvx + dely * delvy + delz * delvz;
fpair -= gamma[itype][jtype] * dot * smooth * rinv;
fpair *= factor_lj*rinv;
fpair *= factor_lj * rinv;
if (eflag) evdwl = 0.0;
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 (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);
}
}
}
@ -152,27 +145,26 @@ void PairBPMSpring::compute(int eflag, int vflag)
void PairBPMSpring::allocate()
{
allocated = 1;
int n = atom->ntypes;
const int np1 = 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(setflag, np1, np1, "pair:setflag");
for (int i = 1; i < np1; i++)
for (int j = i; j < np1; j++) setflag[i][j] = 0;
memory->create(cutsq,n+1,n+1,"pair:cutsq");
memory->create(cutsq, np1, np1, "pair:cutsq");
memory->create(k,n+1,n+1,"pair:k");
memory->create(cut,n+1,n+1,"pair:cut");
memory->create(gamma,n+1,n+1,"pair:gamma");
memory->create(k, np1, np1, "pair:k");
memory->create(cut, np1, np1, "pair:cut");
memory->create(gamma, np1, np1, "pair:gamma");
}
/* ----------------------------------------------------------------------
global settings
------------------------------------------------------------------------- */
void PairBPMSpring::settings(int narg, char **arg)
void PairBPMSpring::settings(int narg, char ** /*arg*/)
{
if (narg != 0) error->all(FLERR,"Illegal pair_style command");
if (narg != 0) error->all(FLERR, "Illegal pair_style command");
}
/* ----------------------------------------------------------------------
@ -181,23 +173,22 @@ void PairBPMSpring::settings(int narg, char **arg)
void PairBPMSpring::coeff(int narg, char **arg)
{
if (narg != 5)
error->all(FLERR,"Incorrect args for pair coefficients");
if (narg != 5) 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);
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 k_one = utils::numeric(FLERR,arg[2],false,lmp);
double cut_one = utils::numeric(FLERR,arg[3],false,lmp);
double gamma_one = utils::numeric(FLERR,arg[4],false,lmp);
double k_one = utils::numeric(FLERR, arg[2], false, lmp);
double cut_one = utils::numeric(FLERR, arg[3], false, lmp);
double gamma_one = utils::numeric(FLERR, arg[4], false, lmp);
if (cut_one <= 0.0) error->all(FLERR,"Incorrect args for pair coefficients");
if (cut_one <= 0.0) error->all(FLERR, "Incorrect args for pair coefficients");
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++) {
k[i][j] = k_one;
cut[i][j] = cut_one;
gamma[i][j] = gamma_one;
@ -207,7 +198,7 @@ void PairBPMSpring::coeff(int narg, char **arg)
}
}
if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients");
if (count == 0) error->all(FLERR, "Incorrect args for pair coefficients");
}
/* ----------------------------------------------------------------------
@ -217,11 +208,9 @@ void PairBPMSpring::coeff(int narg, char **arg)
double PairBPMSpring::init_one(int i, int j)
{
if (setflag[i][j] == 0) {
cut[i][j] = mix_distance(cut[i][i],cut[j][j]);
k[i][j] = mix_energy(k[i][i],k[j][j],
cut[i][i],cut[j][j]);
gamma[i][j] = mix_energy(gamma[i][i],gamma[j][j],
cut[i][i],cut[j][j]);
cut[i][j] = mix_distance(cut[i][i], cut[j][j]);
k[i][j] = mix_energy(k[i][i], k[j][j], cut[i][i], cut[j][j]);
gamma[i][j] = mix_energy(gamma[i][i], gamma[j][j], cut[i][i], cut[j][j]);
}
cut[j][i] = cut[i][j];
@ -239,14 +228,14 @@ void PairBPMSpring::write_restart(FILE *fp)
{
write_restart_settings(fp);
int i,j;
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);
fwrite(&setflag[i][j], sizeof(int), 1, fp);
if (setflag[i][j]) {
fwrite(&k[i][j],sizeof(double),1,fp);
fwrite(&cut[i][j],sizeof(double),1,fp);
fwrite(&gamma[i][j],sizeof(double),1,fp);
fwrite(&k[i][j], sizeof(double), 1, fp);
fwrite(&cut[i][j], sizeof(double), 1, fp);
fwrite(&gamma[i][j], sizeof(double), 1, fp);
}
}
}
@ -260,21 +249,21 @@ void PairBPMSpring::read_restart(FILE *fp)
read_restart_settings(fp);
allocate();
int i,j;
int i, j;
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
if (me == 0) fread(&setflag[i][j], sizeof(int), 1, fp);
MPI_Bcast(&setflag[i][j], 1, MPI_INT, 0, world);
if (setflag[i][j]) {
if (me == 0) {
fread(&k[i][j],sizeof(double),1,fp);
fread(&cut[i][j],sizeof(double),1,fp);
fread(&gamma[i][j],sizeof(double),1,fp);
fread(&k[i][j], sizeof(double), 1, fp);
fread(&cut[i][j], sizeof(double), 1, fp);
fread(&gamma[i][j], sizeof(double), 1, fp);
}
MPI_Bcast(&k[i][j],1,MPI_DOUBLE,0,world);
MPI_Bcast(&cut[i][j],1,MPI_DOUBLE,0,world);
MPI_Bcast(&gamma[i][j],1,MPI_DOUBLE,0,world);
MPI_Bcast(&k[i][j], 1, MPI_DOUBLE, 0, world);
MPI_Bcast(&cut[i][j], 1, MPI_DOUBLE, 0, world);
MPI_Bcast(&gamma[i][j], 1, MPI_DOUBLE, 0, world);
}
}
}
@ -286,7 +275,7 @@ void PairBPMSpring::read_restart(FILE *fp)
void PairBPMSpring::write_data(FILE *fp)
{
for (int i = 1; i <= atom->ntypes; i++)
fprintf(fp,"%d %g %g %g\n",i,k[i][i],cut[i][i],gamma[i][i]);
fprintf(fp, "%d %g %g %g\n", i, k[i][i], cut[i][i], gamma[i][i]);
}
/* ----------------------------------------------------------------------
@ -297,30 +286,28 @@ void PairBPMSpring::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\n",i,j,
k[i][j],cut[i][j],gamma[i][j]);
fprintf(fp, "%d %d %g %g %g\n", i, j, k[i][j], cut[i][j], gamma[i][j]);
}
/* ---------------------------------------------------------------------- */
double PairBPMSpring::single(int i, int j, int itype, int jtype, double rsq,
double factor_coul, double factor_lj,
double &fforce)
double PairBPMSpring::single(int i, int j, int itype, int jtype, double rsq, double /*factor_coul*/,
double factor_lj, double &fforce)
{
double fpair,r,rinv;
double fpair, r, rinv;
double delx, dely, delz, delvx, delvy, delvz, dot, smooth;
if(rsq > cutsq[itype][jtype]) return 0.0;
if (rsq > cutsq[itype][jtype]) return 0.0;
double **x = atom->x;
double **v = atom->v;
r = sqrt(rsq);
rinv = 1.0/r;
rinv = 1.0 / r;
fpair = k[itype][jtype]*(cut[itype][jtype]-r);
fpair = k[itype][jtype] * (cut[itype][jtype] - r);
smooth = rsq/cutsq[itype][jtype];
smooth = rsq / cutsq[itype][jtype];
smooth *= smooth;
smooth = 1.0 - smooth;
delx = x[i][0] - x[j][0];
@ -329,8 +316,8 @@ double PairBPMSpring::single(int i, int j, int itype, int jtype, double rsq,
delvx = v[i][0] - v[j][0];
delvy = v[i][1] - v[j][1];
delvz = v[i][2] - v[j][2];
dot = delx*delvx + dely*delvy + delz*delvz;
fpair -= gamma[itype][jtype]*dot*rinv*smooth;
dot = delx * delvx + dely * delvy + delz * delvz;
fpair -= gamma[itype][jtype] * dot * rinv * smooth;
fpair *= factor_lj;
fforce = fpair;

View File

@ -13,7 +13,7 @@
#ifdef PAIR_CLASS
// clang-format off
PairStyle(bpm/spring,PairBPMSpring)
PairStyle(bpm/spring,PairBPMSpring);
// clang-format on
#else
@ -27,8 +27,8 @@ namespace LAMMPS_NS {
class PairBPMSpring : public Pair {
public:
PairBPMSpring(class LAMMPS *);
virtual ~PairBPMSpring() override;
virtual void compute(int, int) override;
~PairBPMSpring() override;
void compute(int, int) override;
void settings(int, char **) override;
void coeff(int, char **) override;
double init_one(int, int) override;
@ -39,12 +39,12 @@ class PairBPMSpring : public Pair {
double single(int, int, int, int, double, double, double, double &) override;
protected:
double **k,**cut,**gamma;
double **k, **cut, **gamma;
void allocate();
};
}
} // namespace LAMMPS_NS
#endif
#endif

View File

@ -301,11 +301,11 @@ void FixBondBreak::post_integrate()
bond_type[i][k] = bond_type[i][k+1];
if (n_histories > 0)
for (auto &ihistory: histories)
((FixBondHistory *) ihistory)->shift_history(i,k,k+1);
dynamic_cast<FixBondHistory *>(ihistory)->shift_history(i,k,k+1);
}
if (n_histories > 0)
for (auto &ihistory: histories)
((FixBondHistory *) ihistory)->delete_history(i,num_bond[i]-1);
dynamic_cast<FixBondHistory *>(ihistory)->delete_history(i,num_bond[i]-1);
num_bond[i]--;
break;
}

View File

@ -17,21 +17,15 @@
------------------------------------------------------------------------- */
#include "fix_bond_create_angle.h"
#include "atom.h"
#include <cmath>
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
FixBondCreateAngle::FixBondCreateAngle(LAMMPS *lmp, int narg, char **arg) :
FixBondCreate(lmp, narg, arg)
{
}
/* ---------------------------------------------------------------------- */
int FixBondCreateAngle::constrain(int i, int j, double amin, double amax)
{
double **x = atom->x;

View File

@ -26,7 +26,7 @@ namespace LAMMPS_NS {
class FixBondCreateAngle : public FixBondCreate {
public:
FixBondCreateAngle(class LAMMPS *, int, char **);
FixBondCreateAngle(LAMMPS *_lmp, int narg, char **arg) : FixBondCreate(_lmp, narg, arg) {}
private:
int constrain(int, int, double, double) override;

View File

@ -461,28 +461,28 @@ void FixBondSwap::post_integrate()
if (bond_atom[i][ibond] == tag[inext]) {
if (n_histories > 0)
for (auto &ihistory: histories)
((FixBondHistory *) ihistory)->delete_history(i,ibond);
dynamic_cast<FixBondHistory *>(ihistory)->delete_history(i,ibond);
bond_atom[i][ibond] = tag[jnext];
}
for (jbond = 0; jbond < num_bond[j]; jbond++)
if (bond_atom[j][jbond] == tag[jnext]) {
if (n_histories > 0)
for (auto &ihistory: histories)
((FixBondHistory *) ihistory)->delete_history(j,jbond);
dynamic_cast<FixBondHistory *>(ihistory)->delete_history(j,jbond);
bond_atom[j][jbond] = tag[inext];
}
for (ibond = 0; ibond < num_bond[inext]; ibond++)
if (bond_atom[inext][ibond] == tag[i]) {
if (n_histories > 0)
for (auto &ihistory: histories)
((FixBondHistory *) ihistory)->delete_history(inext,ibond);
dynamic_cast<FixBondHistory *>(ihistory)->delete_history(inext,ibond);
bond_atom[inext][ibond] = tag[j];
}
for (jbond = 0; jbond < num_bond[jnext]; jbond++)
if (bond_atom[jnext][jbond] == tag[j]) {
if (n_histories > 0)
for (auto &ihistory: histories)
((FixBondHistory *) ihistory)->delete_history(jnext,jbond);
dynamic_cast<FixBondHistory *>(ihistory)->delete_history(jnext,jbond);
bond_atom[jnext][jbond] = tag[i];
}

View File

@ -3111,9 +3111,9 @@ void FixBondReact::update_everything()
if (n_histories > 0)
for (auto &ihistory: histories) {
for (int n = 0; n < num_bond[atom->map(update_mega_glove[jj+1][i])]; n++)
((FixBondHistory *) ihistory)->cache_history(atom->map(update_mega_glove[jj+1][i]), n);
dynamic_cast<FixBondHistory *>(ihistory)->cache_history(atom->map(update_mega_glove[jj+1][i]), n);
for (int n = 0; n < num_bond[atom->map(update_mega_glove[jj+1][i])]; n++)
((FixBondHistory *) ihistory)->delete_history(atom->map(update_mega_glove[jj+1][i]), 0);
dynamic_cast<FixBondHistory *>(ihistory)->delete_history(atom->map(update_mega_glove[jj+1][i]), 0);
}
num_bond[atom->map(update_mega_glove[jj+1][i])] = 0;
}
@ -3125,17 +3125,17 @@ void FixBondReact::update_everything()
// Cache history information, shift history, then delete final element
if (n_histories > 0)
for (auto &ihistory: histories)
((FixBondHistory *) ihistory)->cache_history(atom->map(update_mega_glove[jj+1][i]), p);
dynamic_cast<FixBondHistory *>(ihistory)->cache_history(atom->map(update_mega_glove[jj+1][i]), p);
for (int m = p; m < num_bond[atom->map(update_mega_glove[jj+1][i])]-1; m++) {
bond_type[atom->map(update_mega_glove[jj+1][i])][m] = bond_type[atom->map(update_mega_glove[jj+1][i])][m+1];
bond_atom[atom->map(update_mega_glove[jj+1][i])][m] = bond_atom[atom->map(update_mega_glove[jj+1][i])][m+1];
if (n_histories > 0)
for (auto &ihistory: histories)
((FixBondHistory *) ihistory)->shift_history(atom->map(update_mega_glove[jj+1][i]),m,m+1);
dynamic_cast<FixBondHistory *>(ihistory)->shift_history(atom->map(update_mega_glove[jj+1][i]),m,m+1);
}
if (n_histories > 0)
for (auto &ihistory: histories)
((FixBondHistory *) ihistory)->delete_history(atom->map(update_mega_glove[jj+1][i]),
dynamic_cast<FixBondHistory *>(ihistory)->delete_history(atom->map(update_mega_glove[jj+1][i]),
num_bond[atom->map(update_mega_glove[jj+1][i])]-1);
num_bond[atom->map(update_mega_glove[jj+1][i])]--;
delta_bonds--;
@ -3158,7 +3158,7 @@ void FixBondReact::update_everything()
// Check cached history data to see if bond regenerated
if (n_histories > 0)
for (auto &ihistory: histories)
((FixBondHistory *) ihistory)->check_cache(atom->map(update_mega_glove[jj+1][i]), p);
dynamic_cast<FixBondHistory *>(ihistory)->check_cache(atom->map(update_mega_glove[jj+1][i]), p);
}
}
if (landlocked_atoms[j][rxnID] == 0) {
@ -3170,7 +3170,7 @@ void FixBondReact::update_everything()
// Check cached history data to see if bond regenerated
if (n_histories > 0)
for (auto &ihistory: histories)
((FixBondHistory *) ihistory)->check_cache(atom->map(update_mega_glove[jj+1][i]), insert_num);
dynamic_cast<FixBondHistory *>(ihistory)->check_cache(atom->map(update_mega_glove[jj+1][i]), insert_num);
num_bond[atom->map(update_mega_glove[jj+1][i])]++;
if (num_bond[atom->map(update_mega_glove[jj+1][i])] > atom->bond_per_atom)
error->one(FLERR,"Bond/react topology/atom exceed system topology/atom");
@ -3184,7 +3184,7 @@ void FixBondReact::update_everything()
if (n_histories > 0)
for (auto &ihistory: histories)
((FixBondHistory *) ihistory)->clear_cache();
dynamic_cast<FixBondHistory *>(ihistory)->clear_cache();
// Angles! First let's delete all angle info:
if (force->angle && twomol->angleflag) {

View File

@ -427,6 +427,8 @@ void Atom::peratom_create()
add_peratom("tri",&tri,INT,0);
add_peratom("body",&body,INT,0);
// BPM package
add_peratom("quat",&quat,DOUBLE,4);
// MOLECULE package

View File

@ -491,8 +491,7 @@ void CommBrick::setup()
return how many procs away are needed to encompass cutghost away from loc
------------------------------------------------------------------------- */
int CommBrick::updown(int dim, int dir, int loc,
double prd, int periodicity, double *split)
int CommBrick::updown(int dim, int dir, int loc, double prd, int periodicity, double *split)
{
int index,count;
double frac,delta;
@ -553,19 +552,15 @@ void CommBrick::forward_comm(int /*dummy*/)
if (comm_x_only) {
if (size_forward_recv[iswap]) {
buf = x[firstrecv[iswap]];
MPI_Irecv(buf,size_forward_recv[iswap],MPI_DOUBLE,
recvproc[iswap],0,world,&request);
MPI_Irecv(buf,size_forward_recv[iswap],MPI_DOUBLE,recvproc[iswap],0,world,&request);
}
n = avec->pack_comm(sendnum[iswap],sendlist[iswap],
buf_send,pbc_flag[iswap],pbc[iswap]);
n = avec->pack_comm(sendnum[iswap],sendlist[iswap],buf_send,pbc_flag[iswap],pbc[iswap]);
if (n) MPI_Send(buf_send,n,MPI_DOUBLE,sendproc[iswap],0,world);
if (size_forward_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
} else if (ghost_velocity) {
if (size_forward_recv[iswap])
MPI_Irecv(buf_recv,size_forward_recv[iswap],MPI_DOUBLE,
recvproc[iswap],0,world,&request);
n = avec->pack_comm_vel(sendnum[iswap],sendlist[iswap],
buf_send,pbc_flag[iswap],pbc[iswap]);
MPI_Irecv(buf_recv,size_forward_recv[iswap],MPI_DOUBLE,recvproc[iswap],0,world,&request);
n = avec->pack_comm_vel(sendnum[iswap],sendlist[iswap],buf_send,pbc_flag[iswap],pbc[iswap]);
if (n) MPI_Send(buf_send,n,MPI_DOUBLE,sendproc[iswap],0,world);
if (size_forward_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
avec->unpack_comm_vel(recvnum[iswap],firstrecv[iswap],buf_recv);
@ -573,8 +568,7 @@ void CommBrick::forward_comm(int /*dummy*/)
if (size_forward_recv[iswap])
MPI_Irecv(buf_recv,size_forward_recv[iswap],MPI_DOUBLE,
recvproc[iswap],0,world,&request);
n = avec->pack_comm(sendnum[iswap],sendlist[iswap],
buf_send,pbc_flag[iswap],pbc[iswap]);
n = avec->pack_comm(sendnum[iswap],sendlist[iswap],buf_send,pbc_flag[iswap],pbc[iswap]);
if (n) MPI_Send(buf_send,n,MPI_DOUBLE,sendproc[iswap],0,world);
if (size_forward_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
avec->unpack_comm(recvnum[iswap],firstrecv[iswap],buf_recv);
@ -586,12 +580,10 @@ void CommBrick::forward_comm(int /*dummy*/)
avec->pack_comm(sendnum[iswap],sendlist[iswap],
x[firstrecv[iswap]],pbc_flag[iswap],pbc[iswap]);
} else if (ghost_velocity) {
avec->pack_comm_vel(sendnum[iswap],sendlist[iswap],
buf_send,pbc_flag[iswap],pbc[iswap]);
avec->pack_comm_vel(sendnum[iswap],sendlist[iswap],buf_send,pbc_flag[iswap],pbc[iswap]);
avec->unpack_comm_vel(recvnum[iswap],firstrecv[iswap],buf_send);
} else {
avec->pack_comm(sendnum[iswap],sendlist[iswap],
buf_send,pbc_flag[iswap],pbc[iswap]);
avec->pack_comm(sendnum[iswap],sendlist[iswap],buf_send,pbc_flag[iswap],pbc[iswap]);
avec->unpack_comm(recvnum[iswap],firstrecv[iswap],buf_send);
}
}
@ -619,18 +611,15 @@ void CommBrick::reverse_comm()
if (sendproc[iswap] != me) {
if (comm_f_only) {
if (size_reverse_recv[iswap])
MPI_Irecv(buf_recv,size_reverse_recv[iswap],MPI_DOUBLE,
sendproc[iswap],0,world,&request);
MPI_Irecv(buf_recv,size_reverse_recv[iswap],MPI_DOUBLE,sendproc[iswap],0,world,&request);
if (size_reverse_send[iswap]) {
buf = f[firstrecv[iswap]];
MPI_Send(buf,size_reverse_send[iswap],MPI_DOUBLE,
recvproc[iswap],0,world);
MPI_Send(buf,size_reverse_send[iswap],MPI_DOUBLE,recvproc[iswap],0,world);
}
if (size_reverse_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
} else {
if (size_reverse_recv[iswap])
MPI_Irecv(buf_recv,size_reverse_recv[iswap],MPI_DOUBLE,
sendproc[iswap],0,world,&request);
MPI_Irecv(buf_recv,size_reverse_recv[iswap],MPI_DOUBLE,sendproc[iswap],0,world,&request);
n = avec->pack_reverse(recvnum[iswap],firstrecv[iswap],buf_send);
if (n) MPI_Send(buf_send,n,MPI_DOUBLE,recvproc[iswap],0,world);
if (size_reverse_recv[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
@ -640,8 +629,7 @@ void CommBrick::reverse_comm()
} else {
if (comm_f_only) {
if (sendnum[iswap])
avec->unpack_reverse(sendnum[iswap],sendlist[iswap],
f[firstrecv[iswap]]);
avec->unpack_reverse(sendnum[iswap],sendlist[iswap],f[firstrecv[iswap]]);
} else {
avec->pack_reverse(recvnum[iswap],firstrecv[iswap],buf_send);
avec->unpack_reverse(sendnum[iswap],sendlist[iswap],buf_send);
@ -734,25 +722,21 @@ void CommBrick::exchange()
if (procgrid[dim] == 1) nrecv = 0;
else {
MPI_Sendrecv(&nsend,1,MPI_INT,procneigh[dim][0],0,
&nrecv1,1,MPI_INT,procneigh[dim][1],0,world,
MPI_STATUS_IGNORE);
&nrecv1,1,MPI_INT,procneigh[dim][1],0,world,MPI_STATUS_IGNORE);
nrecv = nrecv1;
if (procgrid[dim] > 2) {
MPI_Sendrecv(&nsend,1,MPI_INT,procneigh[dim][1],0,
&nrecv2,1,MPI_INT,procneigh[dim][0],0,world,
MPI_STATUS_IGNORE);
&nrecv2,1,MPI_INT,procneigh[dim][0],0,world,MPI_STATUS_IGNORE);
nrecv += nrecv2;
}
if (nrecv > maxrecv) grow_recv(nrecv);
MPI_Irecv(buf_recv,nrecv1,MPI_DOUBLE,procneigh[dim][1],0,
world,&request);
MPI_Irecv(buf_recv,nrecv1,MPI_DOUBLE,procneigh[dim][1],0,world,&request);
MPI_Send(buf_send,nsend,MPI_DOUBLE,procneigh[dim][0],0,world);
MPI_Wait(&request,MPI_STATUS_IGNORE);
if (procgrid[dim] > 2) {
MPI_Irecv(&buf_recv[nrecv1],nrecv2,MPI_DOUBLE,procneigh[dim][0],0,
world,&request);
MPI_Irecv(&buf_recv[nrecv1],nrecv2,MPI_DOUBLE,procneigh[dim][0],0,world,&request);
MPI_Send(buf_send,nsend,MPI_DOUBLE,procneigh[dim][1],0,world);
MPI_Wait(&request,MPI_STATUS_IGNORE);
}
@ -926,11 +910,9 @@ void CommBrick::borders()
if (nsend*size_border > maxsend) grow_send(nsend*size_border,0);
if (ghost_velocity)
n = avec->pack_border_vel(nsend,sendlist[iswap],buf_send,
pbc_flag[iswap],pbc[iswap]);
n = avec->pack_border_vel(nsend,sendlist[iswap],buf_send,pbc_flag[iswap],pbc[iswap]);
else
n = avec->pack_border(nsend,sendlist[iswap],buf_send,
pbc_flag[iswap],pbc[iswap]);
n = avec->pack_border(nsend,sendlist[iswap],buf_send,pbc_flag[iswap],pbc[iswap]);
// swap atoms with other proc
// no MPI calls except SendRecv if nsend/nrecv = 0
@ -939,8 +921,7 @@ void CommBrick::borders()
if (sendproc[iswap] != me) {
MPI_Sendrecv(&nsend,1,MPI_INT,sendproc[iswap],0,
&nrecv,1,MPI_INT,recvproc[iswap],0,world,
MPI_STATUS_IGNORE);
&nrecv,1,MPI_INT,recvproc[iswap],0,world,MPI_STATUS_IGNORE);
if (nrecv*size_border > maxrecv) grow_recv(nrecv*size_border);
if (nrecv) MPI_Irecv(buf_recv,nrecv*size_border,MPI_DOUBLE,
recvproc[iswap],0,world,&request);
@ -1014,16 +995,14 @@ void CommBrick::forward_comm(Pair *pair)
// pack buffer
n = pair->pack_forward_comm(sendnum[iswap],sendlist[iswap],
buf_send,pbc_flag[iswap],pbc[iswap]);
n = pair->pack_forward_comm(sendnum[iswap],sendlist[iswap],buf_send,pbc_flag[iswap],pbc[iswap]);
// exchange with another proc
// if self, set recv buffer to send buffer
if (sendproc[iswap] != me) {
if (recvnum[iswap])
MPI_Irecv(buf_recv,nsize*recvnum[iswap],MPI_DOUBLE,
recvproc[iswap],0,world,&request);
MPI_Irecv(buf_recv,nsize*recvnum[iswap],MPI_DOUBLE,recvproc[iswap],0,world,&request);
if (sendnum[iswap])
MPI_Send(buf_send,n,MPI_DOUBLE,sendproc[iswap],0,world);
if (recvnum[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
@ -1060,8 +1039,7 @@ void CommBrick::reverse_comm(Pair *pair)
if (sendproc[iswap] != me) {
if (sendnum[iswap])
MPI_Irecv(buf_recv,nsize*sendnum[iswap],MPI_DOUBLE,sendproc[iswap],0,
world,&request);
MPI_Irecv(buf_recv,nsize*sendnum[iswap],MPI_DOUBLE,sendproc[iswap],0,world,&request);
if (recvnum[iswap])
MPI_Send(buf_send,n,MPI_DOUBLE,recvproc[iswap],0,world);
if (sendnum[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
@ -1091,16 +1069,14 @@ void CommBrick::forward_comm(Bond *bond)
// pack buffer
n = bond->pack_forward_comm(sendnum[iswap],sendlist[iswap],
buf_send,pbc_flag[iswap],pbc[iswap]);
n = bond->pack_forward_comm(sendnum[iswap],sendlist[iswap],buf_send,pbc_flag[iswap],pbc[iswap]);
// exchange with another proc
// if self, set recv buffer to send buffer
if (sendproc[iswap] != me) {
if (recvnum[iswap])
MPI_Irecv(buf_recv,nsize*recvnum[iswap],MPI_DOUBLE,
recvproc[iswap],0,world,&request);
MPI_Irecv(buf_recv,nsize*recvnum[iswap],MPI_DOUBLE,recvproc[iswap],0,world,&request);
if (sendnum[iswap])
MPI_Send(buf_send,n,MPI_DOUBLE,sendproc[iswap],0,world);
if (recvnum[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
@ -1137,8 +1113,7 @@ void CommBrick::reverse_comm(Bond *bond)
if (sendproc[iswap] != me) {
if (sendnum[iswap])
MPI_Irecv(buf_recv,nsize*sendnum[iswap],MPI_DOUBLE,sendproc[iswap],0,
world,&request);
MPI_Irecv(buf_recv,nsize*sendnum[iswap],MPI_DOUBLE,sendproc[iswap],0,world,&request);
if (recvnum[iswap])
MPI_Send(buf_send,n,MPI_DOUBLE,recvproc[iswap],0,world);
if (sendnum[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
@ -1173,16 +1148,14 @@ void CommBrick::forward_comm(Fix *fix, int size)
// pack buffer
n = fix->pack_forward_comm(sendnum[iswap],sendlist[iswap],
buf_send,pbc_flag[iswap],pbc[iswap]);
n = fix->pack_forward_comm(sendnum[iswap],sendlist[iswap],buf_send,pbc_flag[iswap],pbc[iswap]);
// exchange with another proc
// if self, set recv buffer to send buffer
if (sendproc[iswap] != me) {
if (recvnum[iswap])
MPI_Irecv(buf_recv,nsize*recvnum[iswap],MPI_DOUBLE,recvproc[iswap],0,
world,&request);
MPI_Irecv(buf_recv,nsize*recvnum[iswap],MPI_DOUBLE,recvproc[iswap],0,world,&request);
if (sendnum[iswap])
MPI_Send(buf_send,n,MPI_DOUBLE,sendproc[iswap],0,world);
if (recvnum[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
@ -1224,8 +1197,7 @@ void CommBrick::reverse_comm(Fix *fix, int size)
if (sendproc[iswap] != me) {
if (sendnum[iswap])
MPI_Irecv(buf_recv,nsize*sendnum[iswap],MPI_DOUBLE,sendproc[iswap],0,
world,&request);
MPI_Irecv(buf_recv,nsize*sendnum[iswap],MPI_DOUBLE,sendproc[iswap],0,world,&request);
if (recvnum[iswap])
MPI_Send(buf_send,n,MPI_DOUBLE,recvproc[iswap],0,world);
if (sendnum[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
@ -1263,13 +1235,11 @@ void CommBrick::reverse_comm_variable(Fix *fix)
if (sendproc[iswap] != me) {
MPI_Sendrecv(&nsend,1,MPI_INT,recvproc[iswap],0,
&nrecv,1,MPI_INT,sendproc[iswap],0,world,
MPI_STATUS_IGNORE);
&nrecv,1,MPI_INT,sendproc[iswap],0,world,MPI_STATUS_IGNORE);
if (sendnum[iswap]) {
if (nrecv > maxrecv) grow_recv(nrecv);
MPI_Irecv(buf_recv,maxrecv,MPI_DOUBLE,sendproc[iswap],0,
world,&request);
MPI_Irecv(buf_recv,maxrecv,MPI_DOUBLE,sendproc[iswap],0,world,&request);
}
if (recvnum[iswap])
MPI_Send(buf_send,nsend,MPI_DOUBLE,recvproc[iswap],0,world);
@ -1308,8 +1278,7 @@ void CommBrick::forward_comm(Compute *compute)
if (sendproc[iswap] != me) {
if (recvnum[iswap])
MPI_Irecv(buf_recv,nsize*recvnum[iswap],MPI_DOUBLE,recvproc[iswap],0,
world,&request);
MPI_Irecv(buf_recv,nsize*recvnum[iswap],MPI_DOUBLE,recvproc[iswap],0,world,&request);
if (sendnum[iswap])
MPI_Send(buf_send,n,MPI_DOUBLE,sendproc[iswap],0,world);
if (recvnum[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
@ -1346,8 +1315,7 @@ void CommBrick::reverse_comm(Compute *compute)
if (sendproc[iswap] != me) {
if (sendnum[iswap])
MPI_Irecv(buf_recv,nsize*sendnum[iswap],MPI_DOUBLE,sendproc[iswap],0,
world,&request);
MPI_Irecv(buf_recv,nsize*sendnum[iswap],MPI_DOUBLE,sendproc[iswap],0,world,&request);
if (recvnum[iswap])
MPI_Send(buf_send,n,MPI_DOUBLE,recvproc[iswap],0,world);
if (sendnum[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
@ -1385,8 +1353,7 @@ void CommBrick::forward_comm(Dump *dump)
if (sendproc[iswap] != me) {
if (recvnum[iswap])
MPI_Irecv(buf_recv,nsize*recvnum[iswap],MPI_DOUBLE,recvproc[iswap],0,
world,&request);
MPI_Irecv(buf_recv,nsize*recvnum[iswap],MPI_DOUBLE,recvproc[iswap],0,world,&request);
if (sendnum[iswap])
MPI_Send(buf_send,n,MPI_DOUBLE,sendproc[iswap],0,world);
if (recvnum[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
@ -1423,8 +1390,7 @@ void CommBrick::reverse_comm(Dump *dump)
if (sendproc[iswap] != me) {
if (sendnum[iswap])
MPI_Irecv(buf_recv,nsize*sendnum[iswap],MPI_DOUBLE,sendproc[iswap],0,
world,&request);
MPI_Irecv(buf_recv,nsize*sendnum[iswap],MPI_DOUBLE,sendproc[iswap],0,world,&request);
if (recvnum[iswap])
MPI_Send(buf_send,n,MPI_DOUBLE,recvproc[iswap],0,world);
if (sendnum[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
@ -1472,11 +1438,9 @@ void CommBrick::forward_comm_array(int nsize, double **array)
if (sendproc[iswap] != me) {
if (recvnum[iswap])
MPI_Irecv(buf_recv,nsize*recvnum[iswap],MPI_DOUBLE,recvproc[iswap],0,
world,&request);
MPI_Irecv(buf_recv,nsize*recvnum[iswap],MPI_DOUBLE,recvproc[iswap],0,world,&request);
if (sendnum[iswap])
MPI_Send(buf_send,nsize*sendnum[iswap],MPI_DOUBLE,
sendproc[iswap],0,world);
MPI_Send(buf_send,nsize*sendnum[iswap],MPI_DOUBLE,sendproc[iswap],0,world);
if (recvnum[iswap]) MPI_Wait(&request,MPI_STATUS_IGNORE);
buf = buf_recv;
} else buf = buf_send;
@ -1522,21 +1486,18 @@ int CommBrick::exchange_variable(int n, double *inbuf, double *&outbuf)
nrecv += nrecv1;
if (procgrid[dim] > 2) {
MPI_Sendrecv(&nsend,1,MPI_INT,procneigh[dim][1],0,
&nrecv2,1,MPI_INT,procneigh[dim][0],0,world,
MPI_STATUS_IGNORE);
&nrecv2,1,MPI_INT,procneigh[dim][0],0,world,MPI_STATUS_IGNORE);
nrecv += nrecv2;
} else nrecv2 = 0;
if (nrecv > maxrecv) grow_recv(nrecv);
MPI_Irecv(&buf_recv[nsend],nrecv1,MPI_DOUBLE,procneigh[dim][1],0,
world,&request);
MPI_Irecv(&buf_recv[nsend],nrecv1,MPI_DOUBLE,procneigh[dim][1],0,world,&request);
MPI_Send(buf_recv,nsend,MPI_DOUBLE,procneigh[dim][0],0,world);
MPI_Wait(&request,MPI_STATUS_IGNORE);
if (procgrid[dim] > 2) {
MPI_Irecv(&buf_recv[nsend+nrecv1],nrecv2,MPI_DOUBLE,procneigh[dim][0],0,
world,&request);
MPI_Irecv(&buf_recv[nsend+nrecv1],nrecv2,MPI_DOUBLE,procneigh[dim][0],0,world,&request);
MPI_Send(buf_recv,nsend,MPI_DOUBLE,procneigh[dim][1],0,world);
MPI_Wait(&request,MPI_STATUS_IGNORE);
}

View File

@ -513,16 +513,14 @@ void CommTiled::setup()
MIN(sbox_multi[3+idim]+cutghostmulti[icollection][idim],subhi[idim]);
else
sbox_multi[3+idim] =
MIN(sbox_multi[3+idim]-prd[idim]+cutghostmulti[icollection][idim],
subhi[idim]);
MIN(sbox_multi[3+idim]-prd[idim]+cutghostmulti[icollection][idim],subhi[idim]);
} else {
if (i < noverlap1)
sbox_multi[idim] =
MAX(sbox_multi[idim]-cutghostmulti[icollection][idim],sublo[idim]);
else
sbox_multi[idim] =
MAX(sbox_multi[idim]+prd[idim]-cutghostmulti[icollection][idim],
sublo[idim]);
MAX(sbox_multi[idim]+prd[idim]-cutghostmulti[icollection][idim],sublo[idim]);
sbox_multi[3+idim] = subhi[idim];
}
@ -589,16 +587,14 @@ void CommTiled::setup()
MIN(sbox_multiold[3+idim]+cutghostmultiold[itype][idim],subhi[idim]);
else
sbox_multiold[3+idim] =
MIN(sbox_multiold[3+idim]-prd[idim]+cutghostmultiold[itype][idim],
subhi[idim]);
MIN(sbox_multiold[3+idim]-prd[idim]+cutghostmultiold[itype][idim],subhi[idim]);
} else {
if (i < noverlap1)
sbox_multiold[idim] =
MAX(sbox_multiold[idim]-cutghostmultiold[itype][idim],sublo[idim]);
else
sbox_multiold[idim] =
MAX(sbox_multiold[idim]+prd[idim]-cutghostmultiold[itype][idim],
sublo[idim]);
MAX(sbox_multiold[idim]+prd[idim]-cutghostmultiold[itype][idim],sublo[idim]);
sbox_multiold[3+idim] = subhi[idim];
}
@ -748,8 +744,7 @@ void CommTiled::forward_comm(int /*dummy*/)
}
if (sendself[iswap]) {
avec->pack_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],
x[firstrecv[iswap][nrecv]],pbc_flag[iswap][nsend],
pbc[iswap][nsend]);
x[firstrecv[iswap][nrecv]],pbc_flag[iswap][nsend],pbc[iswap][nsend]);
}
if (recvother[iswap]) MPI_Waitall(nrecv,requests,MPI_STATUS_IGNORE);
@ -757,8 +752,7 @@ void CommTiled::forward_comm(int /*dummy*/)
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++)
MPI_Irecv(&buf_recv[size_forward*forward_recv_offset[iswap][i]],
size_forward_recv[iswap][i],
MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
size_forward_recv[iswap][i],MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
}
if (sendother[iswap]) {
for (i = 0; i < nsend; i++) {
@ -770,15 +764,13 @@ void CommTiled::forward_comm(int /*dummy*/)
if (sendself[iswap]) {
avec->pack_comm_vel(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send,pbc_flag[iswap][nsend],pbc[iswap][nsend]);
avec->unpack_comm_vel(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],
buf_send);
avec->unpack_comm_vel(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
MPI_Waitany(nrecv,requests,&irecv,MPI_STATUS_IGNORE);
avec->unpack_comm_vel(recvnum[iswap][irecv],firstrecv[iswap][irecv],
&buf_recv[size_forward*
forward_recv_offset[iswap][irecv]]);
&buf_recv[size_forward*forward_recv_offset[iswap][irecv]]);
}
}
@ -786,8 +778,7 @@ void CommTiled::forward_comm(int /*dummy*/)
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++)
MPI_Irecv(&buf_recv[size_forward*forward_recv_offset[iswap][i]],
size_forward_recv[iswap][i],
MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
size_forward_recv[iswap][i],MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
}
if (sendother[iswap]) {
for (i = 0; i < nsend; i++) {
@ -799,15 +790,13 @@ void CommTiled::forward_comm(int /*dummy*/)
if (sendself[iswap]) {
avec->pack_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send,pbc_flag[iswap][nsend],pbc[iswap][nsend]);
avec->unpack_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],
buf_send);
avec->unpack_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
MPI_Waitany(nrecv,requests,&irecv,MPI_STATUS_IGNORE);
avec->unpack_comm(recvnum[iswap][irecv],firstrecv[iswap][irecv],
&buf_recv[size_forward*
forward_recv_offset[iswap][irecv]]);
&buf_recv[size_forward*forward_recv_offset[iswap][irecv]]);
}
}
}
@ -840,8 +829,7 @@ void CommTiled::reverse_comm()
if (sendother[iswap]) {
for (i = 0; i < nsend; i++) {
MPI_Irecv(&buf_recv[size_reverse*reverse_recv_offset[iswap][i]],
size_reverse_recv[iswap][i],MPI_DOUBLE,
sendproc[iswap][i],0,world,&requests[i]);
size_reverse_recv[iswap][i],MPI_DOUBLE,sendproc[iswap][i],0,world,&requests[i]);
}
}
if (recvother[iswap]) {
@ -857,8 +845,7 @@ void CommTiled::reverse_comm()
for (i = 0; i < nsend; i++) {
MPI_Waitany(nsend,requests,&irecv,MPI_STATUS_IGNORE);
avec->unpack_reverse(sendnum[iswap][irecv],sendlist[iswap][irecv],
&buf_recv[size_reverse*
reverse_recv_offset[iswap][irecv]]);
&buf_recv[size_reverse*reverse_recv_offset[iswap][irecv]]);
}
}
@ -866,28 +853,23 @@ void CommTiled::reverse_comm()
if (sendother[iswap]) {
for (i = 0; i < nsend; i++)
MPI_Irecv(&buf_recv[size_reverse*reverse_recv_offset[iswap][i]],
size_reverse_recv[iswap][i],MPI_DOUBLE,
sendproc[iswap][i],0,world,&requests[i]);
size_reverse_recv[iswap][i],MPI_DOUBLE,sendproc[iswap][i],0,world,&requests[i]);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
n = avec->pack_reverse(recvnum[iswap][i],firstrecv[iswap][i],
buf_send);
n = avec->pack_reverse(recvnum[iswap][i],firstrecv[iswap][i],buf_send);
MPI_Send(buf_send,n,MPI_DOUBLE,recvproc[iswap][i],0,world);
}
}
if (sendself[iswap]) {
avec->pack_reverse(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],
buf_send);
avec->unpack_reverse(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send);
avec->pack_reverse(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
avec->unpack_reverse(sendnum[iswap][nsend],sendlist[iswap][nsend],buf_send);
}
if (sendother[iswap]) {
for (i = 0; i < nsend; i++) {
MPI_Waitany(nsend,requests,&irecv,MPI_STATUS_IGNORE);
avec->unpack_reverse(sendnum[iswap][irecv],sendlist[iswap][irecv],
&buf_recv[size_reverse*
reverse_recv_offset[iswap][irecv]]);
&buf_recv[size_reverse*reverse_recv_offset[iswap][irecv]]);
}
}
}
@ -990,8 +972,7 @@ void CommTiled::exchange()
if (!nexch) continue;
for (m = 0; m < nexch; m++)
MPI_Irecv(&exchnum[dim][m],1,MPI_INT,
exchproc[dim][m],0,world,&requests[m]);
MPI_Irecv(&exchnum[dim][m],1,MPI_INT,exchproc[dim][m],0,world,&requests[m]);
for (m = 0; m < nexch; m++)
MPI_Send(&nsend,1,MPI_INT,exchproc[dim][m],0,world);
MPI_Waitall(nexch,requests,MPI_STATUS_IGNORE);
@ -1002,8 +983,7 @@ void CommTiled::exchange()
offset = 0;
for (m = 0; m < nexch; m++) {
MPI_Irecv(&buf_recv[offset],exchnum[dim][m],
MPI_DOUBLE,exchproc[dim][m],0,world,&requests[m]);
MPI_Irecv(&buf_recv[offset],exchnum[dim][m],MPI_DOUBLE,exchproc[dim][m],0,world,&requests[m]);
offset += exchnum[dim][m];
}
for (m = 0; m < nexch; m++)
@ -1234,8 +1214,7 @@ void CommTiled::borders()
if (recvother[iswap])
for (m = 0; m < nrecv; m++)
MPI_Irecv(&recvnum[iswap][m],1,MPI_INT,
recvproc[iswap][m],0,world,&requests[m]);
MPI_Irecv(&recvnum[iswap][m],1,MPI_INT,recvproc[iswap][m],0,world,&requests[m]);
if (sendother[iswap])
for (m = 0; m < nsend; m++)
MPI_Send(&sendnum[iswap][m],1,MPI_INT,sendproc[iswap][m],0,world);
@ -1295,17 +1274,14 @@ void CommTiled::borders()
}
if (sendself[iswap]) {
avec->pack_border_vel(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send,pbc_flag[iswap][nsend],
pbc[iswap][nsend]);
avec->unpack_border_vel(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],
buf_send);
buf_send,pbc_flag[iswap][nsend],pbc[iswap][nsend]);
avec->unpack_border_vel(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
MPI_Waitany(nrecv,requests,&m,MPI_STATUS_IGNORE);
avec->unpack_border_vel(recvnum[iswap][m],firstrecv[iswap][m],
&buf_recv[size_border*
forward_recv_offset[iswap][m]]);
&buf_recv[size_border*forward_recv_offset[iswap][m]]);
}
}
@ -1326,15 +1302,13 @@ void CommTiled::borders()
if (sendself[iswap]) {
avec->pack_border(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send,pbc_flag[iswap][nsend],pbc[iswap][nsend]);
avec->unpack_border(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],
buf_send);
avec->unpack_border(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
MPI_Waitany(nrecv,requests,&m,MPI_STATUS_IGNORE);
avec->unpack_border(recvnum[iswap][m],firstrecv[iswap][m],
&buf_recv[size_border*
forward_recv_offset[iswap][m]]);
&buf_recv[size_border*forward_recv_offset[iswap][m]]);
}
}
}
@ -1352,10 +1326,8 @@ void CommTiled::borders()
// For molecular systems we lose some bits for local atom indices due
// to encoding of special pairs in neighbor lists. Check for overflows.
if ((atom->molecular != Atom::ATOMIC)
&& ((atom->nlocal + atom->nghost) > NEIGHMASK))
error->one(FLERR,"Per-processor number of atoms is too large for "
"molecular neighbor lists");
if ((atom->molecular != Atom::ATOMIC) && ((atom->nlocal + atom->nghost) > NEIGHMASK))
error->one(FLERR,"Per-processor number of atoms is too large for molecular neighbor lists");
// insure send/recv buffers are long enough for all forward & reverse comm
// send buf is for one forward or reverse sends to one proc
@ -1389,8 +1361,7 @@ void CommTiled::forward_comm(Pair *pair)
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++)
MPI_Irecv(&buf_recv[nsize*forward_recv_offset[iswap][i]],
nsize*recvnum[iswap][i],
MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
nsize*recvnum[iswap][i],MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
}
if (sendother[iswap]) {
@ -1403,17 +1374,14 @@ void CommTiled::forward_comm(Pair *pair)
if (sendself[iswap]) {
pair->pack_forward_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send,pbc_flag[iswap][nsend],
pbc[iswap][nsend]);
pair->unpack_forward_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],
buf_send);
buf_send,pbc_flag[iswap][nsend],pbc[iswap][nsend]);
pair->unpack_forward_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
MPI_Waitany(nrecv,requests,&irecv,MPI_STATUS_IGNORE);
pair->unpack_forward_comm(recvnum[iswap][irecv],firstrecv[iswap][irecv],
&buf_recv[nsize*
forward_recv_offset[iswap][irecv]]);
&buf_recv[nsize*forward_recv_offset[iswap][irecv]]);
}
}
}
@ -1437,28 +1405,23 @@ void CommTiled::reverse_comm(Pair *pair)
if (sendother[iswap]) {
for (i = 0; i < nsend; i++)
MPI_Irecv(&buf_recv[nsize*reverse_recv_offset[iswap][i]],
nsize*sendnum[iswap][i],MPI_DOUBLE,
sendproc[iswap][i],0,world,&requests[i]);
nsize*sendnum[iswap][i],MPI_DOUBLE,sendproc[iswap][i],0,world,&requests[i]);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
n = pair->pack_reverse_comm(recvnum[iswap][i],firstrecv[iswap][i],
buf_send);
n = pair->pack_reverse_comm(recvnum[iswap][i],firstrecv[iswap][i],buf_send);
MPI_Send(buf_send,n,MPI_DOUBLE,recvproc[iswap][i],0,world);
}
}
if (sendself[iswap]) {
pair->pack_reverse_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],
buf_send);
pair->unpack_reverse_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send);
pair->pack_reverse_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
pair->unpack_reverse_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],buf_send);
}
if (sendother[iswap]) {
for (i = 0; i < nsend; i++) {
MPI_Waitany(nsend,requests,&irecv,MPI_STATUS_IGNORE);
pair->unpack_reverse_comm(sendnum[iswap][irecv],sendlist[iswap][irecv],
&buf_recv[nsize*
reverse_recv_offset[iswap][irecv]]);
&buf_recv[nsize*reverse_recv_offset[iswap][irecv]]);
}
}
}
@ -1482,8 +1445,7 @@ void CommTiled::forward_comm(Bond *bond)
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++)
MPI_Irecv(&buf_recv[nsize*forward_recv_offset[iswap][i]],
nsize*recvnum[iswap][i],
MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
nsize*recvnum[iswap][i],MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
}
if (sendother[iswap]) {
@ -1496,17 +1458,14 @@ void CommTiled::forward_comm(Bond *bond)
if (sendself[iswap]) {
bond->pack_forward_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send,pbc_flag[iswap][nsend],
pbc[iswap][nsend]);
bond->unpack_forward_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],
buf_send);
buf_send,pbc_flag[iswap][nsend],pbc[iswap][nsend]);
bond->unpack_forward_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
MPI_Waitany(nrecv,requests,&irecv,MPI_STATUS_IGNORE);
bond->unpack_forward_comm(recvnum[iswap][irecv],firstrecv[iswap][irecv],
&buf_recv[nsize*
forward_recv_offset[iswap][irecv]]);
&buf_recv[nsize*forward_recv_offset[iswap][irecv]]);
}
}
}
@ -1530,28 +1489,23 @@ void CommTiled::reverse_comm(Bond *bond)
if (sendother[iswap]) {
for (i = 0; i < nsend; i++)
MPI_Irecv(&buf_recv[nsize*reverse_recv_offset[iswap][i]],
nsize*sendnum[iswap][i],MPI_DOUBLE,
sendproc[iswap][i],0,world,&requests[i]);
nsize*sendnum[iswap][i],MPI_DOUBLE,sendproc[iswap][i],0,world,&requests[i]);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
n = bond->pack_reverse_comm(recvnum[iswap][i],firstrecv[iswap][i],
buf_send);
n = bond->pack_reverse_comm(recvnum[iswap][i],firstrecv[iswap][i],buf_send);
MPI_Send(buf_send,n,MPI_DOUBLE,recvproc[iswap][i],0,world);
}
}
if (sendself[iswap]) {
bond->pack_reverse_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],
buf_send);
bond->unpack_reverse_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send);
bond->pack_reverse_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
bond->unpack_reverse_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],buf_send);
}
if (sendother[iswap]) {
for (i = 0; i < nsend; i++) {
MPI_Waitany(nsend,requests,&irecv,MPI_STATUS_IGNORE);
bond->unpack_reverse_comm(sendnum[iswap][irecv],sendlist[iswap][irecv],
&buf_recv[nsize*
reverse_recv_offset[iswap][irecv]]);
&buf_recv[nsize*reverse_recv_offset[iswap][irecv]]);
}
}
}
@ -1580,8 +1534,7 @@ void CommTiled::forward_comm(Fix *fix, int size)
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++)
MPI_Irecv(&buf_recv[nsize*forward_recv_offset[iswap][i]],
nsize*recvnum[iswap][i],
MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
nsize*recvnum[iswap][i],MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
}
if (sendother[iswap]) {
for (i = 0; i < nsend; i++) {
@ -1592,17 +1545,14 @@ void CommTiled::forward_comm(Fix *fix, int size)
}
if (sendself[iswap]) {
fix->pack_forward_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send,pbc_flag[iswap][nsend],
pbc[iswap][nsend]);
fix->unpack_forward_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],
buf_send);
buf_send,pbc_flag[iswap][nsend],pbc[iswap][nsend]);
fix->unpack_forward_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
MPI_Waitany(nrecv,requests,&irecv,MPI_STATUS_IGNORE);
fix->unpack_forward_comm(recvnum[iswap][irecv],firstrecv[iswap][irecv],
&buf_recv[nsize*
forward_recv_offset[iswap][irecv]]);
&buf_recv[nsize*forward_recv_offset[iswap][irecv]]);
}
}
}
@ -1631,28 +1581,23 @@ void CommTiled::reverse_comm(Fix *fix, int size)
if (sendother[iswap]) {
for (i = 0; i < nsend; i++)
MPI_Irecv(&buf_recv[nsize*reverse_recv_offset[iswap][i]],
nsize*sendnum[iswap][i],MPI_DOUBLE,
sendproc[iswap][i],0,world,&requests[i]);
nsize*sendnum[iswap][i],MPI_DOUBLE,sendproc[iswap][i],0,world,&requests[i]);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
n = fix->pack_reverse_comm(recvnum[iswap][i],firstrecv[iswap][i],
buf_send);
n = fix->pack_reverse_comm(recvnum[iswap][i],firstrecv[iswap][i],buf_send);
MPI_Send(buf_send,n,MPI_DOUBLE,recvproc[iswap][i],0,world);
}
}
if (sendself[iswap]) {
fix->pack_reverse_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],
buf_send);
fix->unpack_reverse_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send);
fix->pack_reverse_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
fix->unpack_reverse_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],buf_send);
}
if (sendother[iswap]) {
for (i = 0; i < nsend; i++) {
MPI_Waitany(nsend,requests,&irecv,MPI_STATUS_IGNORE);
fix->unpack_reverse_comm(sendnum[iswap][irecv],sendlist[iswap][irecv],
&buf_recv[nsize*
reverse_recv_offset[iswap][irecv]]);
&buf_recv[nsize*reverse_recv_offset[iswap][irecv]]);
}
}
}
@ -1688,31 +1633,26 @@ void CommTiled::forward_comm(Compute *compute)
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++)
MPI_Irecv(&buf_recv[nsize*forward_recv_offset[iswap][i]],
nsize*recvnum[iswap][i],
MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
nsize*recvnum[iswap][i],MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
}
if (sendother[iswap]) {
for (i = 0; i < nsend; i++) {
n = compute->pack_forward_comm(sendnum[iswap][i],sendlist[iswap][i],
buf_send,pbc_flag[iswap][i],
pbc[iswap][i]);
buf_send,pbc_flag[iswap][i],pbc[iswap][i]);
MPI_Send(buf_send,n,MPI_DOUBLE,sendproc[iswap][i],0,world);
}
}
if (sendself[iswap]) {
compute->pack_forward_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send,pbc_flag[iswap][nsend],
pbc[iswap][nsend]);
compute->unpack_forward_comm(recvnum[iswap][nrecv],
firstrecv[iswap][nrecv],buf_send);
buf_send,pbc_flag[iswap][nsend],pbc[iswap][nsend]);
compute->unpack_forward_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
MPI_Waitany(nrecv,requests,&irecv,MPI_STATUS_IGNORE);
compute->
unpack_forward_comm(recvnum[iswap][irecv],firstrecv[iswap][irecv],
&buf_recv[nsize*
forward_recv_offset[iswap][irecv]]);
&buf_recv[nsize*forward_recv_offset[iswap][irecv]]);
}
}
}
@ -1736,29 +1676,24 @@ void CommTiled::reverse_comm(Compute *compute)
if (sendother[iswap]) {
for (i = 0; i < nsend; i++)
MPI_Irecv(&buf_recv[nsize*reverse_recv_offset[iswap][i]],
nsize*sendnum[iswap][i],MPI_DOUBLE,
sendproc[iswap][i],0,world,&requests[i]);
nsize*sendnum[iswap][i],MPI_DOUBLE,sendproc[iswap][i],0,world,&requests[i]);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
n = compute->pack_reverse_comm(recvnum[iswap][i],firstrecv[iswap][i],
buf_send);
n = compute->pack_reverse_comm(recvnum[iswap][i],firstrecv[iswap][i],buf_send);
MPI_Send(buf_send,n,MPI_DOUBLE,recvproc[iswap][i],0,world);
}
}
if (sendself[iswap]) {
compute->pack_reverse_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],
buf_send);
compute->unpack_reverse_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send);
compute->pack_reverse_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
compute->unpack_reverse_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],buf_send);
}
if (sendother[iswap]) {
for (i = 0; i < nsend; i++) {
MPI_Waitany(nsend,requests,&irecv,MPI_STATUS_IGNORE);
compute->
unpack_reverse_comm(sendnum[iswap][irecv],sendlist[iswap][irecv],
&buf_recv[nsize*
reverse_recv_offset[iswap][irecv]]);
&buf_recv[nsize*reverse_recv_offset[iswap][irecv]]);
}
}
}
@ -1782,21 +1717,18 @@ void CommTiled::forward_comm(Dump *dump)
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++)
MPI_Irecv(&buf_recv[nsize*forward_recv_offset[iswap][i]],
nsize*recvnum[iswap][i],
MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
nsize*recvnum[iswap][i],MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
}
if (sendother[iswap]) {
for (i = 0; i < nsend; i++) {
n = dump->pack_forward_comm(sendnum[iswap][i],sendlist[iswap][i],
buf_send,pbc_flag[iswap][i],
pbc[iswap][i]);
buf_send,pbc_flag[iswap][i],pbc[iswap][i]);
MPI_Send(buf_send,n,MPI_DOUBLE,sendproc[iswap][i],0,world);
}
}
if (sendself[iswap]) {
dump->pack_forward_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send,pbc_flag[iswap][nsend],
pbc[iswap][nsend]);
buf_send,pbc_flag[iswap][nsend],pbc[iswap][nsend]);
dump->unpack_forward_comm(recvnum[iswap][nrecv],
firstrecv[iswap][nrecv],buf_send);
}
@ -1804,8 +1736,7 @@ void CommTiled::forward_comm(Dump *dump)
for (i = 0; i < nrecv; i++) {
MPI_Waitany(nrecv,requests,&irecv,MPI_STATUS_IGNORE);
dump->unpack_forward_comm(recvnum[iswap][irecv],firstrecv[iswap][irecv],
&buf_recv[nsize*
forward_recv_offset[iswap][irecv]]);
&buf_recv[nsize*forward_recv_offset[iswap][irecv]]);
}
}
}
@ -1829,28 +1760,23 @@ void CommTiled::reverse_comm(Dump *dump)
if (sendother[iswap]) {
for (i = 0; i < nsend; i++)
MPI_Irecv(&buf_recv[nsize*reverse_recv_offset[iswap][i]],
nsize*sendnum[iswap][i],MPI_DOUBLE,
sendproc[iswap][i],0,world,&requests[i]);
nsize*sendnum[iswap][i],MPI_DOUBLE,sendproc[iswap][i],0,world,&requests[i]);
}
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++) {
n = dump->pack_reverse_comm(recvnum[iswap][i],firstrecv[iswap][i],
buf_send);
n = dump->pack_reverse_comm(recvnum[iswap][i],firstrecv[iswap][i],buf_send);
MPI_Send(buf_send,n,MPI_DOUBLE,recvproc[iswap][i],0,world);
}
}
if (sendself[iswap]) {
dump->pack_reverse_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],
buf_send);
dump->unpack_reverse_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],
buf_send);
dump->pack_reverse_comm(recvnum[iswap][nrecv],firstrecv[iswap][nrecv],buf_send);
dump->unpack_reverse_comm(sendnum[iswap][nsend],sendlist[iswap][nsend],buf_send);
}
if (sendother[iswap]) {
for (i = 0; i < nsend; i++) {
MPI_Waitany(nsend,requests,&irecv,MPI_STATUS_IGNORE);
dump->unpack_reverse_comm(sendnum[iswap][irecv],sendlist[iswap][irecv],
&buf_recv[nsize*
reverse_recv_offset[iswap][irecv]]);
&buf_recv[nsize*reverse_recv_offset[iswap][irecv]]);
}
}
}
@ -1882,8 +1808,7 @@ void CommTiled::forward_comm_array(int nsize, double **array)
if (recvother[iswap]) {
for (i = 0; i < nrecv; i++)
MPI_Irecv(&buf_recv[nsize*forward_recv_offset[iswap][i]],
nsize*recvnum[iswap][i],
MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
nsize*recvnum[iswap][i],MPI_DOUBLE,recvproc[iswap][i],0,world,&requests[i]);
}
if (sendother[iswap]) {
for (i = 0; i < nsend; i++) {
@ -1893,8 +1818,7 @@ void CommTiled::forward_comm_array(int nsize, double **array)
for (k = 0; k < nsize; k++)
buf_send[m++] = array[j][k];
}
MPI_Send(buf_send,nsize*sendnum[iswap][i],
MPI_DOUBLE,sendproc[iswap][i],0,world);
MPI_Send(buf_send,nsize*sendnum[iswap][i],MPI_DOUBLE,sendproc[iswap][i],0,world);
}
}
if (sendself[iswap]) {
@ -2013,8 +1937,7 @@ void CommTiled::box_drop_tiled(int /*idim*/, double *lo, double *hi, int &indexm
box_drop_tiled_recurse(lo,hi,0,nprocs-1,indexme);
}
void CommTiled::box_drop_tiled_recurse(double *lo, double *hi,
int proclower, int procupper,
void CommTiled::box_drop_tiled_recurse(double *lo, double *hi, int proclower, int procupper,
int &indexme)
{
// end recursion when partition is a single proc
@ -2052,8 +1975,7 @@ void CommTiled::box_drop_tiled_recurse(double *lo, double *hi,
return other box owned by proc as lo/hi corner pts
------------------------------------------------------------------------- */
void CommTiled::box_other_brick(int idim, int idir,
int proc, double *lo, double *hi)
void CommTiled::box_other_brick(int idim, int idir, int proc, double *lo, double *hi)
{
lo[0] = sublo[0]; lo[1] = sublo[1]; lo[2] = sublo[2];
hi[0] = subhi[0]; hi[1] = subhi[1]; hi[2] = subhi[2];
@ -2100,8 +2022,7 @@ void CommTiled::box_other_brick(int idim, int idir,
return other box owned by proc as lo/hi corner pts
------------------------------------------------------------------------- */
void CommTiled::box_other_tiled(int /*idim*/, int /*idir*/,
int proc, double *lo, double *hi)
void CommTiled::box_other_tiled(int /*idim*/, int /*idir*/, int proc, double *lo, double *hi)
{
double (*split)[2] = rcbinfo[proc].mysplit;
@ -2230,8 +2151,7 @@ int CommTiled::point_drop_tiled(int idim, double *x)
recursive point drop thru RCB tree
------------------------------------------------------------------------- */
int CommTiled::point_drop_tiled_recurse(double *x,
int proclower, int procupper)
int CommTiled::point_drop_tiled_recurse(double *x, int proclower, int procupper)
{
// end recursion when partition is a single proc
// return proc
@ -2289,8 +2209,7 @@ void CommTiled::coord2proc_setup()
memcpy(&rcbone.mysplit[0][0],&mysplit[0][0],6*sizeof(double));
rcbone.cutfrac = rcbcutfrac;
rcbone.dim = rcbcutdim;
MPI_Allgather(&rcbone,sizeof(RCBinfo),MPI_CHAR,
rcbinfo,sizeof(RCBinfo),MPI_CHAR,world);
MPI_Allgather(&rcbone,sizeof(RCBinfo),MPI_CHAR,rcbinfo,sizeof(RCBinfo),MPI_CHAR,world);
}
/* ----------------------------------------------------------------------

View File

@ -339,8 +339,8 @@ void DeleteBonds::command(int narg, char **arg)
atom->bond_atom[i][m] = atom->bond_atom[i][n-1];
if (n_histories > 0)
for (auto &ihistory: histories) {
((FixBondHistory *) ihistory)->shift_history(i,m,n-1);
((FixBondHistory *) ihistory)->delete_history(i,n-1);
dynamic_cast<FixBondHistory *>(ihistory)->shift_history(i,m,n-1);
dynamic_cast<FixBondHistory *>(ihistory)->delete_history(i,n-1);
}
atom->num_bond[i]--;
} else m++;
@ -442,32 +442,28 @@ void DeleteBonds::command(int narg, char **arg)
if (atom->avec->bonds_allow) {
bigint nbonds = 0;
for (i = 0; i < nlocal; i++) nbonds += atom->num_bond[i];
MPI_Allreduce(&nbonds,&atom->nbonds,1,MPI_LMP_BIGINT,
MPI_SUM,world);
MPI_Allreduce(&nbonds,&atom->nbonds,1,MPI_LMP_BIGINT,MPI_SUM,world);
if (force->newton_bond == 0) atom->nbonds /= 2;
}
if (atom->avec->angles_allow) {
bigint nangles = 0;
for (i = 0; i < nlocal; i++) nangles += atom->num_angle[i];
MPI_Allreduce(&nangles,&atom->nangles,1,MPI_LMP_BIGINT,
MPI_SUM,world);
MPI_Allreduce(&nangles,&atom->nangles,1,MPI_LMP_BIGINT,MPI_SUM,world);
if (force->newton_bond == 0) atom->nangles /= 3;
}
if (atom->avec->dihedrals_allow) {
bigint ndihedrals = 0;
for (i = 0; i < nlocal; i++) ndihedrals += atom->num_dihedral[i];
MPI_Allreduce(&ndihedrals,&atom->ndihedrals,
1,MPI_LMP_BIGINT,MPI_SUM,world);
MPI_Allreduce(&ndihedrals,&atom->ndihedrals,1,MPI_LMP_BIGINT,MPI_SUM,world);
if (force->newton_bond == 0) atom->ndihedrals /= 4;
}
if (atom->avec->impropers_allow) {
bigint nimpropers = 0;
for (i = 0; i < nlocal; i++) nimpropers += atom->num_improper[i];
MPI_Allreduce(&nimpropers,&atom->nimpropers,
1,MPI_LMP_BIGINT,MPI_SUM,world);
MPI_Allreduce(&nimpropers,&atom->nimpropers,1,MPI_LMP_BIGINT,MPI_SUM,world);
if (force->newton_bond == 0) atom->nimpropers /= 4;
}
@ -546,21 +542,18 @@ void DeleteBonds::command(int narg, char **arg)
}
if (comm->me == 0) {
constexpr auto fmtstr = " {} total {}, {} turned on, {} turned off\n";
if (atom->avec->bonds_allow)
utils::logmesg(lmp," {} total bonds, {} turned on, {} turned off\n",
atom->nbonds,bond_on,bond_off);
utils::logmesg(lmp,fmtstr,atom->nbonds,"bonds",bond_on,bond_off);
if (atom->avec->angles_allow)
utils::logmesg(lmp," {} total angles, {} turned on, {} turned off\n",
atom->nangles,angle_on,angle_off);
utils::logmesg(lmp,fmtstr,atom->nangles,"angles",angle_on,angle_off);
if (atom->avec->dihedrals_allow)
utils::logmesg(lmp," {} total dihedrals, {} turned on, {} turned off\n",
atom->ndihedrals,dihedral_on,dihedral_off);
utils::logmesg(lmp,fmtstr,atom->ndihedrals,"dihedrals",dihedral_on,dihedral_off);
if (atom->avec->impropers_allow)
utils::logmesg(lmp," {} total impropers, {} turned on, {} turned off\n",
atom->nimpropers,improper_on,improper_off);
utils::logmesg(lmp,fmtstr,atom->nimpropers,"impropers",improper_on,improper_off);
}
// re-compute special list if requested

View File

@ -66,7 +66,6 @@ class Dump : protected Pointers {
char *multiname; // filename with % converted to cluster ID
MPI_Comm clustercomm; // MPI communicator within my cluster of procs
int header_flag; // 0 = item, 2 = xyz
int flush_flag; // 0 if no flush, 1 if flush every dump
int sort_flag; // 1 if sorted output
int balance_flag; // 1 if load balanced output

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -23,9 +22,7 @@
#include "neighbor.h"
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace LAMMPS_NS;
using namespace FixConst;
@ -36,15 +33,15 @@ using namespace FixConst;
/* ---------------------------------------------------------------------- */
FixBondHistory::FixBondHistory(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg)
Fix(lmp, narg, arg), bondstore(nullptr), id_fix(nullptr), id_array(nullptr)
{
if (narg != 5) error->all(FLERR,"Illegal fix bond/history command");
update_flag = utils::inumeric(FLERR,arg[3],false,lmp);
ndata = utils::inumeric(FLERR,arg[4],false,lmp);
if (narg != 5) error->all(FLERR, "Illegal fix bond/history command");
update_flag = utils::inumeric(FLERR, arg[3], false, lmp);
ndata = utils::inumeric(FLERR, arg[4], false, lmp);
nbond = atom->bond_per_atom;
if (nbond == 0)
error->all(FLERR, "Cannot store bond variables without any bonds");
if (nbond == 0) error->all(FLERR, "Cannot store bond variables without any bonds");
stored_flag = false;
restart_global = 1;
@ -55,12 +52,8 @@ FixBondHistory::FixBondHistory(LAMMPS *lmp, int narg, char **arg) :
// Prevents sequential calls to pre_exchange() without post_neighbor()
updated_bond_flag = 0;
bondstore = nullptr;
maxbond = 0;
allocate();
id_fix = nullptr;
id_array = nullptr;
}
/* ---------------------------------------------------------------------- */
@ -68,8 +61,8 @@ FixBondHistory::FixBondHistory(LAMMPS *lmp, int narg, char **arg) :
FixBondHistory::~FixBondHistory()
{
if (id_fix && modify->nfix) modify->delete_fix(id_fix);
delete [] id_fix;
delete [] id_array;
delete[] id_fix;
delete[] id_array;
memory->destroy(bondstore);
}
@ -92,10 +85,10 @@ void FixBondHistory::post_constructor()
id_fix = utils::strdup(id + std::string("_FIX_PROP_ATOM"));
id_array = utils::strdup(std::string("d2_") + id);
modify->add_fix(fmt::format("{} {} property/atom {} {}",
id_fix, group->names[igroup], id_array, nbond*ndata));
modify->add_fix(fmt::format("{} {} property/atom {} {}", id_fix, group->names[igroup], id_array,
nbond * ndata));
int tmp1, tmp2;
index = atom->find_custom(&id_array[3],tmp1,tmp2);
index = atom->find_custom(&id_array[3], tmp1, tmp2);
}
/* ---------------------------------------------------------------------- */
@ -103,7 +96,7 @@ void FixBondHistory::post_constructor()
void FixBondHistory::update_atom_value(int i, int m, int idata, double value)
{
if (idata >= ndata || m > nbond) error->all(FLERR, "Index exceeded in fix bond history");
atom->darray[index][i][m*ndata+idata] = value;
atom->darray[index][i][m * ndata + idata] = value;
}
/* ---------------------------------------------------------------------- */
@ -111,7 +104,7 @@ void FixBondHistory::update_atom_value(int i, int m, int idata, double value)
double FixBondHistory::get_atom_value(int i, int m, int idata)
{
if (idata >= ndata || m > nbond) error->all(FLERR, "Index exceeded in fix bond history");
return atom->darray[index][i][m*ndata+idata];
return atom->darray[index][i][m * ndata + idata];
}
/* ---------------------------------------------------------------------- */
@ -148,15 +141,13 @@ void FixBondHistory::pre_exchange()
i2 = bondlist[n][1];
// skip bond if already broken
if (bondlist[n][2] <= 0) {
continue;
}
if (bondlist[n][2] <= 0) { continue; }
if (i1 < nlocal) {
for (m = 0; m < num_bond[i1]; m++) {
if (bond_atom[i1][m] == tag[i2]) {
for (idata = 0; idata < ndata; idata++) {
stored[i1][m*ndata+idata] = bondstore[n][idata];
stored[i1][m * ndata + idata] = bondstore[n][idata];
}
}
}
@ -166,7 +157,7 @@ void FixBondHistory::pre_exchange()
for (m = 0; m < num_bond[i2]; m++) {
if (bond_atom[i2][m] == tag[i1]) {
for (idata = 0; idata < ndata; idata++) {
stored[i2][m*ndata+idata] = bondstore[n][idata];
stored[i2][m * ndata + idata] = bondstore[n][idata];
}
}
}
@ -181,9 +172,11 @@ void FixBondHistory::pre_exchange()
void FixBondHistory::allocate()
{
//Ideally would just ask ntopo for maxbond, but protected
if (comm->nprocs == 1) maxbond = atom->nbonds;
else maxbond = static_cast<int> (LB_FACTOR * atom->nbonds / comm->nprocs);
memory->create(bondstore,maxbond,ndata,"fix_bond_store:bondstore");
if (comm->nprocs == 1)
maxbond = atom->nbonds;
else
maxbond = static_cast<int>(LB_FACTOR * atom->nbonds / comm->nprocs);
memory->create(bondstore, maxbond, ndata, "fix_bond_store:bondstore");
}
/* ---------------------------------------------------------------------- */
@ -193,7 +186,7 @@ void FixBondHistory::setup_post_neighbor()
//Grow array if number of bonds has increased
while (neighbor->nbondlist >= maxbond) {
maxbond += DELTA;
memory->grow(bondstore,maxbond,ndata,"fix_bond_store:bondstore");
memory->grow(bondstore, maxbond, ndata, "fix_bond_store:bondstore");
}
pre_exchange();
@ -210,7 +203,7 @@ void FixBondHistory::post_neighbor()
//Grow array if number of bonds has increased
while (neighbor->nbondlist >= maxbond) {
maxbond += DELTA;
memory->grow(bondstore,maxbond,ndata,"fix_bond_store:bondstore");
memory->grow(bondstore, maxbond, ndata, "fix_bond_store:bondstore");
}
int i1, i2, n, m, idata;
@ -228,25 +221,23 @@ void FixBondHistory::post_neighbor()
i2 = bondlist[n][1];
// skip bond if already broken
if (bondlist[n][2] <= 0) {
continue;
}
if (bondlist[n][2] <= 0) { continue; }
if (i1 < nlocal) {
for (m = 0; m < num_bond[i1]; m++) {
if (bond_atom[i1][m] == tag[i2]) {
for (idata = 0; idata < ndata; idata++) {
bondstore[n][idata] = stored[i1][m*ndata+idata];
bondstore[n][idata] = stored[i1][m * ndata + idata];
}
}
}
}
if (i2 < nlocal){
if (i2 < nlocal) {
for (m = 0; m < num_bond[i2]; m++) {
if (bond_atom[i2][m] == tag[i1]) {
for (idata = 0; idata < ndata; idata++) {
bondstore[n][idata] = stored[i2][m*ndata+idata];
bondstore[n][idata] = stored[i2][m * ndata + idata];
}
}
}
@ -273,8 +264,8 @@ void FixBondHistory::write_restart(FILE *fp)
if (comm->me == 0) {
int size = n * sizeof(double);
fwrite(&size,sizeof(int),1,fp);
fwrite(list,sizeof(double),n,fp);
fwrite(&size, sizeof(int), 1, fp);
fwrite(list, sizeof(double), n, fp);
}
}
@ -284,7 +275,7 @@ void FixBondHistory::restart(char *buf)
{
int n = 0;
double *list = (double *) buf;
stored_flag = static_cast<int> (list[n++]);
stored_flag = static_cast<int>(list[n++]);
}
/* ----------------------------------------------------------------------
@ -295,8 +286,7 @@ void FixBondHistory::set_arrays(int i)
{
double **stored = atom->darray[index];
for (int m = 0; m < nbond; m++)
for (int idata = 0; idata < ndata; idata++)
stored[i][m*ndata+idata] = 0.0;
for (int idata = 0; idata < ndata; idata++) stored[i][m * ndata + idata] = 0.0;
}
/* ----------------------------------------------------------------------
@ -306,8 +296,7 @@ void FixBondHistory::set_arrays(int i)
void FixBondHistory::delete_history(int i, int m)
{
double **stored = atom->darray[index];
for (int idata = 0; idata < ndata; idata ++)
stored[i][m*ndata+idata] = 0.0;
for (int idata = 0; idata < ndata; idata++) stored[i][m * ndata + idata] = 0.0;
}
/* ----------------------------------------------------------------------
@ -319,8 +308,8 @@ void FixBondHistory::shift_history(int i, int m, int k)
if (m == k) return;
double **stored = atom->darray[index];
for (int idata = 0; idata < ndata; idata ++)
stored[i][m*ndata+idata] = stored[i][k*ndata+idata];
for (int idata = 0; idata < ndata; idata++)
stored[i][m * ndata + idata] = stored[i][k * ndata + idata];
}
/* ----------------------------------------------------------------------
@ -334,16 +323,15 @@ void FixBondHistory::cache_history(int i, int m)
// Order tags to create a unique key pair
tagint max_tag = MAX(atom->tag[i], atom->bond_atom[i][m]);
tagint min_tag = MIN(atom->tag[i], atom->bond_atom[i][m]);
std::pair<tagint, tagint> key = std::make_pair(min_tag, max_tag);
auto key = std::make_pair(min_tag, max_tag);
// Copy data to vector
double **stored = atom->darray[index];
std::vector <double> data;
for (int idata = 0; idata < ndata; idata ++)
data.push_back(stored[i][m*ndata+idata]);
std::vector<double> data;
for (int idata = 0; idata < ndata; idata++) data.push_back(stored[i][m * ndata + idata]);
// Add data to cache
cached_histories.insert(std::make_pair(key,data));
cached_histories.insert(std::make_pair(key, data));
}
/* ----------------------------------------------------------------------
@ -355,16 +343,15 @@ void FixBondHistory::check_cache(int i, int m)
// Order tags to create a unique key pair
tagint max_tag = MAX(atom->tag[i], atom->bond_atom[i][m]);
tagint min_tag = MIN(atom->tag[i], atom->bond_atom[i][m]);
std::pair<tagint, tagint> key = std::make_pair(min_tag, max_tag);
auto key = std::make_pair(min_tag, max_tag);
// Check if it exists, if so, copy data
double **stored = atom->darray[index];
std::vector <double> data;
std::vector<double> data;
auto pos = cached_histories.find(key);
if (pos != cached_histories.end()) {
data = pos->second;
for (int idata = 0; idata < ndata; idata ++)
stored[i][m*ndata+idata] = data[idata];
for (int idata = 0; idata < ndata; idata++) stored[i][m * ndata + idata] = data[idata];
}
}

View File

@ -13,7 +13,7 @@
#ifdef FIX_CLASS
// clang-format off
FixStyle(BOND_HISTORY,FixBondHistory)
FixStyle(BOND_HISTORY,FixBondHistory);
// clang-format on
#else
@ -30,7 +30,6 @@ namespace LAMMPS_NS {
class FixBondHistory : public Fix {
public:
FixBondHistory(class LAMMPS *, int, char **);
~FixBondHistory() override;
int setmask() override;
@ -48,25 +47,24 @@ class FixBondHistory : public Fix {
double get_atom_value(int, int, int);
// methods to reorder/delete elements of atom->bond_atom
void delete_history(int,int);
void shift_history(int,int,int);
void cache_history(int,int);
void check_cache(int,int);
void delete_history(int, int);
void shift_history(int, int, int);
void cache_history(int, int);
void check_cache(int, int);
void clear_cache();
// if data is temporarily stored while the bond_atom array
// is being reordered, use map of vectors with pairs for keys
// to enable quick look up
std::map<std::pair<tagint, tagint>, std::vector <double>> cached_histories;
std::map<std::pair<tagint, tagint>, std::vector<double>> cached_histories;
double **bondstore;
int stored_flag;
protected:
void allocate();
int update_flag; //Flag whether history values can evolve
int update_flag; //Flag whether history values can evolve
int updated_bond_flag;
int nbond, maxbond, ndata;
int index;
@ -93,7 +91,4 @@ E: Cannot store bond variables without any bonds
Atoms must have a nonzero number of bonds to store data
*/

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -26,22 +25,21 @@
using namespace LAMMPS_NS;
using namespace FixConst;
enum{MOLECULE,CHARGE,RMASS,IVEC,DVEC,IARRAY,DARRAY};
enum { MOLECULE, CHARGE, RMASS, IVEC, DVEC, IARRAY, DARRAY };
/* ---------------------------------------------------------------------- */
FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg),
nvalue(0), styles(nullptr), index(nullptr), astyle(nullptr)
Fix(lmp, narg, arg), nvalue(0), styles(nullptr), index(nullptr), astyle(nullptr)
{
if (narg < 4) error->all(FLERR,"Illegal fix property/atom command");
if (narg < 4) error->all(FLERR, "Illegal fix property/atom command");
restart_peratom = 1;
wd_section = 1;
create_attribute = 1;
int iarg = 3;
nvalue = narg-iarg;
nvalue = narg - iarg;
styles = new int[nvalue];
cols = new int[nvalue];
index = new int[nvalue];
@ -54,33 +52,30 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) :
values_peratom = 0;
while (iarg < narg) {
if (strcmp(arg[iarg],"mol") == 0) {
if (strcmp(arg[iarg], "mol") == 0) {
if (atom->molecule_flag)
error->all(FLERR,"Fix property/atom mol when atom_style already has molecule attribute");
if (molecule_flag)
error->all(FLERR,"Fix property/atom cannot specify mol twice");
error->all(FLERR, "Fix property/atom mol when atom_style already has molecule attribute");
if (molecule_flag) error->all(FLERR, "Fix property/atom cannot specify mol twice");
styles[nvalue] = MOLECULE;
cols[nvalue] = 0;
atom->molecule_flag = molecule_flag = 1;
values_peratom++;
nvalue++;
iarg++;
} else if (strcmp(arg[iarg],"q") == 0) {
} else if (strcmp(arg[iarg], "q") == 0) {
if (atom->q_flag)
error->all(FLERR,"Fix property/atom q when atom_style already has charge attribute");
if (q_flag)
error->all(FLERR,"Fix property/atom cannot specify q twice");
error->all(FLERR, "Fix property/atom q when atom_style already has charge attribute");
if (q_flag) error->all(FLERR, "Fix property/atom cannot specify q twice");
styles[nvalue] = CHARGE;
cols[nvalue] = 0;
atom->q_flag = q_flag = 1;
values_peratom++;
nvalue++;
iarg++;
} else if (strcmp(arg[iarg],"rmass") == 0) {
} else if (strcmp(arg[iarg], "rmass") == 0) {
if (atom->rmass_flag)
error->all(FLERR,"Fix property/atom rmass when atom_style already has rmass attribute");
if (rmass_flag)
error->all(FLERR,"Fix property/atom cannot specify rmass twice");
error->all(FLERR, "Fix property/atom rmass when atom_style already has rmass attribute");
if (rmass_flag) error->all(FLERR, "Fix property/atom cannot specify rmass twice");
styles[nvalue] = RMASS;
cols[nvalue] = 0;
atom->rmass_flag = rmass_flag = 1;
@ -88,51 +83,49 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) :
nvalue++;
iarg++;
// custom atom vector
// custom atom vector
} else if (utils::strmatch(arg[iarg],"^i_")) {
} else if (utils::strmatch(arg[iarg], "^i_")) {
styles[nvalue] = IVEC;
int flag,ncols;
index[nvalue] = atom->find_custom(&arg[iarg][2],flag,ncols);
if (index[nvalue] >= 0)
error->all(FLERR,"Fix property/atom vector name already exists");
int flag, ncols;
index[nvalue] = atom->find_custom(&arg[iarg][2], flag, ncols);
if (index[nvalue] >= 0) error->all(FLERR, "Fix property/atom vector name already exists");
if (ReadData::is_data_section(id))
error->all(FLERR,"Fix property/atom fix ID must not be a data file section name");
index[nvalue] = atom->add_custom(&arg[iarg][2],0,0);
error->all(FLERR, "Fix property/atom fix ID must not be a data file section name");
index[nvalue] = atom->add_custom(&arg[iarg][2], 0, 0);
cols[nvalue] = 0;
values_peratom++;
nvalue++;
iarg++;
} else if (utils::strmatch(arg[iarg],"^d_")) {
} else if (utils::strmatch(arg[iarg], "^d_")) {
styles[nvalue] = DVEC;
int flag,ncols;
index[nvalue] = atom->find_custom(&arg[iarg][2],flag,ncols);
if (index[nvalue] >= 0)
error->all(FLERR,"Fix property/atom vector name already exists");
int flag, ncols;
index[nvalue] = atom->find_custom(&arg[iarg][2], flag, ncols);
if (index[nvalue] >= 0) error->all(FLERR, "Fix property/atom vector name already exists");
if (ReadData::is_data_section(id))
error->all(FLERR,"Fix property/atom fix ID must not be a data file section name");
index[nvalue] = atom->add_custom(&arg[iarg][2],1,0);
error->all(FLERR, "Fix property/atom fix ID must not be a data file section name");
index[nvalue] = atom->add_custom(&arg[iarg][2], 1, 0);
cols[nvalue] = 0;
values_peratom++;
nvalue++;
iarg++;
// custom atom array
// custom atom array
} else if (utils::strmatch(arg[iarg],"^[id]2_")) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix property/atom command");
} else if (utils::strmatch(arg[iarg], "^[id]2_")) {
if (iarg + 2 > narg) error->all(FLERR, "Illegal fix property/atom command");
int which,flag,ncols;
which = atom->find_custom(&arg[iarg][3],flag,ncols);
int which, flag, ncols;
which = atom->find_custom(&arg[iarg][3], flag, ncols);
if (which >= 0)
error->all(FLERR,"Fix property/atom array name {} already exists", &arg[iarg][3]);
error->all(FLERR, "Fix property/atom array name {} already exists", &arg[iarg][3]);
if (ReadData::is_data_section(id))
error->all(FLERR,"Fix property/atom fix ID must not be a data file section name");
error->all(FLERR, "Fix property/atom fix ID must not be a data file section name");
ncols = utils::inumeric(FLERR,arg[iarg+1],true,lmp);
ncols = utils::inumeric(FLERR, arg[iarg + 1], true, lmp);
if (ncols < 1)
error->all(FLERR,"Invalid array columns number {} in fix property/atom", ncols);
error->all(FLERR, "Invalid array columns number {} in fix property/atom", ncols);
if (arg[iarg][0] == 'i') {
which = 0;
@ -141,26 +134,28 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) :
which = 1;
styles[nvalue] = DARRAY;
}
index[nvalue] = atom->add_custom(&arg[iarg][3],which,ncols);
index[nvalue] = atom->add_custom(&arg[iarg][3], which, ncols);
cols[nvalue] = ncols;
values_peratom += ncols;
nvalue++;
iarg += 2;
// no match
// no match
} else break;
} else
break;
}
// optional args
border = 0;
while (iarg < narg) {
if (strcmp(arg[iarg],"ghost") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix property/atom command");
border = utils::logical(FLERR,arg[iarg+1],false,lmp);
if (strcmp(arg[iarg], "ghost") == 0) {
if (iarg + 2 > narg) error->all(FLERR, "Illegal fix property/atom command");
border = utils::logical(FLERR, arg[iarg + 1], false, lmp);
iarg += 2;
} else error->all(FLERR,"Illegal fix property/atom command");
} else
error->all(FLERR, "Illegal fix property/atom command");
}
if (border) comm_border = values_peratom;
@ -170,12 +165,9 @@ FixPropertyAtom::FixPropertyAtom(LAMMPS *lmp, int narg, char **arg) :
if (border == 0) {
int flag = 0;
for (int i = 0; i < nvalue; i++)
if (styles[i] == MOLECULE
|| styles[i] == CHARGE
|| styles[i] == RMASS) flag = 1;
if (styles[i] == MOLECULE || styles[i] == CHARGE || styles[i] == RMASS) flag = 1;
if (flag && comm->me == 0)
error->warning(FLERR,"Fix property/atom mol or charge or rmass "
"w/out ghost communication");
error->warning(FLERR, "Fix property/atom mol or charge or rmass w/out ghost communication");
}
// store current atom style
@ -198,9 +190,9 @@ FixPropertyAtom::~FixPropertyAtom()
{
// unregister callbacks to this fix from Atom class
atom->delete_callback(id,Atom::GROW);
atom->delete_callback(id,Atom::RESTART);
if (border) atom->delete_callback(id,Atom::BORDER);
atom->delete_callback(id, Atom::GROW);
atom->delete_callback(id, Atom::RESTART);
if (border) atom->delete_callback(id, Atom::BORDER);
// deallocate per-atom vectors in Atom class
// set ptrs to a null pointer, so they no longer exist for Atom class
@ -219,20 +211,20 @@ FixPropertyAtom::~FixPropertyAtom()
memory->destroy(atom->rmass);
atom->rmass = nullptr;
} else if (styles[nv] == IVEC) {
atom->remove_custom(index[nv],0,cols[nv]);
atom->remove_custom(index[nv], 0, cols[nv]);
} else if (styles[nv] == DVEC) {
atom->remove_custom(index[nv],1,cols[nv]);
atom->remove_custom(index[nv], 1, cols[nv]);
} else if (styles[nv] == IARRAY) {
atom->remove_custom(index[nv],0,cols[nv]);
atom->remove_custom(index[nv], 0, cols[nv]);
} else if (styles[nv] == DARRAY) {
atom->remove_custom(index[nv],1,cols[nv]);
atom->remove_custom(index[nv], 1, cols[nv]);
}
}
delete [] styles;
delete [] cols;
delete [] index;
delete [] astyle;
delete[] styles;
delete[] cols;
delete[] index;
delete[] astyle;
}
/* ---------------------------------------------------------------------- */
@ -250,8 +242,8 @@ void FixPropertyAtom::init()
// error if atom style has changed since fix was defined
// don't allow this because user could change to style that defines molecule,q
if (strcmp(astyle,atom->atom_style) != 0)
error->all(FLERR,"Atom style was redefined after using fix property/atom");
if (strcmp(astyle, atom->atom_style) != 0)
error->all(FLERR, "Atom style was redefined after using fix property/atom");
}
/* ----------------------------------------------------------------------
@ -261,7 +253,7 @@ void FixPropertyAtom::init()
void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, tagint id_offset)
{
int j,k,m,ncol;
int j, k, m, ncol;
tagint itag;
char *next;
@ -279,18 +271,18 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, tagint
tagint map_tag_max = atom->map_tag_max;
for (int i = 0; i < n; i++) {
next = strchr(buf,'\n');
next = strchr(buf, '\n');
*next = '\0';
try {
ValueTokenizer values(buf);
if ((int)values.count() != values_peratom+1)
error->all(FLERR,"Incorrect format in {} section of data file: {}"
" expected {} and got {}",keyword,buf,values_peratom+1,values.count());
if ((int) values.count() != values_peratom + 1)
error->all(FLERR, "Incorrect format in {} section of data file: {} expected {} and got {}",
keyword, buf, values_peratom + 1, values.count());
itag = values.next_tagint() + id_offset;
if (itag <= 0 || itag > map_tag_max)
error->all(FLERR,"Invalid atom ID {} in {} section of data file",itag, keyword);
error->all(FLERR, "Invalid atom ID {} in {} section of data file", itag, keyword);
// assign words in line to per-atom vectors
@ -308,17 +300,16 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, tagint
atom->dvector[index[j]][m] = values.next_double();
} else if (styles[j] == IARRAY) {
ncol = cols[j];
for (k = 0; k < ncol; k++)
atom->iarray[index[j]][m][k] = values.next_int();
for (k = 0; k < ncol; k++) atom->iarray[index[j]][m][k] = values.next_int();
} else if (styles[j] == DARRAY) {
ncol = cols[j];
for (k = 0; k < ncol; k++)
atom->darray[index[j]][m][k] = values.next_double();
for (k = 0; k < ncol; k++) atom->darray[index[j]][m][k] = values.next_double();
}
}
}
} catch (TokenizerException &e) {
error->all(FLERR,"Invalid format in {} section of data file '{}': {}",keyword, buf,e.what());
error->all(FLERR, "Invalid format in {} section of data file '{}': {}", keyword, buf,
e.what());
}
buf = next + 1;
}
@ -358,7 +349,7 @@ void FixPropertyAtom::write_data_section_size(int /*mth*/, int &nx, int &ny)
void FixPropertyAtom::write_data_section_pack(int /*mth*/, double **buf)
{
int i,k,ncol;
int i, k, ncol;
// 1st column = atom tag
// rest of columns = per-atom values
@ -394,15 +385,13 @@ void FixPropertyAtom::write_data_section_pack(int /*mth*/, double **buf)
int **iarray = atom->iarray[index[nv]];
ncol = cols[nv];
for (i = 0; i < nlocal; i++)
for (k = 0; k < ncol; k++)
buf[i][icol+k] = ubuf(iarray[i][k]).d;
for (k = 0; k < ncol; k++) buf[i][icol + k] = ubuf(iarray[i][k]).d;
icol += ncol;
} else if (styles[nv] == DARRAY) {
double **darray = atom->darray[index[nv]];
ncol = cols[nv];
for (i = 0; i < nlocal; i++)
for (k = 0; k < ncol; k++)
buf[i][icol+k] = darray[i][k];
for (k = 0; k < ncol; k++) buf[i][icol + k] = darray[i][k];
icol += ncol;
}
}
@ -417,21 +406,30 @@ void FixPropertyAtom::write_data_section_pack(int /*mth*/, double **buf)
void FixPropertyAtom::write_data_section_keyword(int /*mth*/, FILE *fp)
{
if (nvalue == 1 && styles[0] == MOLECULE) fprintf(fp,"\nMolecules\n\n");
else if (nvalue == 1 && styles[0] == CHARGE) fprintf(fp,"\nCharges\n\n");
if (nvalue == 1 && styles[0] == MOLECULE)
fprintf(fp, "\nMolecules\n\n");
else if (nvalue == 1 && styles[0] == CHARGE)
fprintf(fp, "\nCharges\n\n");
else {
fprintf(fp,"\n%s #",id);
fprintf(fp, "\n%s #", id);
// write column hint as comment
for (int i = 0; i < nvalue; ++i) {
if (styles[i] == MOLECULE) fputs(" mol",fp);
else if (styles[i] == CHARGE) fputs(" q",fp);
else if (styles[i] == RMASS) fputs(" rmass",fp);
else if (styles[i] == IVEC) fprintf(fp," i_%s", atom->ivname[index[i]]);
else if (styles[i] == DVEC) fprintf(fp, " d_%s", atom->dvname[index[i]]);
else if (styles[i] == IARRAY) fprintf(fp, " i_%s", atom->ianame[index[i]]);
else if (styles[i] == DARRAY) fprintf(fp, " d_%s", atom->daname[index[i]]);
if (styles[i] == MOLECULE)
fputs(" mol", fp);
else if (styles[i] == CHARGE)
fputs(" q", fp);
else if (styles[i] == RMASS)
fputs(" rmass", fp);
else if (styles[i] == IVEC)
fprintf(fp, " i_%s", atom->ivname[index[i]]);
else if (styles[i] == DVEC)
fprintf(fp, " d_%s", atom->dvname[index[i]]);
else if (styles[i] == IARRAY)
fprintf(fp, " i_%s", atom->ianame[index[i]]);
else if (styles[i] == DARRAY)
fprintf(fp, " d_%s", atom->daname[index[i]]);
}
fputs("\n\n",fp);
fputs("\n\n", fp);
}
}
@ -442,39 +440,36 @@ void FixPropertyAtom::write_data_section_keyword(int /*mth*/, FILE *fp)
only called by proc 0
------------------------------------------------------------------------- */
void FixPropertyAtom::write_data_section(int /*mth*/, FILE *fp,
int n, double **buf, int /*index*/)
void FixPropertyAtom::write_data_section(int /*mth*/, FILE *fp, int n, double **buf, int /*index*/)
{
int k,icol,ncol,nv;
int k, icol, ncol, nv;
std::string line;
for (int i = 0; i < n; i++) {
line = fmt::format("{}",(tagint) ubuf(buf[i][0]).i);
line = fmt::format("{}", (tagint) ubuf(buf[i][0]).i);
icol = 1;
for (nv = 0; nv < nvalue; nv++) {
if (styles[nv] == MOLECULE)
line += fmt::format(" {}",(tagint) ubuf(buf[i][icol++]).i);
line += fmt::format(" {}", (tagint) ubuf(buf[i][icol++]).i);
else if (styles[nv] == CHARGE)
line += fmt::format(" {}",buf[i][icol++]);
line += fmt::format(" {}", buf[i][icol++]);
else if (styles[nv] == RMASS)
line += fmt::format(" {}",buf[i][icol++]);
line += fmt::format(" {}", buf[i][icol++]);
else if (styles[nv] == IVEC)
line += fmt::format(" {}",(int) ubuf(buf[i][icol++]).i);
line += fmt::format(" {}", (int) ubuf(buf[i][icol++]).i);
else if (styles[nv] == DVEC)
line += fmt::format(" {}",buf[i][icol++]);
line += fmt::format(" {}", buf[i][icol++]);
else if (styles[nv] == IARRAY) {
ncol = cols[nv];
for (k = 0; k < ncol; k++)
line += fmt::format(" {}",(int) ubuf(buf[i][icol+k]).i);
for (k = 0; k < ncol; k++) line += fmt::format(" {}", (int) ubuf(buf[i][icol + k]).i);
icol += ncol;
} else if (styles[nv] == DARRAY) {
ncol = cols[nv];
for (k = 0; k < ncol; k++)
line += fmt::format(" {}",buf[i][icol+k]);
for (k = 0; k < ncol; k++) line += fmt::format(" {}", buf[i][icol + k]);
icol += ncol;
}
}
fmt::print(fp,line+"\n");
fmt::print(fp, line + "\n");
}
}
@ -486,13 +481,20 @@ double FixPropertyAtom::memory_usage()
{
double bytes = 0.0;
for (int m = 0; m < nvalue; m++) {
if (styles[m] == MOLECULE) bytes = atom->nmax * sizeof(tagint);
else if (styles[m] == CHARGE) bytes = atom->nmax * sizeof(double);
else if (styles[m] == RMASS) bytes = atom->nmax * sizeof(double);
else if (styles[m] == IVEC) bytes = atom->nmax * sizeof(int);
else if (styles[m] == DVEC) bytes = atom->nmax * sizeof(double);
else if (styles[m] == IARRAY) bytes = (size_t) atom->nmax * cols[m] * sizeof(int);
else if (styles[m] == DARRAY) bytes = (size_t) atom->nmax * cols[m] * sizeof(double);
if (styles[m] == MOLECULE)
bytes = atom->nmax * sizeof(tagint);
else if (styles[m] == CHARGE)
bytes = atom->nmax * sizeof(double);
else if (styles[m] == RMASS)
bytes = atom->nmax * sizeof(double);
else if (styles[m] == IVEC)
bytes = atom->nmax * sizeof(int);
else if (styles[m] == DVEC)
bytes = atom->nmax * sizeof(double);
else if (styles[m] == IARRAY)
bytes = (size_t) atom->nmax * cols[m] * sizeof(int);
else if (styles[m] == DARRAY)
bytes = (size_t) atom->nmax * cols[m] * sizeof(double);
}
return bytes;
}
@ -508,33 +510,33 @@ void FixPropertyAtom::grow_arrays(int nmax)
{
for (int nv = 0; nv < nvalue; nv++) {
if (styles[nv] == MOLECULE) {
memory->grow(atom->molecule,nmax,"atom:molecule");
size_t nbytes = (nmax-nmax_old) * sizeof(tagint);
memset(&atom->molecule[nmax_old],0,nbytes);
memory->grow(atom->molecule, nmax, "atom:molecule");
size_t nbytes = (nmax - nmax_old) * sizeof(tagint);
memset(&atom->molecule[nmax_old], 0, nbytes);
} else if (styles[nv] == CHARGE) {
memory->grow(atom->q,nmax,"atom:q");
size_t nbytes = (nmax-nmax_old) * sizeof(double);
memset(&atom->q[nmax_old],0,nbytes);
memory->grow(atom->q, nmax, "atom:q");
size_t nbytes = (nmax - nmax_old) * sizeof(double);
memset(&atom->q[nmax_old], 0, nbytes);
} else if (styles[nv] == RMASS) {
memory->grow(atom->rmass,nmax,"atom:rmass");
size_t nbytes = (nmax-nmax_old) * sizeof(double);
memset(&atom->rmass[nmax_old],0,nbytes);
memory->grow(atom->rmass, nmax, "atom:rmass");
size_t nbytes = (nmax - nmax_old) * sizeof(double);
memset(&atom->rmass[nmax_old], 0, nbytes);
} else if (styles[nv] == IVEC) {
memory->grow(atom->ivector[index[nv]],nmax,"atom:ivector");
size_t nbytes = (nmax-nmax_old) * sizeof(int);
memset(&atom->ivector[index[nv]][nmax_old],0,nbytes);
memory->grow(atom->ivector[index[nv]], nmax, "atom:ivector");
size_t nbytes = (nmax - nmax_old) * sizeof(int);
memset(&atom->ivector[index[nv]][nmax_old], 0, nbytes);
} else if (styles[nv] == DVEC) {
memory->grow(atom->dvector[index[nv]],nmax,"atom:dvector");
size_t nbytes = (nmax-nmax_old) * sizeof(double);
memset(&atom->dvector[index[nv]][nmax_old],0,nbytes);
memory->grow(atom->dvector[index[nv]], nmax, "atom:dvector");
size_t nbytes = (nmax - nmax_old) * sizeof(double);
memset(&atom->dvector[index[nv]][nmax_old], 0, nbytes);
} else if (styles[nv] == IARRAY) {
memory->grow(atom->iarray[index[nv]],nmax,cols[nv],"atom:iarray");
size_t nbytes = (size_t) (nmax-nmax_old) * cols[nv] * sizeof(int);
if (nbytes) memset(&atom->iarray[index[nv]][nmax_old][0],0,nbytes);
memory->grow(atom->iarray[index[nv]], nmax, cols[nv], "atom:iarray");
size_t nbytes = (size_t) (nmax - nmax_old) * cols[nv] * sizeof(int);
if (nbytes) memset(&atom->iarray[index[nv]][nmax_old][0], 0, nbytes);
} else if (styles[nv] == DARRAY) {
memory->grow(atom->darray[index[nv]],nmax,cols[nv],"atom:darray");
size_t nbytes = (size_t) (nmax-nmax_old) * cols[nv] * sizeof(double);
if (nbytes) memset(&atom->darray[index[nv]][nmax_old][0],0,nbytes);
memory->grow(atom->darray[index[nv]], nmax, cols[nv], "atom:darray");
size_t nbytes = (size_t) (nmax - nmax_old) * cols[nv] * sizeof(double);
if (nbytes) memset(&atom->darray[index[nv]][nmax_old][0], 0, nbytes);
}
}
@ -547,7 +549,7 @@ void FixPropertyAtom::grow_arrays(int nmax)
void FixPropertyAtom::copy_arrays(int i, int j, int /*delflag*/)
{
int k,ncol;
int k, ncol;
for (int nv = 0; nv < nvalue; nv++) {
if (styles[nv] == MOLECULE)
@ -562,24 +564,21 @@ void FixPropertyAtom::copy_arrays(int i, int j, int /*delflag*/)
atom->dvector[index[nv]][j] = atom->dvector[index[nv]][i];
else if (styles[nv] == IARRAY) {
ncol = cols[nv];
for (k = 0; k < ncol; k++)
atom->iarray[index[nv]][j][k] = atom->iarray[index[nv]][i][k];
for (k = 0; k < ncol; k++) atom->iarray[index[nv]][j][k] = atom->iarray[index[nv]][i][k];
} else if (styles[nv] == DARRAY) {
ncol = cols[nv];
for (k = 0; k < ncol; k++)
atom->darray[index[nv]][j][k] = atom->darray[index[nv]][i][k];
for (k = 0; k < ncol; k++) atom->darray[index[nv]][j][k] = atom->darray[index[nv]][i][k];
}
}
}
/* ----------------------------------------------------------------------
initialize one atom's storage values, called when atom is created
------------------------------------------------------------------------- */
void FixPropertyAtom::set_arrays(int i)
{
int k,ncol;
int k, ncol;
for (int nv = 0; nv < nvalue; nv++) {
if (styles[nv] == IVEC)
@ -588,12 +587,10 @@ void FixPropertyAtom::set_arrays(int i)
atom->dvector[index[nv]][i] = 0.0;
else if (styles[nv] == IARRAY) {
ncol = cols[nv];
for (k = 0; k < ncol; k++)
atom->iarray[index[nv]][i][k] = 0;
for (k = 0; k < ncol; k++) atom->iarray[index[nv]][i][k] = 0;
} else if (styles[nv] == DARRAY) {
ncol = cols[nv];
for (k = 0; k < ncol; k++)
atom->darray[index[nv]][i][k] = 0.0;
for (k = 0; k < ncol; k++) atom->darray[index[nv]][i][k] = 0.0;
}
}
}
@ -604,7 +601,7 @@ void FixPropertyAtom::set_arrays(int i)
int FixPropertyAtom::pack_border(int n, int *list, double *buf)
{
int i,j,k,ncol;
int i, j, k, ncol;
int m = 0;
for (int nv = 0; nv < nvalue; nv++) {
@ -643,16 +640,14 @@ int FixPropertyAtom::pack_border(int n, int *list, double *buf)
ncol = cols[nv];
for (i = 0; i < n; i++) {
j = list[i];
for (k = 0; k < ncol; k++)
buf[m++] = ubuf(iarray[j][k]).d;
for (k = 0; k < ncol; k++) buf[m++] = ubuf(iarray[j][k]).d;
}
} else if (styles[nv] == DARRAY) {
double **darray = atom->darray[index[nv]];
ncol = cols[nv];
for (i = 0; i < n; i++) {
j = list[i];
for (k = 0; k < ncol; k++)
buf[m++] = darray[j][k];
for (k = 0; k < ncol; k++) buf[m++] = darray[j][k];
}
}
}
@ -666,49 +661,42 @@ int FixPropertyAtom::pack_border(int n, int *list, double *buf)
int FixPropertyAtom::unpack_border(int n, int first, double *buf)
{
int i,k,last,ncol;
int i, k, last, ncol;
int m = 0;
for (int nv = 0; nv < nvalue; nv++) {
if (styles[nv] == MOLECULE) {
tagint *molecule = atom->molecule;
last = first + n;
for (i = first; i < last; i++)
molecule[i] = (tagint) ubuf(buf[m++]).i;
for (i = first; i < last; i++) molecule[i] = (tagint) ubuf(buf[m++]).i;
} else if (styles[nv] == CHARGE) {
double *q = atom->q;
last = first + n;
for (i = first; i < last; i++)
q[i] = buf[m++];
for (i = first; i < last; i++) q[i] = buf[m++];
} else if (styles[nv] == RMASS) {
double *rmass = atom->rmass;
last = first + n;
for (i = first; i < last; i++)
rmass[i] = buf[m++];
for (i = first; i < last; i++) rmass[i] = buf[m++];
} else if (styles[nv] == IVEC) {
int *ivector = atom->ivector[index[nv]];
last = first + n;
for (i = first; i < last; i++)
ivector[i] = (int) ubuf(buf[m++]).i;
for (i = first; i < last; i++) ivector[i] = (int) ubuf(buf[m++]).i;
} else if (styles[nv] == DVEC) {
double *dvector = atom->dvector[index[nv]];
last = first + n;
for (i = first; i < last; i++)
dvector[i] = buf[m++];
for (i = first; i < last; i++) dvector[i] = buf[m++];
} else if (styles[nv] == IARRAY) {
int **iarray = atom->iarray[index[nv]];
ncol = cols[nv];
last = first + n;
for (i = first; i < last; i++)
for (k = 0; k < ncol; k++)
iarray[i][k] = (int) ubuf(buf[m++]).i;
for (k = 0; k < ncol; k++) iarray[i][k] = (int) ubuf(buf[m++]).i;
} else if (styles[nv] == DARRAY) {
double **darray = atom->darray[index[nv]];
ncol = cols[nv];
last = first + n;
for (i = first; i < last; i++)
for (k = 0; k < ncol; k++)
darray[i][k] = buf[m++];
for (k = 0; k < ncol; k++) darray[i][k] = buf[m++];
}
}
@ -721,23 +709,26 @@ int FixPropertyAtom::unpack_border(int n, int first, double *buf)
int FixPropertyAtom::pack_exchange(int i, double *buf)
{
int k,ncol;
int k, ncol;
int m = 0;
for (int nv = 0; nv < nvalue; nv++) {
if (styles[nv] == MOLECULE) buf[m++] = ubuf(atom->molecule[i]).d;
else if (styles[nv] == CHARGE) buf[m++] = atom->q[i];
else if (styles[nv] == RMASS) buf[m++] = atom->rmass[i];
else if (styles[nv] == IVEC) buf[m++] = ubuf(atom->ivector[index[nv]][i]).d;
else if (styles[nv] == DVEC) buf[m++] = atom->dvector[index[nv]][i];
if (styles[nv] == MOLECULE)
buf[m++] = ubuf(atom->molecule[i]).d;
else if (styles[nv] == CHARGE)
buf[m++] = atom->q[i];
else if (styles[nv] == RMASS)
buf[m++] = atom->rmass[i];
else if (styles[nv] == IVEC)
buf[m++] = ubuf(atom->ivector[index[nv]][i]).d;
else if (styles[nv] == DVEC)
buf[m++] = atom->dvector[index[nv]][i];
else if (styles[nv] == IARRAY) {
ncol = cols[nv];
for (k = 0; k < ncol; k++)
buf[m++] = ubuf(atom->iarray[index[nv]][i][k]).d;
for (k = 0; k < ncol; k++) buf[m++] = ubuf(atom->iarray[index[nv]][i][k]).d;
} else if (styles[nv] == DARRAY) {
ncol = cols[nv];
for (k = 0; k < ncol; k++)
buf[m++] = atom->darray[index[nv]][i][k];
for (k = 0; k < ncol; k++) buf[m++] = atom->darray[index[nv]][i][k];
}
}
@ -750,7 +741,7 @@ int FixPropertyAtom::pack_exchange(int i, double *buf)
int FixPropertyAtom::unpack_exchange(int nlocal, double *buf)
{
int k,ncol;
int k, ncol;
int m = 0;
for (int nv = 0; nv < nvalue; nv++) {
@ -766,12 +757,10 @@ int FixPropertyAtom::unpack_exchange(int nlocal, double *buf)
atom->dvector[index[nv]][nlocal] = buf[m++];
else if (styles[nv] == IARRAY) {
ncol = cols[nv];
for (k = 0; k < ncol; k++)
atom->iarray[index[nv]][nlocal][k] = (int) ubuf(buf[m++]).i;
for (k = 0; k < ncol; k++) atom->iarray[index[nv]][nlocal][k] = (int) ubuf(buf[m++]).i;
} else if (styles[nv] == DARRAY) {
ncol = cols[nv];
for (k = 0; k < ncol; k++)
atom->darray[index[nv]][nlocal][k] = buf[m++];
for (k = 0; k < ncol; k++) atom->darray[index[nv]][nlocal][k] = buf[m++];
}
}
@ -784,31 +773,34 @@ int FixPropertyAtom::unpack_exchange(int nlocal, double *buf)
int FixPropertyAtom::pack_restart(int i, double *buf)
{
int k,ncol;
int k, ncol;
// pack buf[0] this way because other fixes unpack it
buf[0] = values_peratom+1;
buf[0] = values_peratom + 1;
int m = 1;
for (int nv = 0; nv < nvalue; nv++) {
if (styles[nv] == MOLECULE) buf[m++] = ubuf(atom->molecule[i]).d;
else if (styles[nv] == CHARGE) buf[m++] = atom->q[i];
else if (styles[nv] == RMASS) buf[m++] = atom->rmass[i];
else if (styles[nv] == IVEC) buf[m++] = ubuf(atom->ivector[index[nv]][i]).d;
else if (styles[nv] == DVEC) buf[m++] = atom->dvector[index[nv]][i];
if (styles[nv] == MOLECULE)
buf[m++] = ubuf(atom->molecule[i]).d;
else if (styles[nv] == CHARGE)
buf[m++] = atom->q[i];
else if (styles[nv] == RMASS)
buf[m++] = atom->rmass[i];
else if (styles[nv] == IVEC)
buf[m++] = ubuf(atom->ivector[index[nv]][i]).d;
else if (styles[nv] == DVEC)
buf[m++] = atom->dvector[index[nv]][i];
else if (styles[nv] == IARRAY) {
ncol = cols[nv];
for (k = 0; k < ncol; k++)
buf[m++] = ubuf(atom->iarray[index[nv]][i][k]).d;
for (k = 0; k < ncol; k++) buf[m++] = ubuf(atom->iarray[index[nv]][i][k]).d;
} else if (styles[nv] == DARRAY) {
ncol = cols[nv];
for (k = 0; k < ncol; k++)
buf[m++] = atom->darray[index[nv]][i][k];
for (k = 0; k < ncol; k++) buf[m++] = atom->darray[index[nv]][i][k];
}
}
return values_peratom+1;
return values_peratom + 1;
}
/* ----------------------------------------------------------------------
@ -817,14 +809,14 @@ int FixPropertyAtom::pack_restart(int i, double *buf)
void FixPropertyAtom::unpack_restart(int nlocal, int nth)
{
int k,ncol;
int k, ncol;
double **extra = atom->extra;
// skip to Nth set of extra values
// unpack the Nth first values this way because other fixes pack them
int m = 0;
for (int i = 0; i < nth; i++) m += static_cast<int> (extra[nlocal][m]);
for (int i = 0; i < nth; i++) m += static_cast<int>(extra[nlocal][m]);
m++;
for (int nv = 0; nv < nvalue; nv++) {
@ -844,8 +836,7 @@ void FixPropertyAtom::unpack_restart(int nlocal, int nth)
atom->iarray[index[nv]][nlocal][k] = (int) ubuf(extra[nlocal][m++]).i;
} else if (styles[nv] == DARRAY) {
ncol = cols[nv];
for (k = 0; k < ncol; k++)
atom->darray[index[nv]][nlocal][k] = extra[nlocal][m++];
for (k = 0; k < ncol; k++) atom->darray[index[nv]][nlocal][k] = extra[nlocal][m++];
}
}
}
@ -856,7 +847,7 @@ void FixPropertyAtom::unpack_restart(int nlocal, int nth)
int FixPropertyAtom::maxsize_restart()
{
return values_peratom+1;
return values_peratom + 1;
}
/* ----------------------------------------------------------------------
@ -865,5 +856,5 @@ int FixPropertyAtom::maxsize_restart()
int FixPropertyAtom::size_restart(int /*nlocal*/)
{
return values_peratom+1;
return values_peratom + 1;
}

View File

@ -123,4 +123,3 @@ double FixStoreLocal::memory_usage()
double bytes = (double) nmax * (double) nvalues * sizeof(double);
return bytes;
}

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -16,15 +15,12 @@
#include "atom.h"
#include "atom_vec.h"
#include "comm.h"
#include "error.h"
#include "force.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "neighbor.h"
#include "pair.h"
#include <cstring>
#include <vector>
#include <utility>
using namespace LAMMPS_NS;
@ -33,15 +29,9 @@ using namespace FixConst;
/* ---------------------------------------------------------------------- */
FixUpdateSpecialBonds::FixUpdateSpecialBonds(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg)
{
if (narg != 3) error->all(FLERR,"Illegal fix update/special/bonds command");
}
/* ---------------------------------------------------------------------- */
FixUpdateSpecialBonds::~FixUpdateSpecialBonds()
Fix(lmp, narg, arg)
{
if (narg != 3) error->all(FLERR, "Illegal fix update/special/bonds command");
}
/* ---------------------------------------------------------------------- */
@ -59,21 +49,18 @@ int FixUpdateSpecialBonds::setmask()
void FixUpdateSpecialBonds::setup(int /*vflag*/)
{
// Require atoms know about all of their bonds and if they break
if (force->newton_bond)
error->all(FLERR,"Fix update/special/bonds requires Newton bond off");
if (force->newton_bond) error->all(FLERR, "Fix update/special/bonds requires Newton bond off");
if (!atom->avec->bonds_allow)
error->all(FLERR,"Fix update/special/bonds requires atom bonds");
if (!atom->avec->bonds_allow) error->all(FLERR, "Fix update/special/bonds requires atom bonds");
// special lj must be 0 1 1 to censor pair forces between bonded particles
// special coulomb must be 1 1 1 to ensure all pairs are included in the
// neighbor list and 1-3 and 1-4 special bond lists are skipped
if (force->special_lj[1] != 0.0 || force->special_lj[2] != 1.0 ||
force->special_lj[3] != 1.0)
error->all(FLERR,"Fix update/special/bonds requires special LJ weights = 0,1,1");
if (force->special_lj[1] != 0.0 || force->special_lj[2] != 1.0 || force->special_lj[3] != 1.0)
error->all(FLERR, "Fix update/special/bonds requires special LJ weights = 0,1,1");
if (force->special_coul[1] != 1.0 || force->special_coul[2] != 1.0 ||
force->special_coul[3] != 1.0)
error->all(FLERR,"Fix update/special/bonds requires special Coulomb weights = 1,1,1");
error->all(FLERR, "Fix update/special/bonds requires special Coulomb weights = 1,1,1");
new_broken_pairs.clear();
broken_pairs.clear();
@ -107,7 +94,7 @@ void FixUpdateSpecialBonds::pre_exchange()
for (m = 0; m < n1; m++)
if (slist[m] == tagj) break;
n3 = nspecial[i][2];
for (; m < n3-1; m++) slist[m] = slist[m+1];
for (; m < n3 - 1; m++) slist[m] = slist[m + 1];
nspecial[i][0]--;
nspecial[i][1]--;
nspecial[i][2]--;
@ -119,7 +106,7 @@ void FixUpdateSpecialBonds::pre_exchange()
for (m = 0; m < n1; m++)
if (slist[m] == tagi) break;
n3 = nspecial[j][2];
for (; m < n3-1; m++) slist[m] = slist[m+1];
for (; m < n3 - 1; m++) slist[m] = slist[m + 1];
nspecial[j][0]--;
nspecial[j][1]--;
nspecial[j][2]--;
@ -135,14 +122,14 @@ void FixUpdateSpecialBonds::pre_exchange()
void FixUpdateSpecialBonds::pre_force(int /*vflag*/)
{
int i1,i2,j,jj,jnum;
int *jlist,*numneigh,**firstneigh;
int i1, i2, j, jj, jnum;
int *jlist, *numneigh, **firstneigh;
tagint tag1, tag2;
int nlocal = atom->nlocal;
tagint *tag = atom->tag;
NeighList *list = force->pair->list; // may need to be generalized to work with pair hybrid*
NeighList *list = force->pair->list; // may need to be generalized to work with pair hybrid*
numneigh = list->numneigh;
firstneigh = list->firstneigh;
@ -161,9 +148,8 @@ void FixUpdateSpecialBonds::pre_force(int /*vflag*/)
jnum = numneigh[i1];
for (jj = 0; jj < jnum; jj++) {
j = jlist[jj];
j &= SPECIALMASK; // Clear special bond bits
if (tag[j] == tag2)
jlist[jj] = j;
j &= SPECIALMASK; // Clear special bond bits
if (tag[j] == tag2) jlist[jj] = j;
}
}
@ -172,13 +158,11 @@ void FixUpdateSpecialBonds::pre_force(int /*vflag*/)
jnum = numneigh[i2];
for (jj = 0; jj < jnum; jj++) {
j = jlist[jj];
j &= SPECIALMASK; // Clear special bond bits
if (tag[j] == tag1)
jlist[jj] = j;
j &= SPECIALMASK; // Clear special bond bits
if (tag[j] == tag1) jlist[jj] = j;
}
}
}
new_broken_pairs.clear();
}
@ -186,9 +170,7 @@ void FixUpdateSpecialBonds::pre_force(int /*vflag*/)
void FixUpdateSpecialBonds::add_broken_bond(int i, int j)
{
tagint *tag = atom->tag;
std::pair <tagint, tagint> tag_pair = std::make_pair(tag[i],tag[j]);
auto tag_pair = std::make_pair(atom->tag[i], atom->tag[j]);
new_broken_pairs.push_back(tag_pair);
broken_pairs.push_back(tag_pair);
}

View File

@ -13,7 +13,7 @@
#ifdef FIX_CLASS
// clang-format off
FixStyle(UPDATE_SPECIAL_BONDS,FixUpdateSpecialBonds)
FixStyle(UPDATE_SPECIAL_BONDS,FixUpdateSpecialBonds);
// clang-format on
#else
@ -22,26 +22,25 @@ FixStyle(UPDATE_SPECIAL_BONDS,FixUpdateSpecialBonds)
#include "fix.h"
#include <vector>
#include <utility>
#include <vector>
namespace LAMMPS_NS {
class FixUpdateSpecialBonds : public Fix {
public:
FixUpdateSpecialBonds(class LAMMPS *, int, char **);
~FixUpdateSpecialBonds();
int setmask();
void setup(int);
void pre_exchange();
void pre_force(int);
void add_broken_bond(int,int);
int setmask() override;
void setup(int) override;
void pre_exchange() override;
void pre_force(int) override;
void add_broken_bond(int, int);
protected:
// Create two arrays to store bonds broken this timestep (new)
// and since the last neighbor list build
std::vector <std::pair<tagint, tagint>> new_broken_pairs;
std::vector <std::pair<tagint, tagint>> broken_pairs;
std::vector<std::pair<tagint, tagint>> new_broken_pairs;
std::vector<std::pair<tagint, tagint>> broken_pairs;
};
} // namespace LAMMPS_NS

View File

@ -950,28 +950,26 @@ void Set::set(int keyword)
else
error->one(FLERR,"Cannot set quaternion for atom that has none");
if (domain->dimension == 2 && (xvalue != 0.0 || yvalue != 0.0))
error->one(FLERR,"Cannot set quaternion with xy components "
"for 2d system");
error->one(FLERR,"Cannot set quaternion with xy components for 2d system");
double theta2 = MY_PI2 * wvalue/180.0;
double sintheta2 = sin(theta2);
const double theta2 = MY_PI2 * wvalue/180.0;
const double sintheta2 = sin(theta2);
double temp[4];
temp[0] = cos(theta2);
temp[1] = xvalue * sintheta2;
temp[2] = yvalue * sintheta2;
temp[3] = zvalue * sintheta2;
MathExtra::qnormalize(temp);
if (atom->quat_flag) {
double temp[4];
temp[0] = cos(theta2);
temp[1] = xvalue * sintheta2;
temp[2] = yvalue * sintheta2;
temp[3] = zvalue * sintheta2;
MathExtra::qnormalize(temp);
quat2[i][0] = temp[0];
quat2[i][1] = temp[1];
quat2[i][2] = temp[2];
quat2[i][3] = temp[3];
} else {
quat[0] = cos(theta2);
quat[1] = xvalue * sintheta2;
quat[2] = yvalue * sintheta2;
quat[3] = zvalue * sintheta2;
MathExtra::qnormalize(quat);
quat[0] = temp[0];
quat[1] = temp[1];
quat[2] = temp[2];
quat[3] = temp[3];
}
}