enable and apply clang-format, improve error messages.
This commit is contained in:
185
src/fix_wall.cpp
185
src/fix_wall.cpp
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -28,14 +27,14 @@
|
||||
using namespace LAMMPS_NS;
|
||||
using namespace FixConst;
|
||||
|
||||
enum{XLO=0,XHI=1,YLO=2,YHI=3,ZLO=4,ZHI=5};
|
||||
enum{NONE=0,EDGE,CONSTANT,VARIABLE};
|
||||
enum { XLO = 0, XHI = 1, YLO = 2, YHI = 3, ZLO = 4, ZHI = 5 };
|
||||
enum { NONE = 0, EDGE, CONSTANT, VARIABLE };
|
||||
|
||||
static const char *wallpos[] = {"xlo", "xhi", "ylo", "yhi", "zlo", "zhi"};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixWall::FixWall(LAMMPS *lmp, int narg, char **arg) :
|
||||
Fix(lmp, narg, arg),
|
||||
nwall(0)
|
||||
FixWall::FixWall(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), nwall(0)
|
||||
{
|
||||
scalar_flag = 1;
|
||||
vector_flag = 1;
|
||||
@ -64,36 +63,46 @@ FixWall::FixWall(LAMMPS *lmp, int narg, char **arg) :
|
||||
}
|
||||
|
||||
while (iarg < narg) {
|
||||
if ((strcmp(arg[iarg],"xlo") == 0) || (strcmp(arg[iarg],"xhi") == 0) ||
|
||||
(strcmp(arg[iarg],"ylo") == 0) || (strcmp(arg[iarg],"yhi") == 0) ||
|
||||
(strcmp(arg[iarg],"zlo") == 0) || (strcmp(arg[iarg],"zhi") == 0)) {
|
||||
if ((strcmp(arg[iarg], "xlo") == 0) || (strcmp(arg[iarg], "xhi") == 0) ||
|
||||
(strcmp(arg[iarg], "ylo") == 0) || (strcmp(arg[iarg], "yhi") == 0) ||
|
||||
(strcmp(arg[iarg], "zlo") == 0) || (strcmp(arg[iarg], "zhi") == 0)) {
|
||||
if (iarg + 4 > narg) error->all(FLERR, "Missing argument for fix {} command", style);
|
||||
|
||||
int newwall;
|
||||
if (strcmp(arg[iarg],"xlo") == 0) newwall = XLO;
|
||||
else if (strcmp(arg[iarg],"xhi") == 0) newwall = XHI;
|
||||
else if (strcmp(arg[iarg],"ylo") == 0) newwall = YLO;
|
||||
else if (strcmp(arg[iarg],"yhi") == 0) 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 (strcmp(arg[iarg], "xlo") == 0) {
|
||||
newwall = XLO;
|
||||
} else if (strcmp(arg[iarg], "xhi") == 0) {
|
||||
newwall = XHI;
|
||||
} else if (strcmp(arg[iarg], "ylo") == 0) {
|
||||
newwall = YLO;
|
||||
} else if (strcmp(arg[iarg], "yhi") == 0) {
|
||||
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])
|
||||
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;
|
||||
if (strcmp(arg[iarg+1],"EDGE") == 0) {
|
||||
|
||||
if (strcmp(arg[iarg + 1], "EDGE") == 0) {
|
||||
xstyle[nwall] = EDGE;
|
||||
int dim = wallwhich[nwall] / 2;
|
||||
int side = wallwhich[nwall] % 2;
|
||||
if (side == 0) coord0[nwall] = domain->boxlo[dim];
|
||||
else coord0[nwall] = domain->boxhi[dim];
|
||||
} else if (utils::strmatch(arg[iarg+1],"^v_")) {
|
||||
if (side == 0) {
|
||||
coord0[nwall] = domain->boxlo[dim];
|
||||
} else {
|
||||
coord0[nwall] = domain->boxhi[dim];
|
||||
}
|
||||
} else if (utils::strmatch(arg[iarg + 1], "^v_")) {
|
||||
xstyle[nwall] = VARIABLE;
|
||||
xstr[nwall] = utils::strdup(arg[iarg+1]+2);
|
||||
xstr[nwall] = utils::strdup(arg[iarg + 1] + 2);
|
||||
} else {
|
||||
xstyle[nwall] = CONSTANT;
|
||||
coord0[nwall] = utils::numeric(FLERR,arg[iarg+1],false,lmp);
|
||||
coord0[nwall] = utils::numeric(FLERR, arg[iarg + 1], false, lmp);
|
||||
}
|
||||
|
||||
if (utils::strmatch(style, "^wall/lepton")) {
|
||||
@ -140,44 +149,48 @@ FixWall::FixWall(LAMMPS *lmp, int narg, char **arg) :
|
||||
iarg += 5;
|
||||
}
|
||||
} else if (strcmp(arg[iarg], "units") == 0) {
|
||||
} else if (strcmp(arg[iarg],"units") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix wall command");
|
||||
if (strcmp(arg[iarg+1],"box") == 0) scaleflag = 0;
|
||||
else if (strcmp(arg[iarg+1],"lattice") == 0) scaleflag = 1;
|
||||
else error->all(FLERR,"Illegal fix wall command");
|
||||
if (iarg + 2 > narg) error->all(FLERR, "Illegal fix {} command", style);
|
||||
if (strcmp(arg[iarg + 1], "box") == 0)
|
||||
scaleflag = 0;
|
||||
else if (strcmp(arg[iarg + 1], "lattice") == 0)
|
||||
scaleflag = 1;
|
||||
else
|
||||
error->all(FLERR, "Illegal fix {} command", style);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"fld") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix wall command");
|
||||
fldflag = utils::logical(FLERR,arg[iarg+1],false,lmp);
|
||||
} else if (strcmp(arg[iarg], "fld") == 0) {
|
||||
if (iarg + 2 > narg) error->all(FLERR, "Illegal fix {} command", style);
|
||||
fldflag = utils::logical(FLERR, arg[iarg + 1], false, lmp);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"pbc") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix wall command");
|
||||
pbcflag = utils::logical(FLERR,arg[iarg+1],false,lmp);
|
||||
} else if (strcmp(arg[iarg], "pbc") == 0) {
|
||||
if (iarg + 2 > narg) error->all(FLERR, "Illegal fix {} command", style);
|
||||
pbcflag = utils::logical(FLERR, arg[iarg + 1], false, lmp);
|
||||
iarg += 2;
|
||||
} else error->all(FLERR,"Illegal fix wall command");
|
||||
} else
|
||||
error->all(FLERR, "Illegal fix {} command", style);
|
||||
}
|
||||
|
||||
size_vector = nwall;
|
||||
|
||||
// error checks
|
||||
|
||||
if (nwall == 0) error->all(FLERR,"Illegal fix wall command");
|
||||
for (int m = 0; m < nwall; m++)
|
||||
if (nwall == 0) error->all(FLERR, "Illegal fix {} command: no walls defined", style);
|
||||
for (int m = 0; m < nwall; m++) {
|
||||
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++)
|
||||
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) {
|
||||
for (int m = 0; m < nwall; m++) {
|
||||
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)
|
||||
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)
|
||||
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;
|
||||
yscale = domain->lattice->ylattice;
|
||||
zscale = domain->lattice->zlattice;
|
||||
}
|
||||
else xscale = yscale = zscale = 1.0;
|
||||
} else
|
||||
xscale = yscale = zscale = 1.0;
|
||||
|
||||
for (int m = 0; m < nwall; m++) {
|
||||
if (xstyle[m] != CONSTANT) continue;
|
||||
if (wallwhich[m] < YLO) coord0[m] *= xscale;
|
||||
else if (wallwhich[m] < ZLO) coord0[m] *= yscale;
|
||||
else coord0[m] *= zscale;
|
||||
if (wallwhich[m] < YLO)
|
||||
coord0[m] *= xscale;
|
||||
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++) {
|
||||
if (xstyle[m] == VARIABLE) xflag = 1;
|
||||
if (xflag || estyle[m] == VARIABLE || sstyle[m] == VARIABLE) varflag = 1;
|
||||
if (estyle[m] == VARIABLE || sstyle[m] == VARIABLE) wstyle[m] = VARIABLE;
|
||||
else wstyle[m] = CONSTANT;
|
||||
if (estyle[m] == VARIABLE || sstyle[m] == VARIABLE)
|
||||
wstyle[m] = VARIABLE;
|
||||
else
|
||||
wstyle[m] = CONSTANT;
|
||||
}
|
||||
|
||||
eflag = 0;
|
||||
@ -226,9 +244,11 @@ FixWall::~FixWall()
|
||||
if (copymode) return;
|
||||
|
||||
for (int m = 0; m < nwall; m++) {
|
||||
delete [] xstr[m];
|
||||
delete [] estr[m];
|
||||
delete [] sstr[m];
|
||||
delete[] xstr[m];
|
||||
delete[] estr[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
|
||||
|
||||
if (fldflag) mask |= PRE_FORCE;
|
||||
else mask |= POST_FORCE;
|
||||
if (fldflag)
|
||||
mask |= PRE_FORCE;
|
||||
else
|
||||
mask |= POST_FORCE;
|
||||
|
||||
mask |= POST_FORCE_RESPA;
|
||||
mask |= MIN_POST_FORCE;
|
||||
@ -255,24 +277,21 @@ void FixWall::init()
|
||||
for (int m = 0; m < nwall; m++) {
|
||||
if (xstyle[m] == VARIABLE) {
|
||||
xindex[m] = input->variable->find(xstr[m]);
|
||||
if (xindex[m] < 0)
|
||||
error->all(FLERR,"Variable name for fix wall does not exist");
|
||||
if (xindex[m] < 0) error->all(FLERR, "Variable name for fix wall does not exist");
|
||||
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) {
|
||||
eindex[m] = input->variable->find(estr[m]);
|
||||
if (eindex[m] < 0)
|
||||
error->all(FLERR,"Variable name for fix wall does not exist");
|
||||
if (eindex[m] < 0) error->all(FLERR, "Variable name for fix wall does not exist");
|
||||
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) {
|
||||
sindex[m] = input->variable->find(sstr[m]);
|
||||
if (sindex[m] < 0)
|
||||
error->all(FLERR,"Variable name for fix wall does not exist");
|
||||
if (sindex[m] < 0) error->all(FLERR, "Variable name for fix wall does not exist");
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,9 +299,9 @@ void FixWall::init()
|
||||
|
||||
for (int m = 0; m < nwall; m++) precompute(m);
|
||||
|
||||
if (utils::strmatch(update->integrate_style,"^respa")) {
|
||||
ilevel_respa = (dynamic_cast<Respa *>(update->integrate))->nlevels-1;
|
||||
if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa);
|
||||
if (utils::strmatch(update->integrate_style, "^respa")) {
|
||||
ilevel_respa = (dynamic_cast<Respa *>(update->integrate))->nlevels - 1;
|
||||
if (respa_level >= 0) ilevel_respa = MIN(respa_level, ilevel_respa);
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,11 +309,11 @@ void FixWall::init()
|
||||
|
||||
void FixWall::setup(int vflag)
|
||||
{
|
||||
if (utils::strmatch(update->integrate_style,"^verlet")) {
|
||||
if (utils::strmatch(update->integrate_style, "^verlet")) {
|
||||
if (!fldflag) post_force(vflag);
|
||||
} else {
|
||||
(dynamic_cast<Respa *>(update->integrate))->copy_flevel_f(ilevel_respa);
|
||||
post_force_respa(vflag,ilevel_respa,0);
|
||||
post_force_respa(vflag, ilevel_respa, 0);
|
||||
(dynamic_cast<Respa *>(update->integrate))->copy_f_flevel(ilevel_respa);
|
||||
}
|
||||
}
|
||||
@ -339,25 +358,27 @@ void FixWall::post_force(int vflag)
|
||||
for (int m = 0; m < nwall; m++) {
|
||||
if (xstyle[m] == VARIABLE) {
|
||||
coord = input->variable->compute_equal(xindex[m]);
|
||||
if (wallwhich[m] < YLO) coord *= xscale;
|
||||
else if (wallwhich[m] < ZLO) coord *= yscale;
|
||||
else coord *= zscale;
|
||||
} else coord = coord0[m];
|
||||
if (wallwhich[m] < YLO)
|
||||
coord *= xscale;
|
||||
else if (wallwhich[m] < ZLO)
|
||||
coord *= yscale;
|
||||
else
|
||||
coord *= zscale;
|
||||
} else
|
||||
coord = coord0[m];
|
||||
if (wstyle[m] == VARIABLE) {
|
||||
if (estyle[m] == VARIABLE) {
|
||||
epsilon[m] = input->variable->compute_equal(eindex[m]);
|
||||
if (epsilon[m] < 0.0)
|
||||
error->all(FLERR,"Variable evaluation in fix wall gave bad value");
|
||||
if (epsilon[m] < 0.0) error->all(FLERR, "Variable evaluation in fix wall gave bad value");
|
||||
}
|
||||
if (sstyle[m] == VARIABLE) {
|
||||
sigma[m] = input->variable->compute_equal(sindex[m]);
|
||||
if (sigma[m] < 0.0)
|
||||
error->all(FLERR,"Variable evaluation in fix wall gave bad value");
|
||||
if (sigma[m] < 0.0) error->all(FLERR, "Variable evaluation in fix wall gave bad value");
|
||||
}
|
||||
precompute(m);
|
||||
}
|
||||
|
||||
wall_particle(m,wallwhich[m],coord);
|
||||
wall_particle(m, wallwhich[m], coord);
|
||||
}
|
||||
|
||||
if (varflag) modify->addstep_compute(update->ntimestep + 1);
|
||||
@ -386,7 +407,7 @@ double FixWall::compute_scalar()
|
||||
// only sum across procs one time
|
||||
|
||||
if (eflag == 0) {
|
||||
MPI_Allreduce(ewall,ewall_all,nwall+1,MPI_DOUBLE,MPI_SUM,world);
|
||||
MPI_Allreduce(ewall, ewall_all, nwall + 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
eflag = 1;
|
||||
}
|
||||
return ewall_all[0];
|
||||
@ -401,8 +422,8 @@ double FixWall::compute_vector(int n)
|
||||
// only sum across procs one time
|
||||
|
||||
if (eflag == 0) {
|
||||
MPI_Allreduce(ewall,ewall_all,nwall+1,MPI_DOUBLE,MPI_SUM,world);
|
||||
MPI_Allreduce(ewall, ewall_all, nwall + 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
eflag = 1;
|
||||
}
|
||||
return ewall_all[n+1];
|
||||
return ewall_all[n + 1];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user