enable and apply clang-format, improve error messages.

This commit is contained in:
Axel Kohlmeyer
2023-02-22 10:10:15 -05:00
parent 1411d48d9e
commit 94ac3895f9

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
@ -31,11 +30,11 @@ using namespace FixConst;
enum { XLO = 0, XHI = 1, YLO = 2, YHI = 3, ZLO = 4, ZHI = 5 }; enum { XLO = 0, XHI = 1, YLO = 2, YHI = 3, ZLO = 4, ZHI = 5 };
enum { NONE = 0, EDGE, CONSTANT, VARIABLE }; enum { NONE = 0, EDGE, CONSTANT, VARIABLE };
static const char *wallpos[] = {"xlo", "xhi", "ylo", "yhi", "zlo", "zhi"};
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
FixWall::FixWall(LAMMPS *lmp, int narg, char **arg) : FixWall::FixWall(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), nwall(0)
Fix(lmp, narg, arg),
nwall(0)
{ {
scalar_flag = 1; scalar_flag = 1;
vector_flag = 1; vector_flag = 1;
@ -70,24 +69,34 @@ FixWall::FixWall(LAMMPS *lmp, int narg, char **arg) :
if (iarg + 4 > narg) error->all(FLERR, "Missing argument for fix {} command", style); if (iarg + 4 > narg) error->all(FLERR, "Missing argument for fix {} command", style);
int newwall; int newwall;
if (strcmp(arg[iarg],"xlo") == 0) newwall = XLO; if (strcmp(arg[iarg], "xlo") == 0) {
else if (strcmp(arg[iarg],"xhi") == 0) newwall = XHI; newwall = XLO;
else if (strcmp(arg[iarg],"ylo") == 0) newwall = YLO; } else if (strcmp(arg[iarg], "xhi") == 0) {
else if (strcmp(arg[iarg],"yhi") == 0) newwall = YHI; newwall = XHI;
else if (strcmp(arg[iarg],"zlo") == 0) newwall = ZLO; } else if (strcmp(arg[iarg], "ylo") == 0) {
else if (strcmp(arg[iarg],"zhi") == 0) newwall = ZHI; newwall = YLO;
} else if (strcmp(arg[iarg], "yhi") == 0) {
for (int m = 0; (m < nwall) && (m < 6); m++) newwall = YHI;
} else if (strcmp(arg[iarg], "zlo") == 0) {
newwall = ZLO;
} else if (strcmp(arg[iarg], "zhi") == 0) {
newwall = ZHI;
}
for (int m = 0; (m < nwall) && (m < 6); m++) {
if (newwall == wallwhich[m]) if (newwall == wallwhich[m])
error->all(FLERR,"Wall defined twice in fix wall command"); error->all(FLERR, "{} wall defined twice in fix {} command", wallpos[newwall], style);
}
wallwhich[nwall] = newwall; wallwhich[nwall] = newwall;
if (strcmp(arg[iarg + 1], "EDGE") == 0) { if (strcmp(arg[iarg + 1], "EDGE") == 0) {
xstyle[nwall] = EDGE; xstyle[nwall] = EDGE;
int dim = wallwhich[nwall] / 2; int dim = wallwhich[nwall] / 2;
int side = wallwhich[nwall] % 2; int side = wallwhich[nwall] % 2;
if (side == 0) coord0[nwall] = domain->boxlo[dim]; if (side == 0) {
else coord0[nwall] = domain->boxhi[dim]; coord0[nwall] = domain->boxlo[dim];
} else {
coord0[nwall] = domain->boxhi[dim];
}
} else if (utils::strmatch(arg[iarg + 1], "^v_")) { } else if (utils::strmatch(arg[iarg + 1], "^v_")) {
xstyle[nwall] = VARIABLE; xstyle[nwall] = VARIABLE;
xstr[nwall] = utils::strdup(arg[iarg + 1] + 2); xstr[nwall] = utils::strdup(arg[iarg + 1] + 2);
@ -140,44 +149,48 @@ FixWall::FixWall(LAMMPS *lmp, int narg, char **arg) :
iarg += 5; iarg += 5;
} }
} else if (strcmp(arg[iarg], "units") == 0) { } else if (strcmp(arg[iarg], "units") == 0) {
} else if (strcmp(arg[iarg],"units") == 0) { if (iarg + 2 > narg) error->all(FLERR, "Illegal fix {} command", style);
if (iarg+2 > narg) error->all(FLERR,"Illegal fix wall command"); if (strcmp(arg[iarg + 1], "box") == 0)
if (strcmp(arg[iarg+1],"box") == 0) scaleflag = 0; scaleflag = 0;
else if (strcmp(arg[iarg+1],"lattice") == 0) scaleflag = 1; else if (strcmp(arg[iarg + 1], "lattice") == 0)
else error->all(FLERR,"Illegal fix wall command"); scaleflag = 1;
else
error->all(FLERR, "Illegal fix {} command", style);
iarg += 2; iarg += 2;
} else if (strcmp(arg[iarg], "fld") == 0) { } else if (strcmp(arg[iarg], "fld") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix wall command"); if (iarg + 2 > narg) error->all(FLERR, "Illegal fix {} command", style);
fldflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); fldflag = utils::logical(FLERR, arg[iarg + 1], false, lmp);
iarg += 2; iarg += 2;
} else if (strcmp(arg[iarg], "pbc") == 0) { } else if (strcmp(arg[iarg], "pbc") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix wall command"); if (iarg + 2 > narg) error->all(FLERR, "Illegal fix {} command", style);
pbcflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); pbcflag = utils::logical(FLERR, arg[iarg + 1], false, lmp);
iarg += 2; iarg += 2;
} else error->all(FLERR,"Illegal fix wall command"); } else
error->all(FLERR, "Illegal fix {} command", style);
} }
size_vector = nwall; size_vector = nwall;
// error checks // error checks
if (nwall == 0) error->all(FLERR,"Illegal fix wall command"); if (nwall == 0) error->all(FLERR, "Illegal fix {} command: no walls defined", style);
for (int m = 0; m < nwall; m++) for (int m = 0; m < nwall; m++) {
if (cutoff[m] <= 0.0) if (cutoff[m] <= 0.0)
error->all(FLERR,"Fix wall cutoff <= 0.0"); error->all(FLERR, "Fix {} cutoff <= 0.0 for {} wall", style, wallpos[wallwhich[m]]);
}
for (int m = 0; m < nwall; m++) for (int m = 0; m < nwall; m++)
if ((wallwhich[m] == ZLO || wallwhich[m] == ZHI) && domain->dimension == 2) if ((wallwhich[m] == ZLO || wallwhich[m] == ZHI) && domain->dimension == 2)
error->all(FLERR,"Cannot use fix wall zlo/zhi for a 2d simulation"); error->all(FLERR, "Cannot use fix {} zlo/zhi for a 2d simulation", style);
if (!pbcflag) { if (!pbcflag) {
for (int m = 0; m < nwall; m++) { for (int m = 0; m < nwall; m++) {
if ((wallwhich[m] == XLO || wallwhich[m] == XHI) && domain->xperiodic) if ((wallwhich[m] == XLO || wallwhich[m] == XHI) && domain->xperiodic)
error->all(FLERR,"Cannot use fix wall in periodic dimension"); error->all(FLERR, "Cannot use {} wall in periodic x dimension", wallpos[wallwhich[m]]);
if ((wallwhich[m] == YLO || wallwhich[m] == YHI) && domain->yperiodic) if ((wallwhich[m] == YLO || wallwhich[m] == YHI) && domain->yperiodic)
error->all(FLERR,"Cannot use fix wall in periodic dimension"); error->all(FLERR, "Cannot use {} wall in periodic y dimension", wallpos[wallwhich[m]]);
if ((wallwhich[m] == ZLO || wallwhich[m] == ZHI) && domain->zperiodic) if ((wallwhich[m] == ZLO || wallwhich[m] == ZHI) && domain->zperiodic)
error->all(FLERR,"Cannot use fix wall in periodic dimension"); error->all(FLERR, "Cannot use {} wall in periodic z dimension", wallpos[wallwhich[m]]);
} }
} }
@ -192,14 +205,17 @@ FixWall::FixWall(LAMMPS *lmp, int narg, char **arg) :
xscale = domain->lattice->xlattice; xscale = domain->lattice->xlattice;
yscale = domain->lattice->ylattice; yscale = domain->lattice->ylattice;
zscale = domain->lattice->zlattice; zscale = domain->lattice->zlattice;
} } else
else xscale = yscale = zscale = 1.0; xscale = yscale = zscale = 1.0;
for (int m = 0; m < nwall; m++) { for (int m = 0; m < nwall; m++) {
if (xstyle[m] != CONSTANT) continue; if (xstyle[m] != CONSTANT) continue;
if (wallwhich[m] < YLO) coord0[m] *= xscale; if (wallwhich[m] < YLO)
else if (wallwhich[m] < ZLO) coord0[m] *= yscale; coord0[m] *= xscale;
else coord0[m] *= zscale; else if (wallwhich[m] < ZLO)
coord0[m] *= yscale;
else
coord0[m] *= zscale;
} }
} }
@ -211,8 +227,10 @@ FixWall::FixWall(LAMMPS *lmp, int narg, char **arg) :
for (int m = 0; m < nwall; m++) { for (int m = 0; m < nwall; m++) {
if (xstyle[m] == VARIABLE) xflag = 1; if (xstyle[m] == VARIABLE) xflag = 1;
if (xflag || estyle[m] == VARIABLE || sstyle[m] == VARIABLE) varflag = 1; if (xflag || estyle[m] == VARIABLE || sstyle[m] == VARIABLE) varflag = 1;
if (estyle[m] == VARIABLE || sstyle[m] == VARIABLE) wstyle[m] = VARIABLE; if (estyle[m] == VARIABLE || sstyle[m] == VARIABLE)
else wstyle[m] = CONSTANT; wstyle[m] = VARIABLE;
else
wstyle[m] = CONSTANT;
} }
eflag = 0; eflag = 0;
@ -229,6 +247,8 @@ FixWall::~FixWall()
delete[] xstr[m]; delete[] xstr[m];
delete[] estr[m]; delete[] estr[m];
delete[] sstr[m]; delete[] sstr[m];
delete[] lstr[m];
delete[] tstr[m];
} }
} }
@ -240,8 +260,10 @@ int FixWall::setmask()
// FLD implicit needs to invoke wall forces before pair style // FLD implicit needs to invoke wall forces before pair style
if (fldflag) mask |= PRE_FORCE; if (fldflag)
else mask |= POST_FORCE; mask |= PRE_FORCE;
else
mask |= POST_FORCE;
mask |= POST_FORCE_RESPA; mask |= POST_FORCE_RESPA;
mask |= MIN_POST_FORCE; mask |= MIN_POST_FORCE;
@ -255,22 +277,19 @@ void FixWall::init()
for (int m = 0; m < nwall; m++) { for (int m = 0; m < nwall; m++) {
if (xstyle[m] == VARIABLE) { if (xstyle[m] == VARIABLE) {
xindex[m] = input->variable->find(xstr[m]); xindex[m] = input->variable->find(xstr[m]);
if (xindex[m] < 0) if (xindex[m] < 0) error->all(FLERR, "Variable name for fix wall does not exist");
error->all(FLERR,"Variable name for fix wall does not exist");
if (!input->variable->equalstyle(xindex[m])) if (!input->variable->equalstyle(xindex[m]))
error->all(FLERR, "Variable for fix wall is invalid style"); error->all(FLERR, "Variable for fix wall is invalid style");
} }
if (estyle[m] == VARIABLE) { if (estyle[m] == VARIABLE) {
eindex[m] = input->variable->find(estr[m]); eindex[m] = input->variable->find(estr[m]);
if (eindex[m] < 0) if (eindex[m] < 0) error->all(FLERR, "Variable name for fix wall does not exist");
error->all(FLERR,"Variable name for fix wall does not exist");
if (!input->variable->equalstyle(eindex[m])) if (!input->variable->equalstyle(eindex[m]))
error->all(FLERR, "Variable for fix wall is invalid style"); error->all(FLERR, "Variable for fix wall is invalid style");
} }
if (sstyle[m] == VARIABLE) { if (sstyle[m] == VARIABLE) {
sindex[m] = input->variable->find(sstr[m]); sindex[m] = input->variable->find(sstr[m]);
if (sindex[m] < 0) if (sindex[m] < 0) error->all(FLERR, "Variable name for fix wall does not exist");
error->all(FLERR,"Variable name for fix wall does not exist");
if (!input->variable->equalstyle(sindex[m])) if (!input->variable->equalstyle(sindex[m]))
error->all(FLERR, "Variable for fix wall is invalid style"); error->all(FLERR, "Variable for fix wall is invalid style");
} }
@ -339,20 +358,22 @@ void FixWall::post_force(int vflag)
for (int m = 0; m < nwall; m++) { for (int m = 0; m < nwall; m++) {
if (xstyle[m] == VARIABLE) { if (xstyle[m] == VARIABLE) {
coord = input->variable->compute_equal(xindex[m]); coord = input->variable->compute_equal(xindex[m]);
if (wallwhich[m] < YLO) coord *= xscale; if (wallwhich[m] < YLO)
else if (wallwhich[m] < ZLO) coord *= yscale; coord *= xscale;
else coord *= zscale; else if (wallwhich[m] < ZLO)
} else coord = coord0[m]; coord *= yscale;
else
coord *= zscale;
} else
coord = coord0[m];
if (wstyle[m] == VARIABLE) { if (wstyle[m] == VARIABLE) {
if (estyle[m] == VARIABLE) { if (estyle[m] == VARIABLE) {
epsilon[m] = input->variable->compute_equal(eindex[m]); epsilon[m] = input->variable->compute_equal(eindex[m]);
if (epsilon[m] < 0.0) if (epsilon[m] < 0.0) error->all(FLERR, "Variable evaluation in fix wall gave bad value");
error->all(FLERR,"Variable evaluation in fix wall gave bad value");
} }
if (sstyle[m] == VARIABLE) { if (sstyle[m] == VARIABLE) {
sigma[m] = input->variable->compute_equal(sindex[m]); sigma[m] = input->variable->compute_equal(sindex[m]);
if (sigma[m] < 0.0) if (sigma[m] < 0.0) error->all(FLERR, "Variable evaluation in fix wall gave bad value");
error->all(FLERR,"Variable evaluation in fix wall gave bad value");
} }
precompute(m); precompute(m);
} }