enable and apply clang-format, revert to some older code constructs where equivalent

This commit is contained in:
Axel Kohlmeyer
2024-03-08 12:23:02 -05:00
parent bd0eb1ec84
commit e7d77b6244

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,15 +34,14 @@
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace FixConst; using namespace FixConst;
enum{NONE, SPHERE, CYLINDER, PLANE, CONE}; enum { NONE, SPHERE, CYLINDER, PLANE, CONE };
enum{INSIDE, OUTSIDE}; enum { INSIDE, OUTSIDE };
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
FixIndent::FixIndent(LAMMPS *lmp, int narg, char **arg) : FixIndent::FixIndent(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg), Fix(lmp, narg, arg), xstr(nullptr), ystr(nullptr), zstr(nullptr), rstr(nullptr), pstr(nullptr),
xstr(nullptr), ystr(nullptr), zstr(nullptr), rstr(nullptr), pstr(nullptr), rlostr(nullptr), rhistr(nullptr), lostr(nullptr), histr(nullptr)
rlostr(nullptr), rhistr(nullptr), lostr(nullptr), histr(nullptr)
{ {
if (narg < 4) utils::missing_cmd_args(FLERR, "fix indent", error); if (narg < 4) utils::missing_cmd_args(FLERR, "fix indent", error);
@ -57,20 +55,20 @@ FixIndent::FixIndent(LAMMPS *lmp, int narg, char **arg) :
respa_level_support = 1; respa_level_support = 1;
ilevel_respa = 0; ilevel_respa = 0;
k = utils::numeric(FLERR,arg[3],false,lmp); k = utils::numeric(FLERR, arg[3], false, lmp);
if (k < 0.0) error->all(FLERR, "Illegal fix indent force constant: {}", k); if (k < 0.0) error->all(FLERR, "Illegal fix indent force constant: {}", k);
k3 = k/3.0; k3 = k / 3.0;
// read geometry of indenter and optional args // read geometry of indenter and optional args
int iarg = geometry(narg-4,&arg[4]) + 4; int iarg = geometry(narg - 4, &arg[4]) + 4;
options(narg-iarg,&arg[iarg]); options(narg - iarg, &arg[iarg]);
// setup scaling // setup scaling
const double xscale { scaleflag ? domain->lattice->xlattice : 1.0}; const double xscale{scaleflag ? domain->lattice->xlattice : 1.0};
const double yscale { scaleflag ? domain->lattice->ylattice : 1.0}; const double yscale{scaleflag ? domain->lattice->ylattice : 1.0};
const double zscale { scaleflag ? domain->lattice->zlattice : 1.0}; const double zscale{scaleflag ? domain->lattice->zlattice : 1.0};
// apply scaling factors to geometry // apply scaling factors to geometry
@ -104,11 +102,15 @@ FixIndent::FixIndent(LAMMPS *lmp, int narg, char **arg) :
if (!histr) hivalue *= scaling_factor; if (!histr) hivalue *= scaling_factor;
} else if (istyle == PLANE) { } else if (istyle == PLANE) {
if (cdim == 0 && !pstr) pvalue *= xscale; if (cdim == 0 && !pstr)
else if (cdim == 1 && !pstr) pvalue *= yscale; pvalue *= xscale;
else if (cdim == 2 && !pstr) pvalue *= zscale; else if (cdim == 1 && !pstr)
pvalue *= yscale;
else if (cdim == 2 && !pstr)
pvalue *= zscale;
} else error->all(FLERR,"Unknown fix indent keyword: {}", istyle); } else
error->all(FLERR, "Unknown fix indent keyword: {}", istyle);
varflag = 0; varflag = 0;
if (xstr || ystr || zstr || rstr || pstr || rlostr || rhistr || lostr || histr) varflag = 1; if (xstr || ystr || zstr || rstr || pstr || rlostr || rhistr || lostr || histr) varflag = 1;
@ -121,15 +123,15 @@ FixIndent::FixIndent(LAMMPS *lmp, int narg, char **arg) :
FixIndent::~FixIndent() FixIndent::~FixIndent()
{ {
delete [] xstr; delete[] xstr;
delete [] ystr; delete[] ystr;
delete [] zstr; delete[] zstr;
delete [] rstr; delete[] rstr;
delete [] pstr; delete[] pstr;
delete [] rlostr; delete[] rlostr;
delete [] rhistr; delete[] rhistr;
delete [] lostr; delete[] lostr;
delete [] histr; delete[] histr;
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
@ -149,71 +151,62 @@ void FixIndent::init()
{ {
if (xstr) { if (xstr) {
xvar = input->variable->find(xstr); xvar = input->variable->find(xstr);
if (xvar < 0) if (xvar < 0) error->all(FLERR, "Variable {} for fix indent does not exist", xstr);
error->all(FLERR,"Variable {} for fix indent does not exist", xstr);
if (!input->variable->equalstyle(xvar)) if (!input->variable->equalstyle(xvar))
error->all(FLERR,"Variable {} for fix indent is invalid style", xstr); error->all(FLERR, "Variable {} for fix indent is invalid style", xstr);
} }
if (ystr) { if (ystr) {
yvar = input->variable->find(ystr); yvar = input->variable->find(ystr);
if (yvar < 0) if (yvar < 0) error->all(FLERR, "Variable {} for fix indent does not exist", ystr);
error->all(FLERR,"Variable {} for fix indent does not exist", ystr);
if (!input->variable->equalstyle(yvar)) if (!input->variable->equalstyle(yvar))
error->all(FLERR,"Variable {} for fix indent is invalid style", ystr); error->all(FLERR, "Variable {} for fix indent is invalid style", ystr);
} }
if (zstr) { if (zstr) {
zvar = input->variable->find(zstr); zvar = input->variable->find(zstr);
if (zvar < 0) if (zvar < 0) error->all(FLERR, "Variable {} for fix indent does not exist", zstr);
error->all(FLERR,"Variable {} for fix indent does not exist", zstr);
if (!input->variable->equalstyle(zvar)) if (!input->variable->equalstyle(zvar))
error->all(FLERR,"Variable {} for fix indent is invalid style", zstr); error->all(FLERR, "Variable {} for fix indent is invalid style", zstr);
} }
if (rstr) { if (rstr) {
rvar = input->variable->find(rstr); rvar = input->variable->find(rstr);
if (rvar < 0) if (rvar < 0) error->all(FLERR, "Variable {} for fix indent does not exist", rstr);
error->all(FLERR,"Variable {} for fix indent does not exist", rstr);
if (!input->variable->equalstyle(rvar)) if (!input->variable->equalstyle(rvar))
error->all(FLERR,"Variable {} for fix indent is invalid style", rstr); error->all(FLERR, "Variable {} for fix indent is invalid style", rstr);
} }
if (pstr) { if (pstr) {
pvar = input->variable->find(pstr); pvar = input->variable->find(pstr);
if (pvar < 0) if (pvar < 0) error->all(FLERR, "Variable {} for fix indent does not exist", pstr);
error->all(FLERR,"Variable {} for fix indent does not exist", pstr);
if (!input->variable->equalstyle(pvar)) if (!input->variable->equalstyle(pvar))
error->all(FLERR,"Variable {} for fix indent is invalid style", pstr); error->all(FLERR, "Variable {} for fix indent is invalid style", pstr);
} }
if (rlostr) { if (rlostr) {
rlovar = input->variable->find(rlostr); rlovar = input->variable->find(rlostr);
if (rlovar < 0) if (rlovar < 0) error->all(FLERR, "Variable {} for fix indent does not exist", rlostr);
error->all(FLERR,"Variable {} for fix indent does not exist", rlostr);
if (!input->variable->equalstyle(rlovar)) if (!input->variable->equalstyle(rlovar))
error->all(FLERR,"Variable {} for fix indent is invalid style", rlostr); error->all(FLERR, "Variable {} for fix indent is invalid style", rlostr);
} }
if (rhistr) { if (rhistr) {
rhivar = input->variable->find(rhistr); rhivar = input->variable->find(rhistr);
if (rhivar < 0) if (rhivar < 0) error->all(FLERR, "Variable {} for fix indent does not exist", rhistr);
error->all(FLERR,"Variable {} for fix indent does not exist", rhistr);
if (!input->variable->equalstyle(rhivar)) if (!input->variable->equalstyle(rhivar))
error->all(FLERR,"Variable {} for fix indent is invalid style", rhistr); error->all(FLERR, "Variable {} for fix indent is invalid style", rhistr);
} }
if (lostr) { if (lostr) {
lovar = input->variable->find(lostr); lovar = input->variable->find(lostr);
if (lovar < 0) if (lovar < 0) error->all(FLERR, "Variable {} for fix indent does not exist", lostr);
error->all(FLERR,"Variable {} for fix indent does not exist", lostr);
if (!input->variable->equalstyle(lovar)) if (!input->variable->equalstyle(lovar))
error->all(FLERR,"Variable {} for fix indent is invalid style", lostr); error->all(FLERR, "Variable {} for fix indent is invalid style", lostr);
} }
if (histr) { if (histr) {
hivar = input->variable->find(histr); hivar = input->variable->find(histr);
if (hivar < 0) if (hivar < 0) error->all(FLERR, "Variable {} for fix indent does not exist", histr);
error->all(FLERR,"Variable {} for fix indent does not exist", histr);
if (!input->variable->equalstyle(hivar)) if (!input->variable->equalstyle(hivar))
error->all(FLERR,"Variable {} for fix indent is invalid style", histr); error->all(FLERR, "Variable {} for fix indent is invalid style", histr);
} }
if (utils::strmatch(update->integrate_style,"^respa")) { if (utils::strmatch(update->integrate_style, "^respa")) {
ilevel_respa = (dynamic_cast<Respa *>(update->integrate))->nlevels-1; ilevel_respa = (dynamic_cast<Respa *>(update->integrate))->nlevels - 1;
if (respa_level >= 0) ilevel_respa = MIN(respa_level,ilevel_respa); if (respa_level >= 0) ilevel_respa = MIN(respa_level, ilevel_respa);
} }
} }
@ -221,11 +214,11 @@ void FixIndent::init()
void FixIndent::setup(int vflag) void FixIndent::setup(int vflag)
{ {
if (utils::strmatch(update->integrate_style,"^verlet")) if (utils::strmatch(update->integrate_style, "^verlet"))
post_force(vflag); post_force(vflag);
else { else {
(dynamic_cast<Respa *>(update->integrate))->copy_flevel_f(ilevel_respa); (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); (dynamic_cast<Respa *>(update->integrate))->copy_f_flevel(ilevel_respa);
} }
} }
@ -251,7 +244,7 @@ void FixIndent::post_force(int /*vflag*/)
// ctr = current indenter centerz // ctr = current indenter centerz
double ctr[3] {xvalue, yvalue, zvalue}; double ctr[3] = {xvalue, yvalue, zvalue};
if (xstr) ctr[0] = input->variable->compute_equal(xvar); if (xstr) ctr[0] = input->variable->compute_equal(xvar);
if (ystr) ctr[1] = input->variable->compute_equal(yvar); if (ystr) ctr[1] = input->variable->compute_equal(yvar);
if (zstr) ctr[2] = input->variable->compute_equal(zvar); if (zstr) ctr[2] = input->variable->compute_equal(zvar);
@ -271,7 +264,7 @@ void FixIndent::post_force(int /*vflag*/)
domain->remap(ctr); domain->remap(ctr);
double radius { rstr ? input->variable->compute_equal(rvar) : rvalue}; double radius = rstr ? input->variable->compute_equal(rvar) : rvalue;
if (radius < 0.0) error->all(FLERR, "Illegal fix indent sphere radius: {}", radius); if (radius < 0.0) error->all(FLERR, "Illegal fix indent sphere radius: {}", radius);
for (int i = 0; i < nlocal; i++) for (int i = 0; i < nlocal; i++)
@ -279,29 +272,29 @@ void FixIndent::post_force(int /*vflag*/)
delx = x[i][0] - ctr[0]; delx = x[i][0] - ctr[0];
dely = x[i][1] - ctr[1]; dely = x[i][1] - ctr[1];
delz = x[i][2] - ctr[2]; delz = x[i][2] - ctr[2];
domain->minimum_image(delx,dely,delz); domain->minimum_image(delx, dely, delz);
r = sqrt(delx*delx + dely*dely + delz*delz); r = sqrt(delx * delx + dely * dely + delz * delz);
if (side == OUTSIDE) { if (side == OUTSIDE) {
dr = r - radius; dr = r - radius;
fmag = k*dr*dr; fmag = k * dr * dr;
} else { } else {
dr = radius - r; dr = radius - r;
fmag = -k*dr*dr; fmag = -k * dr * dr;
} }
if (dr >= 0.0) continue; if (dr >= 0.0) continue;
fx = delx*fmag/r; fx = delx * fmag / r;
fy = dely*fmag/r; fy = dely * fmag / r;
fz = delz*fmag/r; fz = delz * fmag / r;
f[i][0] += fx; f[i][0] += fx;
f[i][1] += fy; f[i][1] += fy;
f[i][2] += fz; f[i][2] += fz;
indenter[0] -= k3 * dr*dr*dr; indenter[0] -= k3 * dr * dr * dr;
indenter[1] -= fx; indenter[1] -= fx;
indenter[2] -= fy; indenter[2] -= fy;
indenter[3] -= fz; indenter[3] -= fz;
} }
// cylindrical indenter // cylindrical indenter
} else if (istyle == CYLINDER) { } else if (istyle == CYLINDER) {
@ -312,46 +305,46 @@ void FixIndent::post_force(int /*vflag*/)
ctr[cdim] = domain->boxlo[cdim]; ctr[cdim] = domain->boxlo[cdim];
domain->remap(ctr); domain->remap(ctr);
double radius { rstr ? input->variable->compute_equal(rvar) : rvalue}; double radius{rstr ? input->variable->compute_equal(rvar) : rvalue};
if (radius < 0.0) error->all(FLERR, "Illegal fix indent cylinder radius: {}", radius); if (radius < 0.0) error->all(FLERR, "Illegal fix indent cylinder radius: {}", radius);
for (int i = 0; i < nlocal; i++) for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) { if (mask[i] & groupbit) {
double del[3] {x[i][0] - ctr[0], x[i][1] - ctr[1], x[i][2] - ctr[2]}; double del[3] = {x[i][0] - ctr[0], x[i][1] - ctr[1], x[i][2] - ctr[2]};
del[cdim] = 0; del[cdim] = 0;
domain->minimum_image(del[0], del[1], del[2]); domain->minimum_image(del[0], del[1], del[2]);
r = sqrt(del[0]*del[0] + del[1]*del[1] + del[2]*del[2]); r = sqrt(del[0] * del[0] + del[1] * del[1] + del[2] * del[2]);
if (side == OUTSIDE) { if (side == OUTSIDE) {
dr = r - radius; dr = r - radius;
fmag = k*dr*dr; fmag = k * dr * dr;
} else { } else {
dr = radius - r; dr = radius - r;
fmag = -k*dr*dr; fmag = -k * dr * dr;
} }
if (dr >= 0.0) continue; if (dr >= 0.0) continue;
fx = del[0]*fmag/r; fx = del[0] * fmag / r;
fy = del[1]*fmag/r; fy = del[1] * fmag / r;
fz = del[2]*fmag/r; fz = del[2] * fmag / r;
f[i][0] += fx; f[i][0] += fx;
f[i][1] += fy; f[i][1] += fy;
f[i][2] += fz; f[i][2] += fz;
indenter[0] -= k3 * dr*dr*dr; indenter[0] -= k3 * dr * dr * dr;
indenter[1] -= fx; indenter[1] -= fx;
indenter[2] -= fy; indenter[2] -= fy;
indenter[3] -= fz; indenter[3] -= fz;
} }
// conical indenter // conical indenter
} else if (istyle == CONE) { } else if (istyle == CONE) {
double radiuslo { rlostr ? input->variable->compute_equal(rlovar) : rlovalue }; double radiuslo{rlostr ? input->variable->compute_equal(rlovar) : rlovalue};
if (radiuslo < 0.0) error->all(FLERR, "Illegal fix indent cone lower radius: {}", radiuslo); if (radiuslo < 0.0) error->all(FLERR, "Illegal fix indent cone lower radius: {}", radiuslo);
double radiushi { rhistr ? input->variable->compute_equal(rhivar) : rhivalue }; double radiushi{rhistr ? input->variable->compute_equal(rhivar) : rhivalue};
if (radiushi < 0.0) error->all(FLERR, "Illegal fix indent cone high radius: {}", radiushi); if (radiushi < 0.0) error->all(FLERR, "Illegal fix indent cone high radius: {}", radiushi);
double initial_lo { lostr ? input->variable->compute_equal(lovar) : lovalue }; double initial_lo{lostr ? input->variable->compute_equal(lovar) : lovalue};
double initial_hi { histr ? input->variable->compute_equal(hivar) : hivalue }; double initial_hi{histr ? input->variable->compute_equal(hivar) : hivalue};
ctr[cdim] = 0.5 * (initial_hi + initial_lo); ctr[cdim] = 0.5 * (initial_hi + initial_lo);
@ -368,7 +361,7 @@ void FixIndent::post_force(int /*vflag*/)
delz = x[i][2] - ctr[2]; delz = x[i][2] - ctr[2];
domain->minimum_image(delx, dely, delz); domain->minimum_image(delx, dely, delz);
double x0[3] {delx + ctr[0], dely + ctr[1], delz + ctr[2]}; double x0[3] = {delx + ctr[0], dely + ctr[1], delz + ctr[2]};
r = sqrt(delx * delx + dely * dely + delz * delz); r = sqrt(delx * delx + dely * dely + delz * delz);
// check if particle is inside or outside the cone // check if particle is inside or outside the cone
@ -391,12 +384,12 @@ void FixIndent::post_force(int /*vflag*/)
dr = sqrt(x0[0] * x0[0] + x0[1] * x0[1] + x0[2] * x0[2]); dr = sqrt(x0[0] * x0[0] + x0[1] * x0[1] + x0[2] * x0[2]);
int force_sign = { point_inside_cone ? 1 : -1 }; int force_sign = {point_inside_cone ? 1 : -1};
fmag = force_sign * k * dr * dr; fmag = force_sign * k * dr * dr;
fx = delx*fmag/r; fx = delx * fmag / r;
fy = dely*fmag/r; fy = dely * fmag / r;
fz = delz*fmag/r; fz = delz * fmag / r;
f[i][0] += fx; f[i][0] += fx;
f[i][1] += fy; f[i][1] += fy;
f[i][2] += fz; f[i][2] += fz;
@ -407,13 +400,13 @@ void FixIndent::post_force(int /*vflag*/)
} }
} }
// planar indenter // planar indenter
} else { } else {
// plane = current plane position // plane = current plane position
double plane { pstr ? input->variable->compute_equal(pvar) : pvalue}; double plane{pstr ? input->variable->compute_equal(pvar) : pvalue};
for (int i = 0; i < nlocal; i++) for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) { if (mask[i] & groupbit) {
@ -422,7 +415,7 @@ void FixIndent::post_force(int /*vflag*/)
fmag = -planeside * k * dr * dr; fmag = -planeside * k * dr * dr;
f[i][cdim] += fmag; f[i][cdim] += fmag;
indenter[0] -= k3 * dr * dr * dr; indenter[0] -= k3 * dr * dr * dr;
indenter[cdim+1] -= fmag; indenter[cdim + 1] -= fmag;
} }
} }
@ -452,7 +445,7 @@ double FixIndent::compute_scalar()
// only sum across procs one time // only sum across procs one time
if (indenter_flag == 0) { if (indenter_flag == 0) {
MPI_Allreduce(indenter,indenter_all,4,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(indenter, indenter_all, 4, MPI_DOUBLE, MPI_SUM, world);
indenter_flag = 1; indenter_flag = 1;
} }
return indenter_all[0]; return indenter_all[0];
@ -467,10 +460,10 @@ double FixIndent::compute_vector(int n)
// only sum across procs one time // only sum across procs one time
if (indenter_flag == 0) { if (indenter_flag == 0) {
MPI_Allreduce(indenter,indenter_all,4,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(indenter, indenter_all, 4, MPI_DOUBLE, MPI_SUM, world);
indenter_flag = 1; indenter_flag = 1;
} }
return indenter_all[n+1]; return indenter_all[n + 1];
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
@ -487,22 +480,26 @@ int FixIndent::geometry(int narg, char **arg)
// sphere // sphere
if (strcmp(arg[0],"sphere") == 0) { if (strcmp(arg[0], "sphere") == 0) {
if (istyle != NONE) error->all(FLERR, "Fix indent requires a single geometry keyword"); if (istyle != NONE) error->all(FLERR, "Fix indent requires a single geometry keyword");
if (5 > narg) utils::missing_cmd_args(FLERR, "fix indent sphere", error); if (5 > narg) utils::missing_cmd_args(FLERR, "fix indent sphere", error);
if (utils::strmatch(arg[1],"^v_")) { if (utils::strmatch(arg[1], "^v_")) {
xstr = utils::strdup(arg[1]+2); xstr = utils::strdup(arg[1] + 2);
} else xvalue = utils::numeric(FLERR,arg[1],false,lmp); } else
if (utils::strmatch(arg[2],"^v_")) { xvalue = utils::numeric(FLERR, arg[1], false, lmp);
ystr = utils::strdup(arg[2]+2); if (utils::strmatch(arg[2], "^v_")) {
} else yvalue = utils::numeric(FLERR,arg[2],false,lmp); ystr = utils::strdup(arg[2] + 2);
if (utils::strmatch(arg[3],"^v_")) { } else
zstr = utils::strdup(arg[3]+2); yvalue = utils::numeric(FLERR, arg[2], false, lmp);
} else zvalue = utils::numeric(FLERR,arg[3],false,lmp); if (utils::strmatch(arg[3], "^v_")) {
if (utils::strmatch(arg[4],"^v_")) { zstr = utils::strdup(arg[3] + 2);
rstr = utils::strdup(arg[4]+2); } else
} else rvalue = utils::numeric(FLERR,arg[4],false,lmp); zvalue = utils::numeric(FLERR, arg[3], false, lmp);
if (utils::strmatch(arg[4], "^v_")) {
rstr = utils::strdup(arg[4] + 2);
} else
rvalue = utils::numeric(FLERR, arg[4], false, lmp);
istyle = SPHERE; istyle = SPHERE;
return 5; return 5;
@ -510,39 +507,47 @@ int FixIndent::geometry(int narg, char **arg)
// cylinder // cylinder
if (strcmp(arg[0],"cylinder") == 0) { if (strcmp(arg[0], "cylinder") == 0) {
if (istyle != NONE) error->all(FLERR, "Fix indent requires a single geometry keyword"); if (istyle != NONE) error->all(FLERR, "Fix indent requires a single geometry keyword");
if (5 > narg) utils::missing_cmd_args(FLERR, "fix indent cylinder", error); if (5 > narg) utils::missing_cmd_args(FLERR, "fix indent cylinder", error);
if (strcmp(arg[1],"x") == 0) { if (strcmp(arg[1], "x") == 0) {
cdim = 0; cdim = 0;
if (utils::strmatch(arg[2],"^v_")) { if (utils::strmatch(arg[2], "^v_")) {
ystr = utils::strdup(arg[2]+2); ystr = utils::strdup(arg[2] + 2);
} else yvalue = utils::numeric(FLERR,arg[2],false,lmp); } else
if (utils::strmatch(arg[3],"^v_")) { yvalue = utils::numeric(FLERR, arg[2], false, lmp);
zstr = utils::strdup(arg[3]+2); if (utils::strmatch(arg[3], "^v_")) {
} else zvalue = utils::numeric(FLERR,arg[3],false,lmp); zstr = utils::strdup(arg[3] + 2);
} else if (strcmp(arg[1],"y") == 0) { } else
zvalue = utils::numeric(FLERR, arg[3], false, lmp);
} else if (strcmp(arg[1], "y") == 0) {
cdim = 1; cdim = 1;
if (utils::strmatch(arg[2],"^v_")) { if (utils::strmatch(arg[2], "^v_")) {
xstr = utils::strdup(arg[2]+2); xstr = utils::strdup(arg[2] + 2);
} else xvalue = utils::numeric(FLERR,arg[2],false,lmp); } else
if (utils::strmatch(arg[3],"^v_")) { xvalue = utils::numeric(FLERR, arg[2], false, lmp);
zstr = utils::strdup(arg[3]+2); if (utils::strmatch(arg[3], "^v_")) {
} else zvalue = utils::numeric(FLERR,arg[3],false,lmp); zstr = utils::strdup(arg[3] + 2);
} else if (strcmp(arg[1],"z") == 0) { } else
zvalue = utils::numeric(FLERR, arg[3], false, lmp);
} else if (strcmp(arg[1], "z") == 0) {
cdim = 2; cdim = 2;
if (utils::strmatch(arg[2],"^v_")) { if (utils::strmatch(arg[2], "^v_")) {
xstr = utils::strdup(arg[2]+2); xstr = utils::strdup(arg[2] + 2);
} else xvalue = utils::numeric(FLERR,arg[2],false,lmp); } else
if (utils::strmatch(arg[3],"^v_")) { xvalue = utils::numeric(FLERR, arg[2], false, lmp);
ystr = utils::strdup(arg[3]+2); if (utils::strmatch(arg[3], "^v_")) {
} else yvalue = utils::numeric(FLERR,arg[3],false,lmp); ystr = utils::strdup(arg[3] + 2);
} else error->all(FLERR,"Unknown fix indent cylinder argument: {}", arg[1]); } else
yvalue = utils::numeric(FLERR, arg[3], false, lmp);
} else
error->all(FLERR, "Unknown fix indent cylinder argument: {}", arg[1]);
if (utils::strmatch(arg[4],"^v_")) { if (utils::strmatch(arg[4], "^v_")) {
rstr = utils::strdup(arg[4]+2); rstr = utils::strdup(arg[4] + 2);
} else rvalue = utils::numeric(FLERR,arg[4],false,lmp); } else
rvalue = utils::numeric(FLERR, arg[4], false, lmp);
istyle = CYLINDER; istyle = CYLINDER;
return 5; return 5;
@ -550,51 +555,62 @@ int FixIndent::geometry(int narg, char **arg)
// cone // cone
if (strcmp(arg[0],"cone") == 0) { if (strcmp(arg[0], "cone") == 0) {
if (istyle != NONE) error->all(FLERR, "Fix indent requires a single geometry keyword"); if (istyle != NONE) error->all(FLERR, "Fix indent requires a single geometry keyword");
if (8 > narg) utils::missing_cmd_args(FLERR, "fix indent cone", error); if (8 > narg) utils::missing_cmd_args(FLERR, "fix indent cone", error);
if (strcmp(arg[1],"x") == 0) { if (strcmp(arg[1], "x") == 0) {
cdim = 0; cdim = 0;
if (utils::strmatch(arg[2],"^v_")) { if (utils::strmatch(arg[2], "^v_")) {
ystr = utils::strdup(arg[2]+2); ystr = utils::strdup(arg[2] + 2);
} else yvalue = utils::numeric(FLERR,arg[2],false,lmp); } else
if (utils::strmatch(arg[3],"^v_")) { yvalue = utils::numeric(FLERR, arg[2], false, lmp);
zstr = utils::strdup(arg[3]+2); if (utils::strmatch(arg[3], "^v_")) {
} else zvalue = utils::numeric(FLERR,arg[3],false,lmp); zstr = utils::strdup(arg[3] + 2);
} else
zvalue = utils::numeric(FLERR, arg[3], false, lmp);
} else if (strcmp(arg[1],"y") == 0) { } else if (strcmp(arg[1], "y") == 0) {
cdim = 1; cdim = 1;
if (utils::strmatch(arg[2],"^v_")) { if (utils::strmatch(arg[2], "^v_")) {
xstr = utils::strdup(arg[2]+2); xstr = utils::strdup(arg[2] + 2);
} else xvalue = utils::numeric(FLERR,arg[2],false,lmp); } else
if (utils::strmatch(arg[3],"^v_")) { xvalue = utils::numeric(FLERR, arg[2], false, lmp);
zstr = utils::strdup(arg[3]+2); if (utils::strmatch(arg[3], "^v_")) {
} else zvalue = utils::numeric(FLERR,arg[3],false,lmp); zstr = utils::strdup(arg[3] + 2);
} else
zvalue = utils::numeric(FLERR, arg[3], false, lmp);
} else if (strcmp(arg[1],"z") == 0) { } else if (strcmp(arg[1], "z") == 0) {
cdim = 2; cdim = 2;
if (utils::strmatch(arg[2],"^v_")) { if (utils::strmatch(arg[2], "^v_")) {
xstr = utils::strdup(arg[2]+2); xstr = utils::strdup(arg[2] + 2);
} else xvalue = utils::numeric(FLERR,arg[2],false,lmp); } else
if (utils::strmatch(arg[3],"^v_")) { xvalue = utils::numeric(FLERR, arg[2], false, lmp);
ystr = utils::strdup(arg[3]+2); if (utils::strmatch(arg[3], "^v_")) {
} else yvalue = utils::numeric(FLERR,arg[3],false,lmp); ystr = utils::strdup(arg[3] + 2);
} else
yvalue = utils::numeric(FLERR, arg[3], false, lmp);
} else error->all(FLERR,"Unknown fix indent cone argument: {}", arg[1]); } else
error->all(FLERR, "Unknown fix indent cone argument: {}", arg[1]);
if (utils::strmatch(arg[4],"^v_")) { if (utils::strmatch(arg[4], "^v_")) {
rlostr = utils::strdup(arg[4]+2); rlostr = utils::strdup(arg[4] + 2);
} else rlovalue = utils::numeric(FLERR,arg[4],false,lmp); } else
if (utils::strmatch(arg[5],"^v_")) { rlovalue = utils::numeric(FLERR, arg[4], false, lmp);
rhistr = utils::strdup(arg[5]+2); if (utils::strmatch(arg[5], "^v_")) {
} else rhivalue = utils::numeric(FLERR,arg[5],false,lmp); rhistr = utils::strdup(arg[5] + 2);
if (utils::strmatch(arg[6],"^v_")) { } else
lostr = utils::strdup(arg[6]+2); rhivalue = utils::numeric(FLERR, arg[5], false, lmp);
} else lovalue = utils::numeric(FLERR,arg[6],false,lmp); if (utils::strmatch(arg[6], "^v_")) {
if (utils::strmatch(arg[7],"^v_")) { lostr = utils::strdup(arg[6] + 2);
histr = utils::strdup(arg[7]+2); } else
} else hivalue = utils::numeric(FLERR,arg[7],false,lmp); lovalue = utils::numeric(FLERR, arg[6], false, lmp);
if (utils::strmatch(arg[7], "^v_")) {
histr = utils::strdup(arg[7] + 2);
} else
hivalue = utils::numeric(FLERR, arg[7], false, lmp);
istyle = CONE; istyle = CONE;
return 8; return 8;
@ -602,28 +618,36 @@ int FixIndent::geometry(int narg, char **arg)
// plane // plane
if (strcmp(arg[0],"plane") == 0) { if (strcmp(arg[0], "plane") == 0) {
if (istyle != NONE) error->all(FLERR, "Fix indent requires a single geometry keyword"); if (istyle != NONE) error->all(FLERR, "Fix indent requires a single geometry keyword");
if (4 > narg) utils::missing_cmd_args(FLERR, "fix indent plane", error); if (4 > narg) utils::missing_cmd_args(FLERR, "fix indent plane", error);
if (strcmp(arg[1],"x") == 0) cdim = 0; if (strcmp(arg[1], "x") == 0)
else if (strcmp(arg[1],"y") == 0) cdim = 1; cdim = 0;
else if (strcmp(arg[1],"z") == 0) cdim = 2; else if (strcmp(arg[1], "y") == 0)
else error->all(FLERR,"Unknown fix indent plane argument: {}", arg[1]); cdim = 1;
else if (strcmp(arg[1], "z") == 0)
cdim = 2;
else
error->all(FLERR, "Unknown fix indent plane argument: {}", arg[1]);
if (utils::strmatch(arg[2],"^v_")) { if (utils::strmatch(arg[2], "^v_")) {
pstr = utils::strdup(arg[2]+2); pstr = utils::strdup(arg[2] + 2);
} else pvalue = utils::numeric(FLERR,arg[2],false,lmp); } else
pvalue = utils::numeric(FLERR, arg[2], false, lmp);
if (strcmp(arg[3],"lo") == 0) planeside = -1; if (strcmp(arg[3], "lo") == 0)
else if (strcmp(arg[3],"hi") == 0) planeside = 1; planeside = -1;
else error->all(FLERR,"Unknown fix indent plane argument: {}", arg[3]); else if (strcmp(arg[3], "hi") == 0)
planeside = 1;
else
error->all(FLERR, "Unknown fix indent plane argument: {}", arg[3]);
istyle = PLANE; istyle = PLANE;
return 4; return 4;
} }
// invalid istyle arg // invalid istyle arg
error->all(FLERR,"Unknown fix indent argument: {}", arg[0]); error->all(FLERR, "Unknown fix indent argument: {}", arg[0]);
return 0; return 0;
} }
@ -640,21 +664,28 @@ void FixIndent::options(int narg, char **arg)
int iarg = 0; int iarg = 0;
while (iarg < narg) { while (iarg < narg) {
if (strcmp(arg[iarg],"units") == 0) { if (strcmp(arg[iarg], "units") == 0) {
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix indent units", error); if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix indent units", error);
if (strcmp(arg[iarg+1],"box") == 0) scaleflag = 0; if (strcmp(arg[iarg + 1], "box") == 0)
else if (strcmp(arg[iarg+1],"lattice") == 0) scaleflag = 1; scaleflag = 0;
else error->all(FLERR,"Unknown fix indent units argument: {}", arg[iarg+1]); else if (strcmp(arg[iarg + 1], "lattice") == 0)
scaleflag = 1;
else
error->all(FLERR, "Unknown fix indent units argument: {}", arg[iarg + 1]);
iarg += 2; iarg += 2;
} else if (strcmp(arg[iarg],"side") == 0) { } else if (strcmp(arg[iarg], "side") == 0) {
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix indent side", error); if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "fix indent side", error);
if (strcmp(arg[iarg+1],"in") == 0) side = INSIDE; if (strcmp(arg[iarg + 1], "in") == 0)
else if (strcmp(arg[iarg+1],"out") == 0) side = OUTSIDE; side = INSIDE;
else error->all(FLERR,"Unknown fix indent side argument: {}", arg[iarg+1]); else if (strcmp(arg[iarg + 1], "out") == 0)
side = OUTSIDE;
else
error->all(FLERR, "Unknown fix indent side argument: {}", arg[iarg + 1]);
iarg += 2; iarg += 2;
} else error->all(FLERR,"Unknown fix indent argument: {}", arg[iarg]); } else
error->all(FLERR, "Unknown fix indent argument: {}", arg[iarg]);
} }
} }
@ -662,12 +693,12 @@ void FixIndent::options(int narg, char **arg)
determines if a point is inside (true) or outside (false) of a cone determines if a point is inside (true) or outside (false) of a cone
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
bool FixIndent::PointInsideCone(int dir, double *center, double lo, bool FixIndent::PointInsideCone(int dir, double *center, double lo, double hi, double rlo,
double hi, double rlo, double rhi, double *x) double rhi, double *x)
{ {
if ((x[dir] > hi) || (x[dir] < lo)) return false; if ((x[dir] > hi) || (x[dir] < lo)) return false;
double del[3] {x[0] - center[0], x[1] - center[1], x[2] - center[2]}; double del[3] = {x[0] - center[0], x[1] - center[1], x[2] - center[2]};
del[dir] = 0.0; del[dir] = 0.0;
double dist = sqrt(del[0] * del[0] + del[1] * del[1] + del[2] * del[2]); double dist = sqrt(del[0] * del[0] + del[1] * del[1] + del[2] * del[2]);
@ -682,17 +713,14 @@ bool FixIndent::PointInsideCone(int dir, double *center, double lo,
distance between an exterior point and a cone distance between an exterior point and a cone
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void FixIndent::DistanceExteriorPoint(int dir, double *center, double lo, double hi, void FixIndent::DistanceExteriorPoint(int dir, double *center, double lo, double hi, double rlo,
double rlo, double rhi, double rhi, double &x, double &y, double &z)
double &x, double &y, double &z)
{ {
double xp[3], nearest[3], corner1[3], corner2[3]; double xp[3], nearest[3], corner1[3], corner2[3];
double point[3] = {x, y, z};
double del[3] = {x - center[0], y - center[1], z - center[2]};
double point[3] {x, y, z};
double del[3] {x - center[0], y - center[1], z - center[2]};
del[dir] = 0.0; del[dir] = 0.0;
double r = sqrt(del[0] * del[0] + del[1] * del[1] + del[2] * del[2]); double r = sqrt(del[0] * del[0] + del[1] * del[1] + del[2] * del[2]);
corner1[0] = center[0] + del[0] * rlo / r; corner1[0] = center[0] + del[0] * rlo / r;
@ -705,10 +733,10 @@ void FixIndent::DistanceExteriorPoint(int dir, double *center, double lo, double
corner2[2] = center[2] + del[2] * rhi / r; corner2[2] = center[2] + del[2] * rhi / r;
corner2[dir] = hi; corner2[dir] = hi;
double corner3[3] {center[0], center[1], center[2]}; double corner3[3] = {center[0], center[1], center[2]};
corner3[dir] = lo; corner3[dir] = lo;
double corner4[3] {center[0], center[1], center[2]}; double corner4[3] = {center[0], center[1], center[2]};
corner4[dir] = hi; corner4[dir] = hi;
// initialize distance to a big number // initialize distance to a big number
@ -741,18 +769,17 @@ void FixIndent::DistanceExteriorPoint(int dir, double *center, double lo, double
distance between an interior point and a cone distance between an interior point and a cone
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void FixIndent::DistanceInteriorPoint(int dir, double *center, void FixIndent::DistanceInteriorPoint(int dir, double *center, double lo, double hi, double rlo,
double lo, double hi, double rlo, double rhi, double &x, double rhi, double &x, double &y, double &z)
double &y, double &z)
{ {
double r, dist_disk, dist_surf; double r, dist_disk, dist_surf;
double surflo[3], surfhi[3], xs[3]; double surflo[3], surfhi[3], xs[3];
double initial_point[3] {x, y, z}; double initial_point[3] = {x, y, z};
double point[3] {0.0, 0.0, 0.0}; double point[3] = {0.0, 0.0, 0.0};
// initial check with the two disks // initial check with the two disks
if ( (initial_point[dir] - lo) < (hi - initial_point[dir]) ) { if ((initial_point[dir] - lo) < (hi - initial_point[dir])) {
dist_disk = (initial_point[dir] - lo) * (initial_point[dir] - lo); dist_disk = (initial_point[dir] - lo) * (initial_point[dir] - lo);
point[dir] = initial_point[dir] - lo; point[dir] = initial_point[dir] - lo;
} else { } else {
@ -762,7 +789,7 @@ void FixIndent::DistanceInteriorPoint(int dir, double *center,
// check with the points in the conical surface // check with the points in the conical surface
double del[3] {x - center[0], y - center[1], z - center[2]}; double del[3] = {x - center[0], y - center[1], z - center[2]};
del[dir] = 0.0; del[dir] = 0.0;
r = sqrt(del[0] * del[0] + del[1] * del[1] + del[2] * del[2]); r = sqrt(del[0] * del[0] + del[1] * del[1] + del[2] * del[2]);
@ -778,7 +805,7 @@ void FixIndent::DistanceInteriorPoint(int dir, double *center,
point_on_line_segment(surflo, surfhi, initial_point, xs); point_on_line_segment(surflo, surfhi, initial_point, xs);
double dx[3] {initial_point[0] - xs[0], initial_point[1] - xs[1], initial_point[2] - xs[2]}; double dx[3] = {initial_point[0] - xs[0], initial_point[1] - xs[1], initial_point[2] - xs[2]};
dist_surf = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2]; dist_surf = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2];
if (dist_surf < dist_disk) { if (dist_surf < dist_disk) {
x = dx[0]; x = dx[0];