auto loop optimizations
This commit is contained in:
@ -118,11 +118,10 @@ void FixSRP::init()
|
||||
// because this fix's pre_exchange() creates per-atom data structure
|
||||
// that data must be current for atom migration to carry it along
|
||||
|
||||
for (int i = 0; i < modify->nfix; i++) {
|
||||
if (modify->fix[i] == this) break;
|
||||
if (modify->fix[i]->pre_exchange_migrate)
|
||||
error->all(FLERR,"Fix SRP comes after a fix which "
|
||||
"migrates atoms in pre_exchange");
|
||||
for (auto &ifix : modify->get_fix_list()) {
|
||||
if (ifix == this) break;
|
||||
if (ifix->pre_exchange_migrate)
|
||||
error->all(FLERR,"Fix {} comes after a fix which migrates atoms in pre_exchange", style);
|
||||
}
|
||||
|
||||
// setup neigh exclusions for diff atom types
|
||||
|
||||
@ -369,7 +369,7 @@ void plugin_unload(const char *style, const char *name, LAMMPS *lmp)
|
||||
|
||||
// must delete all compute instances using this compute style
|
||||
|
||||
for (auto icompute : lmp->modify->get_compute_by_style(name))
|
||||
for (auto &icompute : lmp->modify->get_compute_by_style(name))
|
||||
lmp->modify->delete_compute(icompute->id);
|
||||
|
||||
} else if (pstyle == "fix") {
|
||||
@ -380,7 +380,7 @@ void plugin_unload(const char *style, const char *name, LAMMPS *lmp)
|
||||
|
||||
// must delete all fix instances using this fix style
|
||||
|
||||
for (auto ifix : lmp->modify->get_fix_by_style(name)) lmp->modify->delete_fix(ifix->id);
|
||||
for (auto &ifix : lmp->modify->get_fix_by_style(name)) lmp->modify->delete_fix(ifix->id);
|
||||
|
||||
} else if (pstyle == "region") {
|
||||
|
||||
@ -388,7 +388,7 @@ void plugin_unload(const char *style, const char *name, LAMMPS *lmp)
|
||||
auto found = region_map->find(name);
|
||||
if (found != region_map->end()) region_map->erase(name);
|
||||
|
||||
for (auto iregion : lmp->domain->get_region_by_style(name)) lmp->domain->delete_region(iregion);
|
||||
for (auto &iregion : lmp->domain->get_region_by_style(name)) lmp->domain->delete_region(iregion);
|
||||
|
||||
} else if (pstyle == "command") {
|
||||
|
||||
|
||||
@ -353,7 +353,7 @@ void FixPOEMS::init()
|
||||
|
||||
if (earlyflag) {
|
||||
bool pflag = false;
|
||||
for (auto ifix : modify->get_fix_list()) {
|
||||
for (auto &ifix : modify->get_fix_list()) {
|
||||
if (utils::strmatch(ifix->style, "^poems")) pflag = true;
|
||||
if (pflag && (ifix->setmask() & POST_FORCE) && !ifix->rigid_flag)
|
||||
if (comm->me == 0)
|
||||
@ -364,7 +364,7 @@ void FixPOEMS::init()
|
||||
|
||||
// error if npt,nph fix comes before rigid fix
|
||||
bool pflag = false;
|
||||
for (auto ifix : modify->get_fix_list()) {
|
||||
for (auto &ifix : modify->get_fix_list()) {
|
||||
if (!pflag && utils::strmatch(ifix->style, "np[th]"))
|
||||
error->all(FLERR, "POEMS fix must come before NPT/NPH fix");
|
||||
if (utils::strmatch(ifix->style, "^poems")) pflag = true;
|
||||
|
||||
@ -155,10 +155,10 @@ void Hyper::command(int narg, char **arg)
|
||||
|
||||
// cannot use hyper with time-dependent fixes or regions
|
||||
|
||||
for (auto ifix : modify->get_fix_list())
|
||||
for (auto &ifix : modify->get_fix_list())
|
||||
if (ifix->time_depend) error->all(FLERR,"Cannot use hyper with a time-dependent fix defined");
|
||||
|
||||
for (auto reg : domain->get_region_list())
|
||||
for (auto ® : domain->get_region_list())
|
||||
if (reg->dynamic_check())
|
||||
error->all(FLERR,"Cannot use hyper with a time-dependent region defined");
|
||||
|
||||
@ -180,9 +180,7 @@ void Hyper::command(int narg, char **arg)
|
||||
|
||||
fix_event->store_state_quench();
|
||||
quench(1);
|
||||
if (dumpflag)
|
||||
for (int idump = 0; idump < ndump; idump++)
|
||||
output->dump[dumplist[idump]]->write();
|
||||
if (dumpflag) for (auto &idump : dumplist) idump->write();
|
||||
fix_event->store_event();
|
||||
if (hyperenable) fix_hyper->build_bond_list(0);
|
||||
fix_event->restore_state_quench();
|
||||
@ -211,9 +209,7 @@ void Hyper::command(int narg, char **arg)
|
||||
nevent++;
|
||||
nevent_atoms += ecount;
|
||||
|
||||
if (dumpflag)
|
||||
for (int idump = 0; idump < ndump; idump++)
|
||||
output->dump[dumplist[idump]]->write();
|
||||
if (dumpflag) for (auto &idump : dumplist) idump->write();
|
||||
fix_event->store_event();
|
||||
if (hyperenable) fix_hyper->build_bond_list(ecount);
|
||||
|
||||
|
||||
@ -229,10 +229,10 @@ void PRD::command(int narg, char **arg)
|
||||
|
||||
// cannot use PRD with time-dependent fixes or regions
|
||||
|
||||
for (auto ifix : modify->get_fix_list())
|
||||
for (auto &ifix : modify->get_fix_list())
|
||||
if (ifix->time_depend) error->all(FLERR,"Cannot use PRD with a time-dependent fix defined");
|
||||
|
||||
for (auto reg : domain->get_region_list())
|
||||
for (auto ® : domain->get_region_list())
|
||||
if (reg->dynamic_check())
|
||||
error->all(FLERR,"Cannot use PRD with a time-dependent region defined");
|
||||
|
||||
|
||||
@ -684,13 +684,13 @@ void FixRigid::init()
|
||||
// if earlyflag, warn if any post-force fixes come after a rigid fix
|
||||
|
||||
int count = 0;
|
||||
for (auto ifix : modify->get_fix_list())
|
||||
for (auto &ifix : modify->get_fix_list())
|
||||
if (ifix->rigid_flag) count++;
|
||||
if (count > 1 && me == 0) error->warning(FLERR,"More than one fix rigid");
|
||||
|
||||
if (earlyflag) {
|
||||
bool rflag = false;
|
||||
for (auto ifix : modify->get_fix_list()) {
|
||||
for (auto &ifix : modify->get_fix_list()) {
|
||||
if (ifix->rigid_flag) rflag = true;
|
||||
if ((comm->me == 0) && rflag && (ifix->setmask() & POST_FORCE) && !ifix->rigid_flag)
|
||||
error->warning(FLERR,"Fix {} with ID {} alters forces after fix rigid",
|
||||
@ -713,7 +713,7 @@ void FixRigid::init()
|
||||
// error if a fix changing the box comes before rigid fix
|
||||
|
||||
bool boxflag = false;
|
||||
for (auto ifix : modify->get_fix_list()) {
|
||||
for (auto &ifix : modify->get_fix_list()) {
|
||||
if (boxflag && utils::strmatch(ifix->style,"^rigid"))
|
||||
error->all(FLERR,"Rigid fixes must come before any box changing fix");
|
||||
if (ifix->box_change) boxflag = true;
|
||||
|
||||
@ -529,13 +529,13 @@ void FixRigidSmall::init()
|
||||
// if earlyflag, warn if any post-force fixes come after a rigid fix
|
||||
|
||||
int count = 0;
|
||||
for (auto ifix : modify->get_fix_list())
|
||||
for (auto &ifix : modify->get_fix_list())
|
||||
if (ifix->rigid_flag) count++;
|
||||
if (count > 1 && me == 0) error->warning(FLERR,"More than one fix rigid");
|
||||
|
||||
if (earlyflag) {
|
||||
bool rflag = false;
|
||||
for (auto ifix : modify->get_fix_list()) {
|
||||
for (auto &ifix : modify->get_fix_list()) {
|
||||
if (ifix->rigid_flag) rflag = true;
|
||||
if ((comm->me == 0) && rflag && (ifix->setmask() & POST_FORCE) && !ifix->rigid_flag)
|
||||
error->warning(FLERR,"Fix {} with ID {} alters forces after fix rigid/small",
|
||||
@ -558,7 +558,7 @@ void FixRigidSmall::init()
|
||||
// error if a fix changing the box comes before rigid fix
|
||||
|
||||
bool boxflag = false;
|
||||
for (auto ifix : modify->get_fix_list()) {
|
||||
for (auto &ifix : modify->get_fix_list()) {
|
||||
if (boxflag && utils::strmatch(ifix->style,"^rigid"))
|
||||
error->all(FLERR,"Rigid fixes must come before any box changing fix");
|
||||
if (ifix->box_change) boxflag = true;
|
||||
|
||||
@ -347,16 +347,12 @@ void FixShake::init()
|
||||
if (update->whichflag == 2)
|
||||
error->all(FLERR,"Fix shake cannot be used with minimization");
|
||||
|
||||
// error if npt,nph fix comes before shake fix
|
||||
|
||||
for (i = 0; i < modify->nfix; i++) {
|
||||
if (strcmp(modify->fix[i]->style,"npt") == 0) break;
|
||||
if (strcmp(modify->fix[i]->style,"nph") == 0) break;
|
||||
}
|
||||
if (i < modify->nfix) {
|
||||
for (int j = i; j < modify->nfix; j++)
|
||||
if (strcmp(modify->fix[j]->style,"shake") == 0)
|
||||
error->all(FLERR,"Shake fix must come before NPT/NPH fix");
|
||||
// error if a fix changing the box comes before shake fix
|
||||
bool boxflag = false;
|
||||
for (auto &ifix : modify->get_fix_list()) {
|
||||
if (boxflag && utils::strmatch(ifix->style,pattern))
|
||||
error->all(FLERR,"Fix {} must come before any box changing fix", style);
|
||||
if (ifix->box_change) boxflag = true;
|
||||
}
|
||||
|
||||
// if rRESPA, find associated fix that must exist
|
||||
|
||||
@ -125,7 +125,7 @@ Domain::~Domain()
|
||||
{
|
||||
if (copymode) return;
|
||||
|
||||
for (auto reg : regions) delete reg;
|
||||
for (auto ® : regions) delete reg;
|
||||
regions.clear();
|
||||
delete lattice;
|
||||
delete region_map;
|
||||
@ -190,7 +190,7 @@ void Domain::init()
|
||||
|
||||
// region inits
|
||||
|
||||
for (auto reg : regions) reg->init();
|
||||
for (auto ® : regions) reg->init();
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
||||
@ -882,7 +882,7 @@ void FixDeform::end_of_step()
|
||||
if (mask[i] & groupbit)
|
||||
domain->x2lamda(x[i],x[i]);
|
||||
|
||||
for (auto ifix : rfix)
|
||||
for (auto &ifix : rfix)
|
||||
ifix->deform(0);
|
||||
}
|
||||
|
||||
@ -921,7 +921,7 @@ void FixDeform::end_of_step()
|
||||
if (mask[i] & groupbit)
|
||||
domain->lamda2x(x[i],x[i]);
|
||||
|
||||
for (auto ifix : rfix)
|
||||
for (auto &ifix : rfix)
|
||||
ifix->deform(1);
|
||||
}
|
||||
|
||||
|
||||
@ -1087,7 +1087,7 @@ bool utils::is_integer(const std::string &str)
|
||||
{
|
||||
if (str.empty()) return false;
|
||||
|
||||
for (auto c : str) {
|
||||
for (const auto &c : str) {
|
||||
if (isdigit(c) || c == '-' || c == '+') continue;
|
||||
return false;
|
||||
}
|
||||
@ -1102,7 +1102,7 @@ bool utils::is_double(const std::string &str)
|
||||
{
|
||||
if (str.empty()) return false;
|
||||
|
||||
for (auto c : str) {
|
||||
for (const auto &c : str) {
|
||||
if (isdigit(c)) continue;
|
||||
if (c == '-' || c == '+' || c == '.') continue;
|
||||
if (c == 'e' || c == 'E') continue;
|
||||
@ -1119,7 +1119,7 @@ bool utils::is_id(const std::string &str)
|
||||
{
|
||||
if (str.empty()) return false;
|
||||
|
||||
for (auto c : str) {
|
||||
for (const auto &c : str) {
|
||||
if (isalnum(c) || (c == '_')) continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user