refactor group access, enable and apply clang-format
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -30,15 +29,15 @@
|
||||
using namespace LAMMPS_NS;
|
||||
using namespace FixConst;
|
||||
|
||||
enum{NONE,CONSTANT,EQUAL,ATOM};
|
||||
enum { NONE, CONSTANT, EQUAL, ATOM };
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixSetForce::FixSetForce(LAMMPS *lmp, int narg, char **arg) :
|
||||
Fix(lmp, narg, arg),
|
||||
xstr(nullptr), ystr(nullptr), zstr(nullptr), idregion(nullptr), sforce(nullptr)
|
||||
Fix(lmp, narg, arg), xstr(nullptr), ystr(nullptr), zstr(nullptr), idregion(nullptr),
|
||||
region(nullptr), sforce(nullptr)
|
||||
{
|
||||
if (narg < 6) error->all(FLERR,"Illegal fix setforce command");
|
||||
if (narg < 6) error->all(FLERR, "Illegal fix setforce command");
|
||||
|
||||
dynamic_group_allow = 1;
|
||||
vector_flag = 1;
|
||||
@ -47,55 +46,51 @@ FixSetForce::FixSetForce(LAMMPS *lmp, int narg, char **arg) :
|
||||
extvector = 1;
|
||||
respa_level_support = 1;
|
||||
ilevel_respa = nlevels_respa = 0;
|
||||
xstr = ystr = zstr = nullptr;
|
||||
|
||||
if (utils::strmatch(arg[3],"^v_")) {
|
||||
xstr = utils::strdup(arg[3]+2);
|
||||
} else if (strcmp(arg[3],"NULL") == 0) {
|
||||
if (utils::strmatch(arg[3], "^v_")) {
|
||||
xstr = utils::strdup(arg[3] + 2);
|
||||
} else if (strcmp(arg[3], "NULL") == 0) {
|
||||
xstyle = NONE;
|
||||
} else {
|
||||
xvalue = utils::numeric(FLERR,arg[3],false,lmp);
|
||||
xvalue = utils::numeric(FLERR, arg[3], false, lmp);
|
||||
xstyle = CONSTANT;
|
||||
}
|
||||
if (utils::strmatch(arg[4],"^v_")) {
|
||||
ystr = utils::strdup(arg[4]+2);
|
||||
} else if (strcmp(arg[4],"NULL") == 0) {
|
||||
if (utils::strmatch(arg[4], "^v_")) {
|
||||
ystr = utils::strdup(arg[4] + 2);
|
||||
} else if (strcmp(arg[4], "NULL") == 0) {
|
||||
ystyle = NONE;
|
||||
} else {
|
||||
yvalue = utils::numeric(FLERR,arg[4],false,lmp);
|
||||
yvalue = utils::numeric(FLERR, arg[4], false, lmp);
|
||||
ystyle = CONSTANT;
|
||||
}
|
||||
if (utils::strmatch(arg[5],"^v_")) {
|
||||
zstr = utils::strdup(arg[5]+2);
|
||||
} else if (strcmp(arg[5],"NULL") == 0) {
|
||||
if (utils::strmatch(arg[5], "^v_")) {
|
||||
zstr = utils::strdup(arg[5] + 2);
|
||||
} else if (strcmp(arg[5], "NULL") == 0) {
|
||||
zstyle = NONE;
|
||||
} else {
|
||||
zvalue = utils::numeric(FLERR,arg[5],false,lmp);
|
||||
zvalue = utils::numeric(FLERR, arg[5], false, lmp);
|
||||
zstyle = CONSTANT;
|
||||
}
|
||||
|
||||
// optional args
|
||||
|
||||
iregion = -1;
|
||||
idregion = nullptr;
|
||||
|
||||
int iarg = 6;
|
||||
while (iarg < narg) {
|
||||
if (strcmp(arg[iarg],"region") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix setforce command");
|
||||
iregion = domain->find_region(arg[iarg+1]);
|
||||
if (iregion == -1)
|
||||
error->all(FLERR,"Region ID for fix setforce does not exist");
|
||||
idregion = utils::strdup(arg[iarg+1]);
|
||||
if (strcmp(arg[iarg], "region") == 0) {
|
||||
if (iarg + 2 > narg) error->all(FLERR, "Illegal fix setforce command");
|
||||
region = domain->get_region_by_id(arg[iarg + 1]);
|
||||
if (!region) error->all(FLERR, "Region {} for fix setforce does not exist", arg[iarg + 1]);
|
||||
idregion = utils::strdup(arg[iarg + 1]);
|
||||
iarg += 2;
|
||||
} else error->all(FLERR,"Illegal fix setforce command");
|
||||
} else
|
||||
error->all(FLERR, "Illegal fix setforce command");
|
||||
}
|
||||
|
||||
force_flag = 0;
|
||||
foriginal[0] = foriginal[1] = foriginal[2] = 0.0;
|
||||
|
||||
maxatom = 1;
|
||||
memory->create(sforce,maxatom,3,"setforce:sforce");
|
||||
memory->create(sforce, maxatom, 3, "setforce:sforce");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -104,10 +99,10 @@ FixSetForce::~FixSetForce()
|
||||
{
|
||||
if (copymode) return;
|
||||
|
||||
delete [] xstr;
|
||||
delete [] ystr;
|
||||
delete [] zstr;
|
||||
delete [] idregion;
|
||||
delete[] xstr;
|
||||
delete[] ystr;
|
||||
delete[] zstr;
|
||||
delete[] idregion;
|
||||
memory->destroy(sforce);
|
||||
}
|
||||
|
||||
@ -130,47 +125,55 @@ void FixSetForce::init()
|
||||
|
||||
if (xstr) {
|
||||
xvar = input->variable->find(xstr);
|
||||
if (xvar < 0)
|
||||
error->all(FLERR,"Variable name for fix setforce does not exist");
|
||||
if (input->variable->equalstyle(xvar)) xstyle = EQUAL;
|
||||
else if (input->variable->atomstyle(xvar)) xstyle = ATOM;
|
||||
else error->all(FLERR,"Variable for fix setforce is invalid style");
|
||||
if (xvar < 0) error->all(FLERR, "Variable {} for fix setforce does not exist", xstr);
|
||||
if (input->variable->equalstyle(xvar))
|
||||
xstyle = EQUAL;
|
||||
else if (input->variable->atomstyle(xvar))
|
||||
xstyle = ATOM;
|
||||
else
|
||||
error->all(FLERR, "Variable {} for fix setforce is invalid style", xstr);
|
||||
}
|
||||
if (ystr) {
|
||||
yvar = input->variable->find(ystr);
|
||||
if (yvar < 0)
|
||||
error->all(FLERR,"Variable name for fix setforce does not exist");
|
||||
if (input->variable->equalstyle(yvar)) ystyle = EQUAL;
|
||||
else if (input->variable->atomstyle(yvar)) ystyle = ATOM;
|
||||
else error->all(FLERR,"Variable for fix setforce is invalid style");
|
||||
if (yvar < 0) error->all(FLERR, "Variable {} for fix setforce does not exist", ystr);
|
||||
if (input->variable->equalstyle(yvar))
|
||||
ystyle = EQUAL;
|
||||
else if (input->variable->atomstyle(yvar))
|
||||
ystyle = ATOM;
|
||||
else
|
||||
error->all(FLERR, "Variable {} for fix setforce is invalid style", ystr);
|
||||
}
|
||||
if (zstr) {
|
||||
zvar = input->variable->find(zstr);
|
||||
if (zvar < 0)
|
||||
error->all(FLERR,"Variable name for fix setforce does not exist");
|
||||
if (input->variable->equalstyle(zvar)) zstyle = EQUAL;
|
||||
else if (input->variable->atomstyle(zvar)) zstyle = ATOM;
|
||||
else error->all(FLERR,"Variable for fix setforce is invalid style");
|
||||
if (zvar < 0) error->all(FLERR, "Variable {} for fix setforce does not exist", zstr);
|
||||
if (input->variable->equalstyle(zvar))
|
||||
zstyle = EQUAL;
|
||||
else if (input->variable->atomstyle(zvar))
|
||||
zstyle = ATOM;
|
||||
else
|
||||
error->all(FLERR, "Variable {} for fix setforce is invalid style", zstr);
|
||||
}
|
||||
|
||||
// set index and check validity of region
|
||||
|
||||
if (iregion >= 0) {
|
||||
iregion = domain->find_region(idregion);
|
||||
if (iregion == -1)
|
||||
error->all(FLERR,"Region ID for fix setforce does not exist");
|
||||
if (idregion) {
|
||||
region = domain->get_region_by_id(idregion);
|
||||
if (!region) error->all(FLERR, "Region {} for fix setforce does not exist", idregion);
|
||||
}
|
||||
|
||||
if (xstyle == ATOM || ystyle == ATOM || zstyle == ATOM)
|
||||
varflag = ATOM;
|
||||
else if (xstyle == EQUAL || ystyle == EQUAL || zstyle == EQUAL)
|
||||
varflag = EQUAL;
|
||||
else varflag = CONSTANT;
|
||||
else
|
||||
varflag = CONSTANT;
|
||||
|
||||
if (utils::strmatch(update->integrate_style,"^respa")) {
|
||||
nlevels_respa = (dynamic_cast<Respa *>( update->integrate))->nlevels;
|
||||
if (respa_level >= 0) ilevel_respa = MIN(respa_level,nlevels_respa-1);
|
||||
else ilevel_respa = nlevels_respa-1;
|
||||
if (utils::strmatch(update->integrate_style, "^respa")) {
|
||||
nlevels_respa = (dynamic_cast<Respa *>(update->integrate))->nlevels;
|
||||
if (respa_level >= 0)
|
||||
ilevel_respa = MIN(respa_level, nlevels_respa - 1);
|
||||
else
|
||||
ilevel_respa = nlevels_respa - 1;
|
||||
}
|
||||
|
||||
// cannot use non-zero forces for a minimization since no energy is integrated
|
||||
@ -185,21 +188,20 @@ void FixSetForce::init()
|
||||
if (ystyle == CONSTANT && yvalue != 0.0) flag = 1;
|
||||
if (zstyle == CONSTANT && zvalue != 0.0) flag = 1;
|
||||
}
|
||||
if (flag)
|
||||
error->all(FLERR,"Cannot use non-zero forces in an energy minimization");
|
||||
if (flag) error->all(FLERR, "Cannot use non-zero forces in an energy minimization");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixSetForce::setup(int vflag)
|
||||
{
|
||||
if (utils::strmatch(update->integrate_style,"^verlet"))
|
||||
if (utils::strmatch(update->integrate_style, "^verlet"))
|
||||
post_force(vflag);
|
||||
else
|
||||
for (int ilevel = 0; ilevel < nlevels_respa; ilevel++) {
|
||||
(dynamic_cast<Respa *>( update->integrate))->copy_flevel_f(ilevel);
|
||||
post_force_respa(vflag,ilevel,0);
|
||||
(dynamic_cast<Respa *>( update->integrate))->copy_f_flevel(ilevel);
|
||||
(dynamic_cast<Respa *>(update->integrate))->copy_flevel_f(ilevel);
|
||||
post_force_respa(vflag, ilevel, 0);
|
||||
(dynamic_cast<Respa *>(update->integrate))->copy_f_flevel(ilevel);
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,18 +223,14 @@ void FixSetForce::post_force(int /*vflag*/)
|
||||
|
||||
// update region if necessary
|
||||
|
||||
Region *region = nullptr;
|
||||
if (iregion >= 0) {
|
||||
region = domain->regions[iregion];
|
||||
region->prematch();
|
||||
}
|
||||
if (region) region->prematch();
|
||||
|
||||
// reallocate sforce array if necessary
|
||||
|
||||
if (varflag == ATOM && atom->nmax > maxatom) {
|
||||
maxatom = atom->nmax;
|
||||
memory->destroy(sforce);
|
||||
memory->create(sforce,maxatom,3,"setforce:sforce");
|
||||
memory->create(sforce, maxatom, 3, "setforce:sforce");
|
||||
}
|
||||
|
||||
foriginal[0] = foriginal[1] = foriginal[2] = 0.0;
|
||||
@ -241,7 +239,7 @@ void FixSetForce::post_force(int /*vflag*/)
|
||||
if (varflag == CONSTANT) {
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) {
|
||||
if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue;
|
||||
if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue;
|
||||
foriginal[0] += f[i][0];
|
||||
foriginal[1] += f[i][1];
|
||||
foriginal[2] += f[i][2];
|
||||
@ -250,36 +248,45 @@ void FixSetForce::post_force(int /*vflag*/)
|
||||
if (zstyle) f[i][2] = zvalue;
|
||||
}
|
||||
|
||||
// variable force, wrap with clear/add
|
||||
// variable force, wrap with clear/add
|
||||
|
||||
} else {
|
||||
|
||||
modify->clearstep_compute();
|
||||
|
||||
if (xstyle == EQUAL) xvalue = input->variable->compute_equal(xvar);
|
||||
if (xstyle == EQUAL)
|
||||
xvalue = input->variable->compute_equal(xvar);
|
||||
else if (xstyle == ATOM)
|
||||
input->variable->compute_atom(xvar,igroup,&sforce[0][0],3,0);
|
||||
if (ystyle == EQUAL) yvalue = input->variable->compute_equal(yvar);
|
||||
input->variable->compute_atom(xvar, igroup, &sforce[0][0], 3, 0);
|
||||
if (ystyle == EQUAL)
|
||||
yvalue = input->variable->compute_equal(yvar);
|
||||
else if (ystyle == ATOM)
|
||||
input->variable->compute_atom(yvar,igroup,&sforce[0][1],3,0);
|
||||
if (zstyle == EQUAL) zvalue = input->variable->compute_equal(zvar);
|
||||
input->variable->compute_atom(yvar, igroup, &sforce[0][1], 3, 0);
|
||||
if (zstyle == EQUAL)
|
||||
zvalue = input->variable->compute_equal(zvar);
|
||||
else if (zstyle == ATOM)
|
||||
input->variable->compute_atom(zvar,igroup,&sforce[0][2],3,0);
|
||||
input->variable->compute_atom(zvar, igroup, &sforce[0][2], 3, 0);
|
||||
|
||||
modify->addstep_compute(update->ntimestep + 1);
|
||||
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) {
|
||||
if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue;
|
||||
if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue;
|
||||
foriginal[0] += f[i][0];
|
||||
foriginal[1] += f[i][1];
|
||||
foriginal[2] += f[i][2];
|
||||
if (xstyle == ATOM) f[i][0] = sforce[i][0];
|
||||
else if (xstyle) f[i][0] = xvalue;
|
||||
if (ystyle == ATOM) f[i][1] = sforce[i][1];
|
||||
else if (ystyle) f[i][1] = yvalue;
|
||||
if (zstyle == ATOM) f[i][2] = sforce[i][2];
|
||||
else if (zstyle) f[i][2] = zvalue;
|
||||
if (xstyle == ATOM)
|
||||
f[i][0] = sforce[i][0];
|
||||
else if (xstyle)
|
||||
f[i][0] = xvalue;
|
||||
if (ystyle == ATOM)
|
||||
f[i][1] = sforce[i][1];
|
||||
else if (ystyle)
|
||||
f[i][1] = yvalue;
|
||||
if (zstyle == ATOM)
|
||||
f[i][2] = sforce[i][2];
|
||||
else if (zstyle)
|
||||
f[i][2] = zvalue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -298,11 +305,7 @@ void FixSetForce::post_force_respa(int vflag, int ilevel, int /*iloop*/)
|
||||
foriginal[1] += foriginal_saved[1];
|
||||
foriginal[2] += foriginal_saved[2];
|
||||
} else {
|
||||
Region *region = nullptr;
|
||||
if (iregion >= 0) {
|
||||
region = domain->regions[iregion];
|
||||
region->prematch();
|
||||
}
|
||||
if (region) region->prematch();
|
||||
|
||||
double **x = atom->x;
|
||||
double **f = atom->f;
|
||||
@ -311,7 +314,7 @@ void FixSetForce::post_force_respa(int vflag, int ilevel, int /*iloop*/)
|
||||
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) {
|
||||
if (region && !region->match(x[i][0],x[i][1],x[i][2])) continue;
|
||||
if (region && !region->match(x[i][0], x[i][1], x[i][2])) continue;
|
||||
foriginal_saved[0] += f[i][0];
|
||||
foriginal_saved[1] += f[i][1];
|
||||
foriginal_saved[2] += f[i][2];
|
||||
@ -338,7 +341,7 @@ double FixSetForce::compute_vector(int n)
|
||||
// only sum across procs one time
|
||||
|
||||
if (force_flag == 0) {
|
||||
MPI_Allreduce(foriginal,foriginal_all,3,MPI_DOUBLE,MPI_SUM,world);
|
||||
MPI_Allreduce(foriginal, foriginal_all, 3, MPI_DOUBLE, MPI_SUM, world);
|
||||
force_flag = 1;
|
||||
}
|
||||
return foriginal_all[n];
|
||||
@ -351,6 +354,6 @@ double FixSetForce::compute_vector(int n)
|
||||
double FixSetForce::memory_usage()
|
||||
{
|
||||
double bytes = 0.0;
|
||||
if (varflag == ATOM) bytes = maxatom*3 * sizeof(double);
|
||||
if (varflag == ATOM) bytes = maxatom * 3 * sizeof(double);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user