address CodeQL warnings and reformat with clang-format

This commit is contained in:
Axel Kohlmeyer
2021-07-27 12:29:44 -04:00
parent f7f85822a9
commit d292da78ca
7 changed files with 239 additions and 267 deletions

View File

@ -116,7 +116,7 @@ ComputeHMA::ComputeHMA(LAMMPS *lmp, int narg, char **arg) :
computeU = computeP = computeCv = -1;
returnAnharmonic = 0;
size_vector = 0;
memory->create(extlist, 3, "hma:extlist");
extlist = new int[3];
for (int iarg=4; iarg<narg; iarg++) {
if (!strcmp(arg[iarg], "u")) {
if (computeU>-1) continue;
@ -145,20 +145,11 @@ ComputeHMA::ComputeHMA(LAMMPS *lmp, int narg, char **arg) :
}
}
if (size_vector == 0) {
error->all(FLERR,"Illegal compute hma command");
}
if (size_vector<3) {
memory->grow(extlist, size_vector, "hma:extlist");
}
memory->create(vector, size_vector, "hma:vector");
if (size_vector == 0) error->all(FLERR,"Illegal compute hma command");
vector = new double[size_vector];
if (computeU>-1 || computeCv>-1) {
peflag = 1;
}
if (computeP>-1) {
pressflag = 1;
}
if (computeU>-1 || computeCv>-1) peflag = 1;
if (computeP>-1) pressflag = 1;
nmax = 0;
}
@ -170,10 +161,11 @@ ComputeHMA::~ComputeHMA()
// check nfix in case all fixes have already been deleted
if (modify->nfix) modify->delete_fix(id_fix);
delete [] id_fix;
delete [] id_temp;
memory->destroy(extlist);
memory->destroy(vector);
delete[] id_fix;
delete[] id_temp;
delete[] extlist;
delete[] vector;
memory->destroy(deltaR);
}

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -14,28 +13,26 @@
#include "compute_force_tally.h"
#include <cmath>
#include "atom.h"
#include "group.h"
#include "pair.h"
#include "update.h"
#include "memory.h"
#include "comm.h"
#include "error.h"
#include "force.h"
#include "comm.h"
#include "group.h"
#include "memory.h"
#include "pair.h"
#include "update.h"
#include <cmath>
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
ComputeForceTally::ComputeForceTally(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg)
ComputeForceTally::ComputeForceTally(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg)
{
if (narg < 4) error->all(FLERR,"Illegal compute force/tally command");
if (narg < 4) error->all(FLERR, "Illegal compute force/tally command");
igroup2 = group->find(arg[3]);
if (igroup2 == -1)
error->all(FLERR,"Could not find compute force/tally second group ID");
if (igroup2 == -1) error->all(FLERR, "Could not find compute force/tally second group ID");
groupbit2 = group->bitmask[igroup2];
scalar_flag = 1;
@ -46,7 +43,7 @@ ComputeForceTally::ComputeForceTally(LAMMPS *lmp, int narg, char **arg) :
comm_reverse = size_peratom_cols = 3;
extscalar = 1;
peflag = 1; // we need Pair::ev_tally() to be run
peflag = 1; // we need Pair::ev_tally() to be run
did_setup = invoked_peratom = invoked_scalar = -1;
nmax = -1;
@ -68,17 +65,16 @@ ComputeForceTally::~ComputeForceTally()
void ComputeForceTally::init()
{
if (force->pair == nullptr)
error->all(FLERR,"Trying to use compute force/tally without pair style");
error->all(FLERR, "Trying to use compute force/tally without pair style");
else
force->pair->add_tally_callback(this);
if (comm->me == 0) {
if (force->pair->single_enable == 0 || force->pair->manybody_flag)
error->warning(FLERR,"Compute force/tally used with incompatible pair style");
error->warning(FLERR, "Compute force/tally used with incompatible pair style");
if (force->bond || force->angle || force->dihedral
|| force->improper || force->kspace)
error->warning(FLERR,"Compute force/tally only called from pair style");
if (force->bond || force->angle || force->dihedral || force->improper || force->kspace)
error->warning(FLERR, "Compute force/tally only called from pair style");
}
did_setup = -1;
}
@ -99,51 +95,48 @@ void ComputeForceTally::pair_setup_callback(int, int)
if (atom->nmax > nmax) {
memory->destroy(fatom);
nmax = atom->nmax;
memory->create(fatom,nmax,size_peratom_cols,"force/tally:fatom");
memory->create(fatom, nmax, size_peratom_cols, "force/tally:fatom");
array_atom = fatom;
}
// clear storage
for (int i=0; i < ntotal; ++i)
for (int j=0; j < size_peratom_cols; ++j)
fatom[i][j] = 0.0;
for (int i = 0; i < ntotal; ++i)
for (int j = 0; j < size_peratom_cols; ++j) fatom[i][j] = 0.0;
for (int i=0; i < size_peratom_cols; ++i)
vector[i] = ftotal[i] = 0.0;
for (int i = 0; i < size_peratom_cols; ++i) vector[i] = ftotal[i] = 0.0;
did_setup = update->ntimestep;
}
/* ---------------------------------------------------------------------- */
void ComputeForceTally::pair_tally_callback(int i, int j, int nlocal, int newton,
double, double, double fpair,
double dx, double dy, double dz)
void ComputeForceTally::pair_tally_callback(int i, int j, int nlocal, int newton, double, double,
double fpair, double dx, double dy, double dz)
{
const int * const mask = atom->mask;
const int *const mask = atom->mask;
if ( ((mask[i] & groupbit) && (mask[j] & groupbit2))
|| ((mask[i] & groupbit2) && (mask[j] & groupbit))) {
if (((mask[i] & groupbit) && (mask[j] & groupbit2)) ||
((mask[i] & groupbit2) && (mask[j] & groupbit))) {
if (newton || i < nlocal) {
if (mask[i] & groupbit) {
ftotal[0] += fpair*dx;
ftotal[1] += fpair*dy;
ftotal[2] += fpair*dz;
ftotal[0] += fpair * dx;
ftotal[1] += fpair * dy;
ftotal[2] += fpair * dz;
}
fatom[i][0] += fpair*dx;
fatom[i][1] += fpair*dy;
fatom[i][2] += fpair*dz;
fatom[i][0] += fpair * dx;
fatom[i][1] += fpair * dy;
fatom[i][2] += fpair * dz;
}
if (newton || j < nlocal) {
if (mask[j] & groupbit) {
ftotal[0] -= fpair*dx;
ftotal[1] -= fpair*dy;
ftotal[2] -= fpair*dz;
ftotal[0] -= fpair * dx;
ftotal[1] -= fpair * dy;
ftotal[2] -= fpair * dz;
}
fatom[j][0] -= fpair*dx;
fatom[j][1] -= fpair*dy;
fatom[j][2] -= fpair*dz;
fatom[j][0] -= fpair * dx;
fatom[j][1] -= fpair * dy;
fatom[j][2] -= fpair * dz;
}
}
}
@ -152,7 +145,7 @@ void ComputeForceTally::pair_tally_callback(int i, int j, int nlocal, int newton
int ComputeForceTally::pack_reverse_comm(int n, int first, double *buf)
{
int i,m,last;
int i, m, last;
m = 0;
last = first + n;
@ -168,7 +161,7 @@ int ComputeForceTally::pack_reverse_comm(int n, int first, double *buf)
void ComputeForceTally::unpack_reverse_comm(int n, int *list, double *buf)
{
int i,j,m;
int i, j, m;
m = 0;
for (i = 0; i < n; i++) {
@ -184,15 +177,14 @@ void ComputeForceTally::unpack_reverse_comm(int n, int *list, double *buf)
double ComputeForceTally::compute_scalar()
{
invoked_scalar = update->ntimestep;
if ((did_setup != invoked_scalar)
|| (update->eflag_global != invoked_scalar))
error->all(FLERR,"Energy was not tallied on needed timestep");
if ((did_setup != invoked_scalar) || (update->eflag_global != invoked_scalar))
error->all(FLERR, "Energy was not tallied on needed timestep");
// sum accumulated forces across procs
MPI_Allreduce(ftotal,vector,size_peratom_cols,MPI_DOUBLE,MPI_SUM,world);
MPI_Allreduce(ftotal, vector, size_peratom_cols, MPI_DOUBLE, MPI_SUM, world);
scalar = sqrt(vector[0]*vector[0]+vector[1]*vector[1]+vector[2]*vector[2]);
scalar = sqrt(vector[0] * vector[0] + vector[1] * vector[1] + vector[2] * vector[2]);
return scalar;
}
@ -201,9 +193,8 @@ double ComputeForceTally::compute_scalar()
void ComputeForceTally::compute_peratom()
{
invoked_peratom = update->ntimestep;
if ((did_setup != invoked_peratom)
|| (update->eflag_global != invoked_peratom))
error->all(FLERR,"Energy was not tallied on needed timestep");
if ((did_setup != invoked_peratom) || (update->eflag_global != invoked_peratom))
error->all(FLERR, "Energy was not tallied on needed timestep");
// collect contributions from ghost atoms
@ -213,8 +204,7 @@ void ComputeForceTally::compute_peratom()
// clear out ghost atom data after it has been collected to local atoms
const int nall = atom->nlocal + atom->nghost;
for (int i = atom->nlocal; i < nall; ++i)
for (int j = 0; j < size_peratom_cols; ++j)
fatom[i][j] = 0.0;
for (int j = 0; j < size_peratom_cols; ++j) fatom[i][j] = 0.0;
}
}
@ -224,7 +214,6 @@ void ComputeForceTally::compute_peratom()
double ComputeForceTally::memory_usage()
{
double bytes = (nmax < 0) ? 0 : nmax*size_peratom_cols * sizeof(double);
double bytes = (nmax < 0) ? 0 : nmax * (double)size_peratom_cols * 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
@ -15,26 +14,25 @@
#include "compute_heat_flux_tally.h"
#include "atom.h"
#include "group.h"
#include "pair.h"
#include "update.h"
#include "memory.h"
#include "comm.h"
#include "error.h"
#include "force.h"
#include "comm.h"
#include "group.h"
#include "memory.h"
#include "pair.h"
#include "update.h"
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
ComputeHeatFluxTally::ComputeHeatFluxTally(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg)
Compute(lmp, narg, arg)
{
if (narg < 4) error->all(FLERR,"Illegal compute heat/flux/tally command");
if (narg < 4) error->all(FLERR, "Illegal compute heat/flux/tally command");
igroup2 = group->find(arg[3]);
if (igroup2 == -1)
error->all(FLERR,"Could not find compute heat/flux/tally second group ID");
if (igroup2 == -1) error->all(FLERR, "Could not find compute heat/flux/tally second group ID");
groupbit2 = group->bitmask[igroup2];
vector_flag = 1;
@ -44,7 +42,7 @@ ComputeHeatFluxTally::ComputeHeatFluxTally(LAMMPS *lmp, int narg, char **arg) :
comm_reverse = 7;
extvector = 1;
size_vector = 6;
peflag = 1; // we need Pair::ev_tally() to be run
peflag = 1; // we need Pair::ev_tally() to be run
did_setup = 0;
invoked_peratom = invoked_scalar = -1;
@ -71,17 +69,16 @@ ComputeHeatFluxTally::~ComputeHeatFluxTally()
void ComputeHeatFluxTally::init()
{
if (force->pair == nullptr)
error->all(FLERR,"Trying to use compute heat/flux/tally without pair style");
error->all(FLERR, "Trying to use compute heat/flux/tally without pair style");
else
force->pair->add_tally_callback(this);
if (comm->me == 0) {
if (force->pair->single_enable == 0 || force->pair->manybody_flag)
error->warning(FLERR,"Compute heat/flux/tally used with incompatible pair style");
error->warning(FLERR, "Compute heat/flux/tally used with incompatible pair style");
if (force->bond || force->angle || force->dihedral
|| force->improper || force->kspace)
error->warning(FLERR,"Compute heat/flux/tally only called from pair style");
if (force->bond || force->angle || force->dihedral || force->improper || force->kspace)
error->warning(FLERR, "Compute heat/flux/tally only called from pair style");
}
did_setup = -1;
}
@ -102,13 +99,13 @@ void ComputeHeatFluxTally::pair_setup_callback(int, int)
memory->destroy(stress);
memory->destroy(eatom);
nmax = atom->nmax;
memory->create(stress,nmax,6,"heat/flux/tally:stress");
memory->create(eatom,nmax,"heat/flux/tally:eatom");
memory->create(stress, nmax, 6, "heat/flux/tally:stress");
memory->create(eatom, nmax, "heat/flux/tally:eatom");
}
// clear storage
for (int i=0; i < ntotal; ++i) {
for (int i = 0; i < ntotal; ++i) {
eatom[i] = 0.0;
stress[i][0] = 0.0;
stress[i][1] = 0.0;
@ -118,30 +115,29 @@ void ComputeHeatFluxTally::pair_setup_callback(int, int)
stress[i][5] = 0.0;
}
for (int i=0; i < size_vector; ++i)
vector[i] = heatj[i] = 0.0;
for (int i = 0; i < size_vector; ++i) vector[i] = heatj[i] = 0.0;
did_setup = update->ntimestep;
}
/* ---------------------------------------------------------------------- */
void ComputeHeatFluxTally::pair_tally_callback(int i, int j, int nlocal, int newton,
double evdwl, double ecoul, double fpair,
double dx, double dy, double dz)
void ComputeHeatFluxTally::pair_tally_callback(int i, int j, int nlocal, int newton, double evdwl,
double ecoul, double fpair, double dx, double dy,
double dz)
{
const int * const mask = atom->mask;
const int *const mask = atom->mask;
if ( ((mask[i] & groupbit) && (mask[j] & groupbit2))
|| ((mask[i] & groupbit2) && (mask[j] & groupbit))) {
if (((mask[i] & groupbit) && (mask[j] & groupbit2)) ||
((mask[i] & groupbit2) && (mask[j] & groupbit))) {
const double epairhalf = 0.5 * (evdwl + ecoul);
fpair *= 0.5;
const double v0 = dx*dx*fpair; // dx*fpair = Fij_x
const double v1 = dy*dy*fpair;
const double v2 = dz*dz*fpair;
const double v3 = dx*dy*fpair;
const double v4 = dx*dz*fpair;
const double v5 = dy*dz*fpair;
const double v0 = dx * dx * fpair; // dx*fpair = Fij_x
const double v1 = dy * dy * fpair;
const double v2 = dz * dz * fpair;
const double v3 = dx * dy * fpair;
const double v4 = dx * dz * fpair;
const double v5 = dy * dz * fpair;
if (newton || i < nlocal) {
eatom[i] += epairhalf;
@ -168,7 +164,7 @@ void ComputeHeatFluxTally::pair_tally_callback(int i, int j, int nlocal, int new
int ComputeHeatFluxTally::pack_reverse_comm(int n, int first, double *buf)
{
int i,m,last;
int i, m, last;
m = 0;
last = first + n;
@ -188,7 +184,7 @@ int ComputeHeatFluxTally::pack_reverse_comm(int n, int first, double *buf)
void ComputeHeatFluxTally::unpack_reverse_comm(int n, int *list, double *buf)
{
int i,j,m;
int i, j, m;
m = 0;
for (i = 0; i < n; i++) {
@ -209,7 +205,7 @@ void ComputeHeatFluxTally::compute_vector()
{
invoked_vector = update->ntimestep;
if ((did_setup != invoked_vector) || (update->eflag_global != invoked_vector))
error->all(FLERR,"Energy was not tallied on needed timestep");
error->all(FLERR, "Energy was not tallied on needed timestep");
// collect contributions from ghost atoms
@ -244,26 +240,28 @@ void ComputeHeatFluxTally::compute_vector()
double *rmass = atom->rmass;
int *type = atom->type;
double jc[3] = {0.0,0.0,0.0};
double jv[3] = {0.0,0.0,0.0};
double jc[3] = {0.0, 0.0, 0.0};
double jv[3] = {0.0, 0.0, 0.0};
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
const double * const vi = v[i];
const double * const si = stress[i];
const double *const vi = v[i];
const double *const si = stress[i];
double ke_i;
if (rmass) ke_i = pfactor * rmass[i];
else ke_i = pfactor * mass[type[i]];
ke_i *= (vi[0]*vi[0] + vi[1]*vi[1] + vi[2]*vi[2]);
if (rmass)
ke_i = pfactor * rmass[i];
else
ke_i = pfactor * mass[type[i]];
ke_i *= (vi[0] * vi[0] + vi[1] * vi[1] + vi[2] * vi[2]);
ke_i += eatom[i];
jc[0] += ke_i*vi[0];
jc[1] += ke_i*vi[1];
jc[2] += ke_i*vi[2];
jv[0] += si[0]*vi[0] + si[3]*vi[1] + si[4]*vi[2];
jv[1] += si[3]*vi[0] + si[1]*vi[1] + si[5]*vi[2];
jv[2] += si[4]*vi[0] + si[5]*vi[1] + si[2]*vi[2];
jc[0] += ke_i * vi[0];
jc[1] += ke_i * vi[1];
jc[2] += ke_i * vi[2];
jv[0] += si[0] * vi[0] + si[3] * vi[1] + si[4] * vi[2];
jv[1] += si[3] * vi[0] + si[1] * vi[1] + si[5] * vi[2];
jv[2] += si[4] * vi[0] + si[5] * vi[1] + si[2] * vi[2];
}
}
@ -274,7 +272,7 @@ void ComputeHeatFluxTally::compute_vector()
heatj[3] = jc[0];
heatj[4] = jc[1];
heatj[5] = jc[2];
MPI_Allreduce(heatj,vector,size_vector,MPI_DOUBLE,MPI_SUM,world);
MPI_Allreduce(heatj, vector, size_vector, MPI_DOUBLE, MPI_SUM, world);
}
/* ----------------------------------------------------------------------
@ -283,7 +281,6 @@ void ComputeHeatFluxTally::compute_vector()
double ComputeHeatFluxTally::memory_usage()
{
double bytes = (nmax < 0) ? 0 : nmax*comm_reverse * sizeof(double);
double bytes = (nmax < 0) ? 0 : nmax * (double)comm_reverse * sizeof(double);
return bytes;
}

View File

@ -233,6 +233,6 @@ void ComputeHeatFluxVirialTally::compute_peratom()
double ComputeHeatFluxVirialTally::memory_usage()
{
double bytes = (nmax < 0) ? 0 : nmax * size_peratom_cols * sizeof(double);
double bytes = (nmax < 0) ? 0 : nmax * (double)size_peratom_cols * 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
@ -15,25 +14,23 @@
#include "compute_pe_mol_tally.h"
#include "atom.h"
#include "comm.h"
#include "error.h"
#include "force.h"
#include "group.h"
#include "pair.h"
#include "update.h"
#include "error.h"
#include "force.h"
#include "comm.h"
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
ComputePEMolTally::ComputePEMolTally(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg)
ComputePEMolTally::ComputePEMolTally(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg)
{
if (narg < 4) error->all(FLERR,"Illegal compute pe/mol/tally command");
if (narg < 4) error->all(FLERR, "Illegal compute pe/mol/tally command");
igroup2 = group->find(arg[3]);
if (igroup2 == -1)
error->all(FLERR,"Could not find compute pe/mol/tally second group ID");
if (igroup2 == -1) error->all(FLERR, "Could not find compute pe/mol/tally second group ID");
groupbit2 = group->bitmask[igroup2];
vector_flag = 1;
@ -42,7 +39,7 @@ ComputePEMolTally::ComputePEMolTally(LAMMPS *lmp, int narg, char **arg) :
dynamic_group_allow = 0;
extvector = 1;
peflag = 1; // we need Pair::ev_tally() to be run
peflag = 1; // we need Pair::ev_tally() to be run
did_setup = invoked_vector = -1;
vector = new double[size_vector];
@ -61,20 +58,18 @@ ComputePEMolTally::~ComputePEMolTally()
void ComputePEMolTally::init()
{
if (force->pair == nullptr)
error->all(FLERR,"Trying to use compute pe/mol/tally without pair style");
error->all(FLERR, "Trying to use compute pe/mol/tally without pair style");
else
force->pair->add_tally_callback(this);
if (atom->molecule_flag == 0)
error->all(FLERR,"Compute pe/mol/tally requires molecule IDs");
if (atom->molecule_flag == 0) error->all(FLERR, "Compute pe/mol/tally requires molecule IDs");
if (comm->me == 0) {
if (force->pair->single_enable == 0 || force->pair->manybody_flag)
error->warning(FLERR,"Compute pe/mol/tally used with incompatible pair style");
error->warning(FLERR, "Compute pe/mol/tally used with incompatible pair style");
if (force->bond || force->angle || force->dihedral
|| force->improper || force->kspace)
error->warning(FLERR,"Compute pe/mol/tally only called from pair style");
if (force->bond || force->angle || force->dihedral || force->improper || force->kspace)
error->warning(FLERR, "Compute pe/mol/tally only called from pair style");
}
did_setup = -1;
}
@ -93,29 +88,33 @@ void ComputePEMolTally::pair_setup_callback(int, int)
}
/* ---------------------------------------------------------------------- */
void ComputePEMolTally::pair_tally_callback(int i, int j, int nlocal, int newton,
double evdwl, double ecoul, double,
double, double, double)
void ComputePEMolTally::pair_tally_callback(int i, int j, int nlocal, int newton, double evdwl,
double ecoul, double, double, double, double)
{
const int * const mask = atom->mask;
const tagint * const molid = atom->molecule;
const int *const mask = atom->mask;
const tagint *const molid = atom->molecule;
if ( ((mask[i] & groupbit) && (mask[j] & groupbit2))
|| ((mask[i] & groupbit2) && (mask[j] & groupbit))) {
if (((mask[i] & groupbit) && (mask[j] & groupbit2)) ||
((mask[i] & groupbit2) && (mask[j] & groupbit))) {
evdwl *= 0.5; ecoul *= 0.5;
evdwl *= 0.5;
ecoul *= 0.5;
if (newton || i < nlocal) {
if (molid[i] == molid[j]) {
etotal[0] += evdwl; etotal[1] += ecoul;
etotal[0] += evdwl;
etotal[1] += ecoul;
} else {
etotal[2] += evdwl; etotal[3] += ecoul;
etotal[2] += evdwl;
etotal[3] += ecoul;
}
}
if (newton || j < nlocal) {
if (molid[i] == molid[j]) {
etotal[0] += evdwl; etotal[1] += ecoul;
etotal[0] += evdwl;
etotal[1] += ecoul;
} else {
etotal[2] += evdwl; etotal[3] += ecoul;
etotal[2] += evdwl;
etotal[3] += ecoul;
}
}
}
@ -127,10 +126,9 @@ void ComputePEMolTally::compute_vector()
{
invoked_vector = update->ntimestep;
if ((did_setup != invoked_vector) || (update->eflag_global != invoked_vector))
error->all(FLERR,"Energy was not tallied on needed timestep");
error->all(FLERR, "Energy was not tallied on needed timestep");
// sum accumulated energies across procs
MPI_Allreduce(etotal,vector,size_vector,MPI_DOUBLE,MPI_SUM,world);
MPI_Allreduce(etotal, vector, size_vector, MPI_DOUBLE, MPI_SUM, world);
}

View File

@ -1,4 +1,3 @@
// clang-format off
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
@ -15,26 +14,24 @@
#include "compute_pe_tally.h"
#include "atom.h"
#include "group.h"
#include "pair.h"
#include "update.h"
#include "memory.h"
#include "comm.h"
#include "error.h"
#include "force.h"
#include "comm.h"
#include "group.h"
#include "memory.h"
#include "pair.h"
#include "update.h"
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
ComputePETally::ComputePETally(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg)
ComputePETally::ComputePETally(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg)
{
if (narg < 4) error->all(FLERR,"Illegal compute pe/tally command");
if (narg < 4) error->all(FLERR, "Illegal compute pe/tally command");
igroup2 = group->find(arg[3]);
if (igroup2 == -1)
error->all(FLERR,"Could not find compute pe/tally second group ID");
if (igroup2 == -1) error->all(FLERR, "Could not find compute pe/tally second group ID");
groupbit2 = group->bitmask[igroup2];
scalar_flag = 1;
@ -45,7 +42,7 @@ ComputePETally::ComputePETally(LAMMPS *lmp, int narg, char **arg) :
comm_reverse = size_peratom_cols = 2;
extscalar = 1;
peflag = 1; // we need Pair::ev_tally() to be run
peflag = 1; // we need Pair::ev_tally() to be run
did_setup = invoked_peratom = invoked_scalar = -1;
nmax = -1;
@ -67,17 +64,16 @@ ComputePETally::~ComputePETally()
void ComputePETally::init()
{
if (force->pair == nullptr)
error->all(FLERR,"Trying to use compute pe/tally without a pair style");
error->all(FLERR, "Trying to use compute pe/tally without a pair style");
else
force->pair->add_tally_callback(this);
if (comm->me == 0) {
if (force->pair->single_enable == 0 || force->pair->manybody_flag)
error->warning(FLERR,"Compute pe/tally used with incompatible pair style");
error->warning(FLERR, "Compute pe/tally used with incompatible pair style");
if (force->bond || force->angle || force->dihedral
|| force->improper || force->kspace)
error->warning(FLERR,"Compute pe/tally only called from pair style");
if (force->bond || force->angle || force->dihedral || force->improper || force->kspace)
error->warning(FLERR, "Compute pe/tally only called from pair style");
}
did_setup = -1;
}
@ -98,14 +94,13 @@ void ComputePETally::pair_setup_callback(int, int)
if (atom->nmax > nmax) {
memory->destroy(eatom);
nmax = atom->nmax;
memory->create(eatom,nmax,size_peratom_cols,"pe/tally:eatom");
memory->create(eatom, nmax, size_peratom_cols, "pe/tally:eatom");
array_atom = eatom;
}
// clear storage
for (int i=0; i < ntotal; ++i)
eatom[i][0] = eatom[i][1] = 0.0;
for (int i = 0; i < ntotal; ++i) eatom[i][0] = eatom[i][1] = 0.0;
vector[0] = etotal[0] = vector[1] = etotal[1] = 0.0;
@ -113,23 +108,27 @@ void ComputePETally::pair_setup_callback(int, int)
}
/* ---------------------------------------------------------------------- */
void ComputePETally::pair_tally_callback(int i, int j, int nlocal, int newton,
double evdwl, double ecoul, double,
double, double, double)
void ComputePETally::pair_tally_callback(int i, int j, int nlocal, int newton, double evdwl,
double ecoul, double, double, double, double)
{
const int * const mask = atom->mask;
const int *const mask = atom->mask;
if ( ((mask[i] & groupbit) && (mask[j] & groupbit2))
|| ((mask[i] & groupbit2) && (mask[j] & groupbit))) {
if (((mask[i] & groupbit) && (mask[j] & groupbit2)) ||
((mask[i] & groupbit2) && (mask[j] & groupbit))) {
evdwl *= 0.5; ecoul *= 0.5;
evdwl *= 0.5;
ecoul *= 0.5;
if (newton || i < nlocal) {
etotal[0] += evdwl; eatom[i][0] += evdwl;
etotal[1] += ecoul; eatom[i][1] += ecoul;
etotal[0] += evdwl;
eatom[i][0] += evdwl;
etotal[1] += ecoul;
eatom[i][1] += ecoul;
}
if (newton || j < nlocal) {
etotal[0] += evdwl; eatom[j][0] += evdwl;
etotal[1] += ecoul; eatom[j][1] += ecoul;
etotal[0] += evdwl;
eatom[j][0] += evdwl;
etotal[1] += ecoul;
eatom[j][1] += ecoul;
}
}
}
@ -138,7 +137,7 @@ void ComputePETally::pair_tally_callback(int i, int j, int nlocal, int newton,
int ComputePETally::pack_reverse_comm(int n, int first, double *buf)
{
int i,m,last;
int i, m, last;
m = 0;
last = first + n;
@ -153,7 +152,7 @@ int ComputePETally::pack_reverse_comm(int n, int first, double *buf)
void ComputePETally::unpack_reverse_comm(int n, int *list, double *buf)
{
int i,j,m;
int i, j, m;
m = 0;
for (i = 0; i < n; i++) {
@ -168,15 +167,14 @@ void ComputePETally::unpack_reverse_comm(int n, int *list, double *buf)
double ComputePETally::compute_scalar()
{
invoked_scalar = update->ntimestep;
if ((did_setup != invoked_scalar)
|| (update->eflag_global != invoked_scalar))
error->all(FLERR,"Energy was not tallied on needed timestep");
if ((did_setup != invoked_scalar) || (update->eflag_global != invoked_scalar))
error->all(FLERR, "Energy was not tallied on needed timestep");
// sum accumulated energies across procs
MPI_Allreduce(etotal,vector,size_peratom_cols,MPI_DOUBLE,MPI_SUM,world);
MPI_Allreduce(etotal, vector, size_peratom_cols, MPI_DOUBLE, MPI_SUM, world);
scalar = vector[0]+vector[1];
scalar = vector[0] + vector[1];
return scalar;
}
@ -185,9 +183,8 @@ double ComputePETally::compute_scalar()
void ComputePETally::compute_peratom()
{
invoked_peratom = update->ntimestep;
if ((did_setup != invoked_peratom)
|| (update->eflag_global != invoked_peratom))
error->all(FLERR,"Energy was not tallied on needed timestep");
if ((did_setup != invoked_peratom) || (update->eflag_global != invoked_peratom))
error->all(FLERR, "Energy was not tallied on needed timestep");
// collect contributions from ghost atoms
@ -196,8 +193,7 @@ void ComputePETally::compute_peratom()
// clear out ghost atom data after it has been collected to local atoms
const int nall = atom->nlocal + atom->nghost;
for (int i = atom->nlocal; i < nall; ++i)
eatom[i][0] = eatom[i][1] = 0.0;
for (int i = atom->nlocal; i < nall; ++i) eatom[i][0] = eatom[i][1] = 0.0;
}
}
@ -207,7 +203,6 @@ void ComputePETally::compute_peratom()
double ComputePETally::memory_usage()
{
double bytes = (nmax < 0) ? 0 : nmax*size_peratom_cols * sizeof(double);
double bytes = (nmax < 0) ? 0 : nmax * (double)size_peratom_cols * 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
@ -15,27 +14,25 @@
#include "compute_stress_tally.h"
#include "atom.h"
#include "group.h"
#include "pair.h"
#include "update.h"
#include "memory.h"
#include "error.h"
#include "force.h"
#include "comm.h"
#include "domain.h"
#include "error.h"
#include "force.h"
#include "group.h"
#include "memory.h"
#include "pair.h"
#include "update.h"
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
ComputeStressTally::ComputeStressTally(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg)
ComputeStressTally::ComputeStressTally(LAMMPS *lmp, int narg, char **arg) : Compute(lmp, narg, arg)
{
if (narg < 4) error->all(FLERR,"Illegal compute stress/tally command");
if (narg < 4) error->all(FLERR, "Illegal compute stress/tally command");
igroup2 = group->find(arg[3]);
if (igroup2 == -1)
error->all(FLERR,"Could not find compute stress/tally second group ID");
if (igroup2 == -1) error->all(FLERR, "Could not find compute stress/tally second group ID");
groupbit2 = group->bitmask[igroup2];
scalar_flag = 1;
@ -46,7 +43,7 @@ ComputeStressTally::ComputeStressTally(LAMMPS *lmp, int narg, char **arg) :
comm_reverse = size_peratom_cols = 6;
extscalar = 0;
peflag = 1; // we need Pair::ev_tally() to be run
peflag = 1; // we need Pair::ev_tally() to be run
did_setup = invoked_peratom = invoked_scalar = -1;
nmax = -1;
@ -70,17 +67,16 @@ ComputeStressTally::~ComputeStressTally()
void ComputeStressTally::init()
{
if (force->pair == nullptr)
error->all(FLERR,"Trying to use compute stress/tally without pair style");
error->all(FLERR, "Trying to use compute stress/tally without pair style");
else
force->pair->add_tally_callback(this);
if (comm->me == 0) {
if (force->pair->single_enable == 0 || force->pair->manybody_flag)
error->warning(FLERR,"Compute stress/tally used with incompatible pair style");
error->warning(FLERR, "Compute stress/tally used with incompatible pair style");
if (force->bond || force->angle || force->dihedral
|| force->improper || force->kspace)
error->warning(FLERR,"Compute stress/tally only called from pair style");
if (force->bond || force->angle || force->dihedral || force->improper || force->kspace)
error->warning(FLERR, "Compute stress/tally only called from pair style");
}
did_setup = -1;
}
@ -101,55 +97,64 @@ void ComputeStressTally::pair_setup_callback(int, int)
if (atom->nmax > nmax) {
memory->destroy(stress);
nmax = atom->nmax;
memory->create(stress,nmax,size_peratom_cols,"stress/tally:stress");
memory->create(stress, nmax, size_peratom_cols, "stress/tally:stress");
array_atom = stress;
}
// clear storage
for (int i=0; i < ntotal; ++i)
for (int j=0; j < size_peratom_cols; ++j)
stress[i][j] = 0.0;
for (int i = 0; i < ntotal; ++i)
for (int j = 0; j < size_peratom_cols; ++j) stress[i][j] = 0.0;
for (int i=0; i < size_peratom_cols; ++i)
vector[i] = virial[i] = 0.0;
for (int i = 0; i < size_peratom_cols; ++i) vector[i] = virial[i] = 0.0;
did_setup = update->ntimestep;
}
/* ---------------------------------------------------------------------- */
void ComputeStressTally::pair_tally_callback(int i, int j, int nlocal, int newton,
double, double, double fpair,
double dx, double dy, double dz)
void ComputeStressTally::pair_tally_callback(int i, int j, int nlocal, int newton, double, double,
double fpair, double dx, double dy, double dz)
{
const int * const mask = atom->mask;
const int *const mask = atom->mask;
if ( ((mask[i] & groupbit) && (mask[j] & groupbit2))
|| ((mask[i] & groupbit2) && (mask[j] & groupbit))) {
if (((mask[i] & groupbit) && (mask[j] & groupbit2)) ||
((mask[i] & groupbit2) && (mask[j] & groupbit))) {
fpair *= 0.5;
const double v0 = dx*dx*fpair;
const double v1 = dy*dy*fpair;
const double v2 = dz*dz*fpair;
const double v3 = dx*dy*fpair;
const double v4 = dx*dz*fpair;
const double v5 = dy*dz*fpair;
const double v0 = dx * dx * fpair;
const double v1 = dy * dy * fpair;
const double v2 = dz * dz * fpair;
const double v3 = dx * dy * fpair;
const double v4 = dx * dz * fpair;
const double v5 = dy * dz * fpair;
if (newton || i < nlocal) {
virial[0] += v0; stress[i][0] += v0;
virial[1] += v1; stress[i][1] += v1;
virial[2] += v2; stress[i][2] += v2;
virial[3] += v3; stress[i][3] += v3;
virial[4] += v4; stress[i][4] += v4;
virial[5] += v5; stress[i][5] += v5;
virial[0] += v0;
stress[i][0] += v0;
virial[1] += v1;
stress[i][1] += v1;
virial[2] += v2;
stress[i][2] += v2;
virial[3] += v3;
stress[i][3] += v3;
virial[4] += v4;
stress[i][4] += v4;
virial[5] += v5;
stress[i][5] += v5;
}
if (newton || j < nlocal) {
virial[0] += v0; stress[j][0] += v0;
virial[1] += v1; stress[j][1] += v1;
virial[2] += v2; stress[j][2] += v2;
virial[3] += v3; stress[j][3] += v3;
virial[4] += v4; stress[j][4] += v4;
virial[5] += v5; stress[j][5] += v5;
virial[0] += v0;
stress[j][0] += v0;
virial[1] += v1;
stress[j][1] += v1;
virial[2] += v2;
stress[j][2] += v2;
virial[3] += v3;
stress[j][3] += v3;
virial[4] += v4;
stress[j][4] += v4;
virial[5] += v5;
stress[j][5] += v5;
}
}
}
@ -158,7 +163,7 @@ void ComputeStressTally::pair_tally_callback(int i, int j, int nlocal, int newto
int ComputeStressTally::pack_reverse_comm(int n, int first, double *buf)
{
int i,m,last;
int i, m, last;
m = 0;
last = first + n;
@ -177,7 +182,7 @@ int ComputeStressTally::pack_reverse_comm(int n, int first, double *buf)
void ComputeStressTally::unpack_reverse_comm(int n, int *list, double *buf)
{
int i,j,m;
int i, j, m;
m = 0;
for (i = 0; i < n; i++) {
@ -196,18 +201,17 @@ void ComputeStressTally::unpack_reverse_comm(int n, int *list, double *buf)
double ComputeStressTally::compute_scalar()
{
invoked_scalar = update->ntimestep;
if ((did_setup != invoked_scalar)
|| (update->eflag_global != invoked_scalar))
error->all(FLERR,"Energy was not tallied on needed timestep");
if ((did_setup != invoked_scalar) || (update->eflag_global != invoked_scalar))
error->all(FLERR, "Energy was not tallied on needed timestep");
// sum accumulated forces across procs
MPI_Allreduce(virial,vector,size_peratom_cols,MPI_DOUBLE,MPI_SUM,world);
MPI_Allreduce(virial, vector, size_peratom_cols, MPI_DOUBLE, MPI_SUM, world);
if (domain->dimension == 3)
scalar = (vector[0]+vector[1]+vector[2])/3.0;
scalar = (vector[0] + vector[1] + vector[2]) / 3.0;
else
scalar = (vector[0]+vector[1])/2.0;
scalar = (vector[0] + vector[1]) / 2.0;
return scalar;
}
@ -217,9 +221,8 @@ double ComputeStressTally::compute_scalar()
void ComputeStressTally::compute_peratom()
{
invoked_peratom = update->ntimestep;
if ((did_setup != invoked_peratom)
|| (update->eflag_global != invoked_peratom))
error->all(FLERR,"Energy was not tallied on needed timestep");
if ((did_setup != invoked_peratom) || (update->eflag_global != invoked_peratom))
error->all(FLERR, "Energy was not tallied on needed timestep");
// collect contributions from ghost atoms
@ -228,8 +231,7 @@ void ComputeStressTally::compute_peratom()
const int nall = atom->nlocal + atom->nghost;
for (int i = atom->nlocal; i < nall; ++i)
for (int j = 0; j < size_peratom_cols; ++j)
stress[i][j] = 0.0;
for (int j = 0; j < size_peratom_cols; ++j) stress[i][j] = 0.0;
}
// convert to stress*volume units = -pressure*volume
@ -251,7 +253,6 @@ void ComputeStressTally::compute_peratom()
double ComputeStressTally::memory_usage()
{
double bytes = (nmax < 0) ? 0 : nmax*size_peratom_cols * sizeof(double);
double bytes = (nmax < 0) ? 0 : nmax * (double)size_peratom_cols * sizeof(double);
return bytes;
}