enabled and apply clang-format

This commit is contained in:
Axel Kohlmeyer
2024-10-19 11:02:53 -04:00
parent 34ab2f862a
commit 760d871b7a
4 changed files with 405 additions and 360 deletions

View File

@ -1,4 +1,3 @@
// clang-format off
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories https://www.lammps.org/, Sandia National Laboratories
@ -13,20 +12,22 @@
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "compute_angle_local.h" #include "compute_angle_local.h"
#include <cmath>
#include <cstring> #include "angle.h"
#include "atom.h" #include "atom.h"
#include "atom_vec.h" #include "atom_vec.h"
#include "molecule.h"
#include "update.h"
#include "domain.h" #include "domain.h"
#include "error.h"
#include "force.h" #include "force.h"
#include "angle.h"
#include "input.h" #include "input.h"
#include "variable.h"
#include "math_const.h" #include "math_const.h"
#include "memory.h" #include "memory.h"
#include "error.h" #include "molecule.h"
#include "update.h"
#include "variable.h"
#include <cmath>
#include <cstring>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace MathConst; using namespace MathConst;
@ -38,8 +39,8 @@ enum{THETA,ENG,VARIABLE};
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
ComputeAngleLocal::ComputeAngleLocal(LAMMPS *lmp, int narg, char **arg) : ComputeAngleLocal::ComputeAngleLocal(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg), Compute(lmp, narg, arg), bstyle(nullptr), vvar(nullptr), tstr(nullptr), vstr(nullptr),
bstyle(nullptr), vvar(nullptr), tstr(nullptr), vstr(nullptr), vlocal(nullptr), alocal(nullptr) vlocal(nullptr), alocal(nullptr)
{ {
if (narg < 4) error->all(FLERR, "Illegal compute angle/local command"); if (narg < 4) error->all(FLERR, "Illegal compute angle/local command");
@ -70,7 +71,8 @@ ComputeAngleLocal::ComputeAngleLocal(LAMMPS *lmp, int narg, char **arg) :
bstyle[nvalues++] = VARIABLE; bstyle[nvalues++] = VARIABLE;
vstr[nvar] = utils::strdup(&arg[iarg][2]); vstr[nvar] = utils::strdup(&arg[iarg][2]);
nvar++; nvar++;
} else break; } else
break;
} }
// optional args // optional args
@ -86,28 +88,27 @@ ComputeAngleLocal::ComputeAngleLocal(LAMMPS *lmp, int narg, char **arg) :
delete[] tstr; delete[] tstr;
tstr = utils::strdup(arg[iarg + 2]); tstr = utils::strdup(arg[iarg + 2]);
tflag = 1; tflag = 1;
} else error->all(FLERR,"Illegal compute angle/local command"); } else
error->all(FLERR, "Illegal compute angle/local command");
iarg += 3; iarg += 3;
} else error->all(FLERR,"Illegal compute angle/local command"); } else
error->all(FLERR, "Illegal compute angle/local command");
} }
// error check // error check
if (nvar) { if (nvar) {
if (!setflag) if (!setflag) error->all(FLERR, "Compute angle/local variable requires a set variable");
error->all(FLERR,"Compute angle/local variable requires a set variable");
for (int i = 0; i < nvar; i++) { for (int i = 0; i < nvar; i++) {
vvar[i] = input->variable->find(vstr[i]); vvar[i] = input->variable->find(vstr[i]);
if (vvar[i] < 0) if (vvar[i] < 0) error->all(FLERR, "Variable name for copute angle/local does not exist");
error->all(FLERR,"Variable name for copute angle/local does not exist");
if (!input->variable->equalstyle(vvar[i])) if (!input->variable->equalstyle(vvar[i]))
error->all(FLERR, "Variable for compute angle/local is invalid style"); error->all(FLERR, "Variable for compute angle/local is invalid style");
} }
if (tstr) { if (tstr) {
tvar = input->variable->find(tstr); tvar = input->variable->find(tstr);
if (tvar < 0) if (tvar < 0) error->all(FLERR, "Variable name for compute angle/local does not exist");
error->all(FLERR,"Variable name for compute angle/local does not exist");
if (!input->variable->internalstyle(tvar)) if (!input->variable->internalstyle(tvar))
error->all(FLERR, "Variable for compute angle/local is invalid style"); error->all(FLERR, "Variable for compute angle/local is invalid style");
} }
@ -116,8 +117,10 @@ ComputeAngleLocal::ComputeAngleLocal(LAMMPS *lmp, int narg, char **arg) :
// initialize output // initialize output
if (nvalues == 1) size_local_cols = 0; if (nvalues == 1)
else size_local_cols = nvalues; size_local_cols = 0;
else
size_local_cols = nvalues;
nmax = 0; nmax = 0;
vlocal = nullptr; vlocal = nullptr;
@ -149,14 +152,12 @@ void ComputeAngleLocal::init()
if (nvar) { if (nvar) {
for (int i = 0; i < nvar; i++) { for (int i = 0; i < nvar; i++) {
vvar[i] = input->variable->find(vstr[i]); vvar[i] = input->variable->find(vstr[i]);
if (vvar[i] < 0) if (vvar[i] < 0) error->all(FLERR, "Variable name for compute angle/local does not exist");
error->all(FLERR,"Variable name for compute angle/local does not exist");
} }
if (tstr) { if (tstr) {
tvar = input->variable->find(tstr); tvar = input->variable->find(tstr);
if (tvar < 0) if (tvar < 0) error->all(FLERR, "Variable name for compute angle/local does not exist");
error->all(FLERR,"Variable name for compute angle/local does not exist");
} }
} }
@ -224,7 +225,8 @@ int ComputeAngleLocal::compute_angles(int flag)
for (atom2 = 0; atom2 < nlocal; atom2++) { for (atom2 = 0; atom2 < nlocal; atom2++) {
if (!(mask[atom2] & groupbit)) continue; if (!(mask[atom2] & groupbit)) continue;
if (molecular == Atom::MOLECULAR) na = num_angle[atom2]; if (molecular == Atom::MOLECULAR)
na = num_angle[atom2];
else { else {
if (molindex[atom2] < 0) continue; if (molindex[atom2] < 0) continue;
imol = molindex[atom2]; imol = molindex[atom2];
@ -284,8 +286,10 @@ int ComputeAngleLocal::compute_angles(int flag)
theta = acos(c); theta = acos(c);
} }
if (nvalues == 1) ptr = &vlocal[m]; if (nvalues == 1)
else ptr = alocal[m]; ptr = &vlocal[m];
else
ptr = alocal[m];
if (nvar) { if (nvar) {
ivar = 0; ivar = 0;
@ -298,8 +302,10 @@ int ComputeAngleLocal::compute_angles(int flag)
ptr[n] = 180.0 * theta / MY_PI; ptr[n] = 180.0 * theta / MY_PI;
break; break;
case ENG: case ENG:
if (atype > 0) ptr[n] = angle->single(atype,atom1,atom2,atom3); if (atype > 0)
else ptr[n] = 0.0; ptr[n] = angle->single(atype, atom1, atom2, atom3);
else
ptr[n] = 0.0;
break; break;
case VARIABLE: case VARIABLE:
ptr[n] = input->variable->compute_equal(vvar[ivar]); ptr[n] = input->variable->compute_equal(vvar[ivar]);

View File

@ -1,4 +1,3 @@
// clang-format off
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories https://www.lammps.org/, Sandia National Laboratories
@ -35,13 +34,30 @@ using namespace LAMMPS_NS;
static constexpr int DELTA = 10000; static constexpr int DELTA = 10000;
enum{DIST,DX,DY,DZ,VELVIB,OMEGA,ENGTRANS,ENGVIB,ENGROT,ENGPOT,FORCE,FX,FY,FZ,VARIABLE,BN}; enum {
DIST,
DX,
DY,
DZ,
VELVIB,
OMEGA,
ENGTRANS,
ENGVIB,
ENGROT,
ENGPOT,
FORCE,
FX,
FY,
FZ,
VARIABLE,
BN
};
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) : ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg), Compute(lmp, narg, arg), bstyle(nullptr), vvar(nullptr), dstr(nullptr), vstr(nullptr),
bstyle(nullptr), vvar(nullptr), dstr(nullptr), vstr(nullptr), vlocal(nullptr), alocal(nullptr) vlocal(nullptr), alocal(nullptr)
{ {
if (narg < 4) error->all(FLERR, "Illegal compute bond/local command"); if (narg < 4) error->all(FLERR, "Illegal compute bond/local command");
@ -64,20 +80,34 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) :
int iarg; int iarg;
for (iarg = 3; iarg < narg; iarg++) { for (iarg = 3; iarg < narg; iarg++) {
if (strcmp(arg[iarg],"dist") == 0) bstyle[nvalues++] = DIST; if (strcmp(arg[iarg], "dist") == 0)
else if (strcmp(arg[iarg],"dx") == 0) bstyle[nvalues++] = DX; bstyle[nvalues++] = DIST;
else if (strcmp(arg[iarg],"dy") == 0) bstyle[nvalues++] = DY; else if (strcmp(arg[iarg], "dx") == 0)
else if (strcmp(arg[iarg],"dz") == 0) bstyle[nvalues++] = DZ; bstyle[nvalues++] = DX;
else if (strcmp(arg[iarg],"engpot") == 0) bstyle[nvalues++] = ENGPOT; else if (strcmp(arg[iarg], "dy") == 0)
else if (strcmp(arg[iarg],"force") == 0) bstyle[nvalues++] = FORCE; bstyle[nvalues++] = DY;
else if (strcmp(arg[iarg],"fx") == 0) bstyle[nvalues++] = FX; else if (strcmp(arg[iarg], "dz") == 0)
else if (strcmp(arg[iarg],"fy") == 0) bstyle[nvalues++] = FY; bstyle[nvalues++] = DZ;
else if (strcmp(arg[iarg],"fz") == 0) bstyle[nvalues++] = FZ; else if (strcmp(arg[iarg], "engpot") == 0)
else if (strcmp(arg[iarg],"engvib") == 0) bstyle[nvalues++] = ENGVIB; bstyle[nvalues++] = ENGPOT;
else if (strcmp(arg[iarg],"engrot") == 0) bstyle[nvalues++] = ENGROT; else if (strcmp(arg[iarg], "force") == 0)
else if (strcmp(arg[iarg],"engtrans") == 0) bstyle[nvalues++] = ENGTRANS; bstyle[nvalues++] = FORCE;
else if (strcmp(arg[iarg],"omega") == 0) bstyle[nvalues++] = OMEGA; else if (strcmp(arg[iarg], "fx") == 0)
else if (strcmp(arg[iarg],"velvib") == 0) bstyle[nvalues++] = VELVIB; bstyle[nvalues++] = FX;
else if (strcmp(arg[iarg], "fy") == 0)
bstyle[nvalues++] = FY;
else if (strcmp(arg[iarg], "fz") == 0)
bstyle[nvalues++] = FZ;
else if (strcmp(arg[iarg], "engvib") == 0)
bstyle[nvalues++] = ENGVIB;
else if (strcmp(arg[iarg], "engrot") == 0)
bstyle[nvalues++] = ENGROT;
else if (strcmp(arg[iarg], "engtrans") == 0)
bstyle[nvalues++] = ENGTRANS;
else if (strcmp(arg[iarg], "omega") == 0)
bstyle[nvalues++] = OMEGA;
else if (strcmp(arg[iarg], "velvib") == 0)
bstyle[nvalues++] = VELVIB;
else if (strncmp(arg[iarg], "v_", 2) == 0) { else if (strncmp(arg[iarg], "v_", 2) == 0) {
bstyle[nvalues++] = VARIABLE; bstyle[nvalues++] = VARIABLE;
vstr[nvar] = utils::strdup(&arg[iarg][2]); vstr[nvar] = utils::strdup(&arg[iarg][2]);
@ -87,7 +117,8 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) :
if (n <= 0) error->all(FLERR, "Invalid keyword {} in compute bond/local command", arg[iarg]); if (n <= 0) error->all(FLERR, "Invalid keyword {} in compute bond/local command", arg[iarg]);
bstyle[nvalues] = BN; bstyle[nvalues] = BN;
bindex[nvalues++] = n - 1; bindex[nvalues++] = n - 1;
} else break; } else
break;
} }
// optional args // optional args
@ -102,16 +133,17 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) :
if (strcmp(arg[iarg + 1], "dist") == 0) { if (strcmp(arg[iarg + 1], "dist") == 0) {
delete[] dstr; delete[] dstr;
dstr = utils::strdup(arg[iarg + 2]); dstr = utils::strdup(arg[iarg + 2]);
} else error->all(FLERR,"Unknown compute bond/local set keyword: {}", arg[iarg+2]); } else
error->all(FLERR, "Unknown compute bond/local set keyword: {}", arg[iarg + 2]);
iarg += 3; iarg += 3;
} else error->all(FLERR,"Unknown compute bond/local keyword: {}", arg[iarg]); } else
error->all(FLERR, "Unknown compute bond/local keyword: {}", arg[iarg]);
} }
// error check // error check
if (nvar) { if (nvar) {
if (!setflag) if (!setflag) error->all(FLERR, "Compute bond/local variable requires a set variable");
error->all(FLERR,"Compute bond/local variable requires a set variable");
for (int i = 0; i < nvar; i++) { for (int i = 0; i < nvar; i++) {
vvar[i] = input->variable->find(vstr[i]); vvar[i] = input->variable->find(vstr[i]);
if (vvar[i] < 0) if (vvar[i] < 0)
@ -122,31 +154,33 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) :
if (dstr) { if (dstr) {
dvar = input->variable->find(dstr); dvar = input->variable->find(dstr);
if (dvar < 0) if (dvar < 0) error->all(FLERR, "Variable name for compute bond/local does not exist");
error->all(FLERR,"Variable name for compute bond/local does not exist");
if (!input->variable->internalstyle(dvar)) if (!input->variable->internalstyle(dvar))
error->all(FLERR, "Variable for compute bond/local is invalid style"); error->all(FLERR, "Variable for compute bond/local is invalid style");
} }
} else if (setflag) } else if (setflag)
error->all(FLERR, "Compute bond/local set used with without a variable"); error->all(FLERR, "Compute bond/local set used with without a variable");
// set singleflag if need to call bond->single() // set singleflag if need to call bond->single()
// set velflag if compute any quantities based on velocities // set velflag if compute any quantities based on velocities
singleflag = 0; singleflag = 0;
velflag = 0; velflag = 0;
for (int i = 0; i < nvalues; i++) { for (int i = 0; i < nvalues; i++) {
if (bstyle[i] == ENGPOT || bstyle[i] == FORCE || bstyle[i] == FX || if (bstyle[i] == ENGPOT || bstyle[i] == FORCE || bstyle[i] == FX || bstyle[i] == FY ||
bstyle[i] == FY || bstyle[i] == FZ || bstyle[i] == BN) singleflag = 1; bstyle[i] == FZ || bstyle[i] == BN)
if (bstyle[i] == VELVIB || bstyle[i] == OMEGA || bstyle[i] == ENGTRANS || singleflag = 1;
bstyle[i] == ENGVIB || bstyle[i] == ENGROT) velflag = 1; if (bstyle[i] == VELVIB || bstyle[i] == OMEGA || bstyle[i] == ENGTRANS || bstyle[i] == ENGVIB ||
bstyle[i] == ENGROT)
velflag = 1;
} }
// initialize output // initialize output
if (nvalues == 1) size_local_cols = 0; if (nvalues == 1)
else size_local_cols = nvalues; size_local_cols = 0;
else
size_local_cols = nvalues;
nmax = 0; nmax = 0;
vlocal = nullptr; vlocal = nullptr;
@ -173,8 +207,7 @@ ComputeBondLocal::~ComputeBondLocal()
void ComputeBondLocal::init() void ComputeBondLocal::init()
{ {
if (force->bond == nullptr) if (force->bond == nullptr) error->all(FLERR, "No bond style is defined for compute bond/local");
error->all(FLERR,"No bond style is defined for compute bond/local");
for (int i = 0; i < nvalues; i++) for (int i = 0; i < nvalues; i++)
if (bstyle[i] == BN && bindex[i] >= force->bond->single_extra) if (bstyle[i] == BN && bindex[i] >= force->bond->single_extra)
@ -183,21 +216,21 @@ void ComputeBondLocal::init()
if (nvar) { if (nvar) {
for (int i = 0; i < nvar; i++) { for (int i = 0; i < nvar; i++) {
vvar[i] = input->variable->find(vstr[i]); vvar[i] = input->variable->find(vstr[i]);
if (vvar[i] < 0) if (vvar[i] < 0) error->all(FLERR, "Variable name for compute bond/local does not exist");
error->all(FLERR,"Variable name for compute bond/local does not exist");
} }
if (dstr) { if (dstr) {
dvar = input->variable->find(dstr); dvar = input->variable->find(dstr);
if (dvar < 0) if (dvar < 0) error->all(FLERR, "Variable name for compute bond/local does not exist");
error->all(FLERR,"Variable name for compute bond/local does not exist");
} }
} }
// set ghostvelflag if need to acquire ghost atom velocities // set ghostvelflag if need to acquire ghost atom velocities
if (velflag && !comm->ghost_velocity) ghostvelflag = 1; if (velflag && !comm->ghost_velocity)
else ghostvelflag = 0; ghostvelflag = 1;
else
ghostvelflag = 0;
// do initial memory allocation so that memory_usage() is correct // do initial memory allocation so that memory_usage() is correct
@ -280,7 +313,8 @@ int ComputeBondLocal::compute_bonds(int flag)
for (atom1 = 0; atom1 < nlocal; atom1++) { for (atom1 = 0; atom1 < nlocal; atom1++) {
if (!(mask[atom1] & groupbit)) continue; if (!(mask[atom1] & groupbit)) continue;
if (molecular == Atom::MOLECULAR) nb = num_bond[atom1]; if (molecular == Atom::MOLECULAR)
nb = num_bond[atom1];
else { else {
if (molindex[atom1] < 0) continue; if (molindex[atom1] < 0) continue;
imol = molindex[atom1]; imol = molindex[atom1];
@ -317,16 +351,17 @@ int ComputeBondLocal::compute_bonds(int flag)
fbond = 0.0; fbond = 0.0;
} else { } else {
if (singleflag) engpot = bond->single(btype,rsq,atom1,atom2,fbond); if (singleflag)
else fbond = engpot = 0.0; engpot = bond->single(btype, rsq, atom1, atom2, fbond);
else
fbond = engpot = 0.0;
engvib = engrot = engtrans = omegasq = vvib = 0.0; engvib = engrot = engtrans = omegasq = vvib = 0.0;
if (velflag) { if (velflag) {
if (rmass) { if (rmass) {
mass1 = rmass[atom1]; mass1 = rmass[atom1];
mass2 = rmass[atom2]; mass2 = rmass[atom2];
} } else {
else {
mass1 = mass[type[atom1]]; mass1 = mass[type[atom1]];
mass2 = mass[type[atom2]]; mass2 = mass[type[atom2]];
} }
@ -369,8 +404,7 @@ int ComputeBondLocal::compute_bonds(int flag)
// vrotsq = tangential speed squared of atom1 only // vrotsq = tangential speed squared of atom1 only
// omegasq = omega squared, and is the same for atom1 and atom2 // omegasq = omega squared, and is the same for atom1 and atom2
inertia = mass1*MathExtra::lensq3(delr1) + inertia = mass1 * MathExtra::lensq3(delr1) + mass2 * MathExtra::lensq3(delr2);
mass2*MathExtra::lensq3(delr2);
vrotsq = MathExtra::lensq3(delv1) - vpar1 * vpar1; vrotsq = MathExtra::lensq3(delv1) - vpar1 * vpar1;
omegasq = vrotsq / MathExtra::lensq3(delr1); omegasq = vrotsq / MathExtra::lensq3(delr1);
@ -384,8 +418,10 @@ int ComputeBondLocal::compute_bonds(int flag)
engrot *= mvv2e; engrot *= mvv2e;
} }
if (nvalues == 1) ptr = &vlocal[m]; if (nvalues == 1)
else ptr = alocal[m]; ptr = &vlocal[m];
else
ptr = alocal[m];
if (nvar) { if (nvar) {
ivar = 0; ivar = 0;
@ -459,8 +495,8 @@ int ComputeBondLocal::compute_bonds(int flag)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int ComputeBondLocal::pack_forward_comm(int n, int *list, double *buf, int ComputeBondLocal::pack_forward_comm(int n, int *list, double *buf, int /*pbc_flag*/,
int /*pbc_flag*/, int * /*pbc*/) int * /*pbc*/)
{ {
int i, j, m; int i, j, m;

View File

@ -1,4 +1,3 @@
// clang-format off
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories https://www.lammps.org/, Sandia National Laboratories
@ -13,19 +12,21 @@
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "compute_dihedral_local.h" #include "compute_dihedral_local.h"
#include <cmath>
#include <cstring>
#include "atom.h" #include "atom.h"
#include "atom_vec.h" #include "atom_vec.h"
#include "molecule.h"
#include "update.h"
#include "domain.h" #include "domain.h"
#include "error.h"
#include "force.h" #include "force.h"
#include "input.h" #include "input.h"
#include "variable.h"
#include "math_const.h" #include "math_const.h"
#include "memory.h" #include "memory.h"
#include "error.h" #include "molecule.h"
#include "update.h"
#include "variable.h"
#include <cmath>
#include <cstring>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace MathConst; using namespace MathConst;
@ -37,14 +38,13 @@ enum { PHI, VARIABLE };
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
ComputeDihedralLocal::ComputeDihedralLocal(LAMMPS *lmp, int narg, char **arg) : ComputeDihedralLocal::ComputeDihedralLocal(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg), Compute(lmp, narg, arg), bstyle(nullptr), vvar(nullptr), pstr(nullptr), vstr(nullptr),
bstyle(nullptr), vvar(nullptr), pstr(nullptr), vstr(nullptr), vlocal(nullptr), alocal(nullptr) vlocal(nullptr), alocal(nullptr)
{ {
if (narg < 4) error->all(FLERR, "Illegal compute dihedral/local command"); if (narg < 4) error->all(FLERR, "Illegal compute dihedral/local command");
if (atom->avec->dihedrals_allow == 0) if (atom->avec->dihedrals_allow == 0)
error->all(FLERR, error->all(FLERR, "Compute dihedral/local used when dihedrals are not allowed");
"Compute dihedral/local used when dihedrals are not allowed");
local_flag = 1; local_flag = 1;
@ -66,7 +66,8 @@ ComputeDihedralLocal::ComputeDihedralLocal(LAMMPS *lmp, int narg, char **arg) :
bstyle[nvalues++] = VARIABLE; bstyle[nvalues++] = VARIABLE;
vstr[nvar] = utils::strdup(&arg[iarg][2]); vstr[nvar] = utils::strdup(&arg[iarg][2]);
nvar++; nvar++;
} else break; } else
break;
} }
// optional args // optional args
@ -77,35 +78,31 @@ ComputeDihedralLocal::ComputeDihedralLocal(LAMMPS *lmp, int narg, char **arg) :
while (iarg < narg) { while (iarg < narg) {
if (strcmp(arg[iarg], "set") == 0) { if (strcmp(arg[iarg], "set") == 0) {
setflag = 1; setflag = 1;
if (iarg+3 > narg) if (iarg + 3 > narg) error->all(FLERR, "Illegal compute dihedral/local command");
error->all(FLERR,"Illegal compute dihedral/local command");
if (strcmp(arg[iarg + 1], "phi") == 0) { if (strcmp(arg[iarg + 1], "phi") == 0) {
delete[] pstr; delete[] pstr;
pstr = utils::strdup(arg[iarg + 2]); pstr = utils::strdup(arg[iarg + 2]);
} else error->all(FLERR,"Illegal compute dihedral/local command"); } else
error->all(FLERR, "Illegal compute dihedral/local command");
iarg += 3; iarg += 3;
} else error->all(FLERR,"Illegal compute dihedral/local command"); } else
error->all(FLERR, "Illegal compute dihedral/local command");
} }
// error check // error check
if (nvar) { if (nvar) {
if (!setflag) if (!setflag) error->all(FLERR, "Compute dihedral/local variable requires a set variable");
error->all(FLERR,"Compute dihedral/local variable requires a set variable");
for (int i = 0; i < nvar; i++) { for (int i = 0; i < nvar; i++) {
vvar[i] = input->variable->find(vstr[i]); vvar[i] = input->variable->find(vstr[i]);
if (vvar[i] < 0) if (vvar[i] < 0) error->all(FLERR, "Variable name for copute dihedral/local does not exist");
error->all(FLERR,
"Variable name for copute dihedral/local does not exist");
if (!input->variable->equalstyle(vvar[i])) if (!input->variable->equalstyle(vvar[i]))
error->all(FLERR, "Variable for compute dihedral/local is invalid style"); error->all(FLERR, "Variable for compute dihedral/local is invalid style");
} }
if (pstr) { if (pstr) {
pvar = input->variable->find(pstr); pvar = input->variable->find(pstr);
if (pvar < 0) if (pvar < 0) error->all(FLERR, "Variable name for compute dihedral/local does not exist");
error->all(FLERR,
"Variable name for compute dihedral/local does not exist");
if (!input->variable->internalstyle(pvar)) if (!input->variable->internalstyle(pvar))
error->all(FLERR, "Variable for compute dihedral/local is invalid style"); error->all(FLERR, "Variable for compute dihedral/local is invalid style");
} }
@ -114,8 +111,10 @@ ComputeDihedralLocal::ComputeDihedralLocal(LAMMPS *lmp, int narg, char **arg) :
// initialize output // initialize output
if (nvalues == 1) size_local_cols = 0; if (nvalues == 1)
else size_local_cols = nvalues; size_local_cols = 0;
else
size_local_cols = nvalues;
nmax = 0; nmax = 0;
vlocal = nullptr; vlocal = nullptr;
@ -147,16 +146,12 @@ void ComputeDihedralLocal::init()
if (nvar) { if (nvar) {
for (int i = 0; i < nvar; i++) { for (int i = 0; i < nvar; i++) {
vvar[i] = input->variable->find(vstr[i]); vvar[i] = input->variable->find(vstr[i]);
if (vvar[i] < 0) if (vvar[i] < 0) error->all(FLERR, "Variable name for compute dihedral/local does not exist");
error->all(FLERR,
"Variable name for compute dihedral/local does not exist");
} }
if (pstr) { if (pstr) {
pvar = input->variable->find(pstr); pvar = input->variable->find(pstr);
if (pvar < 0) if (pvar < 0) error->all(FLERR, "Variable name for compute dihedral/local does not exist");
error->all(FLERR,
"Variable name for compute dihedral/local does not exist");
} }
} }
@ -220,7 +215,8 @@ int ComputeDihedralLocal::compute_dihedrals(int flag)
for (atom2 = 0; atom2 < nlocal; atom2++) { for (atom2 = 0; atom2 < nlocal; atom2++) {
if (!(mask[atom2] & groupbit)) continue; if (!(mask[atom2] & groupbit)) continue;
if (molecular == Atom::MOLECULAR) nd = num_dihedral[atom2]; if (molecular == Atom::MOLECULAR)
nd = num_dihedral[atom2];
else { else {
if (molindex[atom2] < 0) continue; if (molindex[atom2] < 0) continue;
imol = molindex[atom2]; imol = molindex[atom2];
@ -297,8 +293,10 @@ int ComputeDihedralLocal::compute_dihedrals(int flag)
if (c < -1.0) c = -1.0; if (c < -1.0) c = -1.0;
phi = atan2(s, c); phi = atan2(s, c);
if (nvalues == 1) ptr = &vlocal[m]; if (nvalues == 1)
else ptr = alocal[m]; ptr = &vlocal[m];
else
ptr = alocal[m];
if (nvar) { if (nvar) {
ivar = 0; ivar = 0;

View File

@ -1,4 +1,3 @@
// clang-format off
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories https://www.lammps.org/, Sandia National Laboratories
@ -13,36 +12,35 @@
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "compute_improper_local.h" #include "compute_improper_local.h"
#include <cmath>
#include <cstring>
#include "atom.h" #include "atom.h"
#include "atom_vec.h" #include "atom_vec.h"
#include "molecule.h"
#include "update.h"
#include "domain.h" #include "domain.h"
#include "error.h"
#include "force.h" #include "force.h"
#include "math_const.h" #include "math_const.h"
#include "memory.h" #include "memory.h"
#include "error.h" #include "molecule.h"
#include "update.h"
#include <cmath>
#include <cstring>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace MathConst; using namespace MathConst;
static constexpr int DELTA = 10000; static constexpr int DELTA = 10000;
static constexpr double SMALL = 0.001; static constexpr double SMALL = 0.001;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
ComputeImproperLocal::ComputeImproperLocal(LAMMPS *lmp, int narg, char **arg) : ComputeImproperLocal::ComputeImproperLocal(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg), Compute(lmp, narg, arg), vlocal(nullptr), alocal(nullptr)
vlocal(nullptr), alocal(nullptr)
{ {
if (narg < 4) error->all(FLERR, "Illegal compute improper/local command"); if (narg < 4) error->all(FLERR, "Illegal compute improper/local command");
if (atom->avec->impropers_allow == 0) if (atom->avec->impropers_allow == 0)
error->all(FLERR, error->all(FLERR, "Compute improper/local used when impropers are not allowed");
"Compute improper/local used when impropers are not allowed");
local_flag = 1; local_flag = 1;
nvalues = narg - 3; nvalues = narg - 3;
@ -50,12 +48,16 @@ ComputeImproperLocal::ComputeImproperLocal(LAMMPS *lmp, int narg, char **arg) :
nvalues = 0; nvalues = 0;
for (int iarg = 3; iarg < narg; iarg++) { for (int iarg = 3; iarg < narg; iarg++) {
if (strcmp(arg[iarg],"chi") == 0) cflag = nvalues++; if (strcmp(arg[iarg], "chi") == 0)
else error->all(FLERR,"Invalid keyword in compute improper/local command"); cflag = nvalues++;
else
error->all(FLERR, "Invalid keyword in compute improper/local command");
} }
if (nvalues == 1) size_local_cols = 0; if (nvalues == 1)
else size_local_cols = nvalues; size_local_cols = 0;
else
size_local_cols = nvalues;
nmax = 0; nmax = 0;
vlocal = nullptr; vlocal = nullptr;
@ -135,8 +137,10 @@ int ComputeImproperLocal::compute_impropers(int flag)
if (nvalues == 1) { if (nvalues == 1) {
if (cflag >= 0) cbuf = vlocal; if (cflag >= 0) cbuf = vlocal;
} else { } else {
if (cflag >= 0 && alocal) cbuf = &alocal[0][cflag]; if (cflag >= 0 && alocal)
else cbuf = nullptr; cbuf = &alocal[0][cflag];
else
cbuf = nullptr;
} }
} }
@ -144,7 +148,8 @@ int ComputeImproperLocal::compute_impropers(int flag)
for (atom2 = 0; atom2 < nlocal; atom2++) { for (atom2 = 0; atom2 < nlocal; atom2++) {
if (!(mask[atom2] & groupbit)) continue; if (!(mask[atom2] & groupbit)) continue;
if (molecular == Atom::MOLECULAR) ni = num_improper[atom2]; if (molecular == Atom::MOLECULAR)
ni = num_improper[atom2];
else { else {
if (molindex[atom2] < 0) continue; if (molindex[atom2] < 0) continue;
imol = molindex[atom2]; imol = molindex[atom2];