use references when looping over fixes from list

This commit is contained in:
Axel Kohlmeyer
2021-10-25 21:41:57 -04:00
parent d0416757b7
commit 8bf016eaef
8 changed files with 17 additions and 17 deletions

View File

@ -481,12 +481,12 @@ void PairGranHookeHistory::init_style()
int itype; int itype;
for (i = 1; i <= atom->ntypes; i++) { for (i = 1; i <= atom->ntypes; i++) {
onerad_dynamic[i] = onerad_frozen[i] = 0.0; onerad_dynamic[i] = onerad_frozen[i] = 0.0;
for (auto ipour : pours) { for (auto &ipour : pours) {
itype = i; itype = i;
double maxrad = *((double *) ipour->extract("radius", itype)); double maxrad = *((double *) ipour->extract("radius", itype));
if (maxrad > 0.0) onerad_dynamic[i] = maxrad; if (maxrad > 0.0) onerad_dynamic[i] = maxrad;
} }
for (auto idep : deps) { for (auto &idep : deps) {
itype = i; itype = i;
double maxrad = *((double *) idep->extract("radius", itype)); double maxrad = *((double *) idep->extract("radius", itype));
if (maxrad > 0.0) onerad_dynamic[i] = maxrad; if (maxrad > 0.0) onerad_dynamic[i] = maxrad;

View File

@ -1160,12 +1160,12 @@ void PairGranular::init_style()
int itype; int itype;
for (i = 1; i <= atom->ntypes; i++) { for (i = 1; i <= atom->ntypes; i++) {
onerad_dynamic[i] = onerad_frozen[i] = 0.0; onerad_dynamic[i] = onerad_frozen[i] = 0.0;
for (auto ipour : pours) { for (auto &ipour : pours) {
itype = i; itype = i;
double maxrad = *((double *) ipour->extract("radius", itype)); double maxrad = *((double *) ipour->extract("radius", itype));
if (maxrad > 0.0) onerad_dynamic[i] = maxrad; if (maxrad > 0.0) onerad_dynamic[i] = maxrad;
} }
for (auto idep : deps) { for (auto &idep : deps) {
itype = i; itype = i;
double maxrad = *((double *) idep->extract("radius", itype)); double maxrad = *((double *) idep->extract("radius", itype));
if (maxrad > 0.0) onerad_dynamic[i] = maxrad; if (maxrad > 0.0) onerad_dynamic[i] = maxrad;

View File

@ -202,7 +202,7 @@ void Comm::init()
if (ghost_velocity) size_border += atom->avec->size_velocity; if (ghost_velocity) size_border += atom->avec->size_velocity;
const auto &fix_list = modify->get_fix_list(); const auto &fix_list = modify->get_fix_list();
for (auto fix : fix_list) for (const auto &fix : fix_list)
size_border += fix->comm_border; size_border += fix->comm_border;
// per-atom limits for communication // per-atom limits for communication
@ -218,7 +218,7 @@ void Comm::init()
if (force->pair) maxforward = MAX(maxforward,force->pair->comm_forward); if (force->pair) maxforward = MAX(maxforward,force->pair->comm_forward);
if (force->pair) maxreverse = MAX(maxreverse,force->pair->comm_reverse); if (force->pair) maxreverse = MAX(maxreverse,force->pair->comm_reverse);
for (auto fix : fix_list) { for (const auto &fix : fix_list) {
maxforward = MAX(maxforward,fix->comm_forward); maxforward = MAX(maxforward,fix->comm_forward);
maxreverse = MAX(maxreverse,fix->comm_reverse); maxreverse = MAX(maxreverse,fix->comm_reverse);
} }
@ -243,7 +243,7 @@ void Comm::init()
maxexchange_atom = atom->avec->maxexchange; maxexchange_atom = atom->avec->maxexchange;
maxexchange_fix_dynamic = 0; maxexchange_fix_dynamic = 0;
for (auto fix : fix_list) for (const auto &fix : fix_list)
if (fix->maxexchange_dynamic) maxexchange_fix_dynamic = 1; if (fix->maxexchange_dynamic) maxexchange_fix_dynamic = 1;
if ((mode == Comm::MULTI) && (neighbor->style != Neighbor::MULTI)) if ((mode == Comm::MULTI) && (neighbor->style != Neighbor::MULTI))
@ -266,7 +266,7 @@ void Comm::init()
void Comm::init_exchange() void Comm::init_exchange()
{ {
maxexchange_fix = 0; maxexchange_fix = 0;
for (auto fix : modify->get_fix_list()) for (const auto &fix : modify->get_fix_list())
maxexchange_fix += fix->maxexchange; maxexchange_fix += fix->maxexchange;
maxexchange = maxexchange_atom + maxexchange_fix; maxexchange = maxexchange_atom + maxexchange_fix;

View File

@ -105,7 +105,7 @@ void Group::assign(int narg, char **arg)
int igroup = find(arg[0]); int igroup = find(arg[0]);
if (igroup == -1) error->all(FLERR,"Could not find group delete group ID"); if (igroup == -1) error->all(FLERR,"Could not find group delete group ID");
if (igroup == 0) error->all(FLERR,"Cannot delete group all"); if (igroup == 0) error->all(FLERR,"Cannot delete group all");
for (auto fix : modify->get_fix_list()) for (const auto &fix : modify->get_fix_list())
if (fix->igroup == igroup) if (fix->igroup == igroup)
error->all(FLERR,"Cannot delete group currently used by a fix"); error->all(FLERR,"Cannot delete group currently used by a fix");
for (i = 0; i < modify->ncompute; i++) for (i = 0; i < modify->ncompute; i++)

View File

@ -569,7 +569,7 @@ void Info::command(int narg, char **arg)
int i = 0; int i = 0;
char **names = group->names; char **names = group->names;
fputs("\nCompute information:\n",out); fputs("\nCompute information:\n",out);
for (auto compute : modify->get_compute_list()) for (const auto &compute : modify->get_compute_list())
fmt::print(out,"Compute[{:3d}]: {:16} style = {:16} group = {}\n", i++, fmt::print(out,"Compute[{:3d}]: {:16} style = {:16} group = {}\n", i++,
std::string(compute->id)+',',std::string(compute->style)+',', std::string(compute->id)+',',std::string(compute->style)+',',
names[compute->igroup]); names[compute->igroup]);
@ -598,7 +598,7 @@ void Info::command(int narg, char **arg)
int i = 0; int i = 0;
char **names = group->names; char **names = group->names;
fputs("\nFix information:\n",out); fputs("\nFix information:\n",out);
for (auto fix : modify->get_fix_list()) for (const auto &fix : modify->get_fix_list())
fmt::print(out, "Fix[{:3d}]: {:16} style = {:16} group = {}\n",i++, fmt::print(out, "Fix[{:3d}]: {:16} style = {:16} group = {}\n",i++,
std::string(fix->id)+',',std::string(fix->style)+',',names[fix->igroup]); std::string(fix->id)+',',std::string(fix->style)+',',names[fix->igroup]);
} }
@ -906,7 +906,7 @@ bool Info::is_defined(const char *category, const char *name)
return true; return true;
} }
} else if (strcmp(category,"fix") == 0) { } else if (strcmp(category,"fix") == 0) {
for (auto fix : modify->get_fix_list()) { for (const auto &fix : modify->get_fix_list()) {
if (strcmp(fix->id,name) == 0) if (strcmp(fix->id,name) == 0)
return true; return true;
} }
@ -1011,7 +1011,7 @@ static std::vector<std::string> get_style_names(std::map<std::string, ValueType>
std::vector<std::string> names; std::vector<std::string> names;
names.reserve(styles->size()); names.reserve(styles->size());
for (auto const& kv : *styles) { for (auto const &kv : *styles) {
// skip "secret" styles // skip "secret" styles
if (isupper(kv.first[0])) continue; if (isupper(kv.first[0])) continue;
names.push_back(kv.first); names.push_back(kv.first);

View File

@ -53,7 +53,7 @@ void Verlet::init()
// warn if no fixes doing time integration // warn if no fixes doing time integration
bool do_time_integrate = false; bool do_time_integrate = false;
for (auto fix : modify->get_fix_list()) for (const auto &fix : modify->get_fix_list())
if (fix->time_integrate) do_time_integrate; if (fix->time_integrate) do_time_integrate;
if (!do_time_integrate && (comm->me == 0)) if (!do_time_integrate && (comm->me == 0))

View File

@ -213,7 +213,7 @@ void WriteData::write(const std::string &file)
// extra sections managed by fixes // extra sections managed by fixes
if (fixflag) if (fixflag)
for (auto ifix : modify->get_fix_list()) for (auto &ifix : modify->get_fix_list())
if (ifix->wd_section) if (ifix->wd_section)
for (int m = 0; m < ifix->wd_section; m++) fix(ifix,m); for (int m = 0; m < ifix->wd_section; m++) fix(ifix,m);
@ -267,7 +267,7 @@ void WriteData::header()
// fix info // fix info
if (fixflag) if (fixflag)
for (auto ifix : modify->get_fix_list()) for (auto &ifix : modify->get_fix_list())
if (ifix->wd_header) if (ifix->wd_header)
for (int m = 0; m < ifix->wd_header; m++) for (int m = 0; m < ifix->wd_header; m++)
ifix->write_data_header(fp,m); ifix->write_data_header(fp,m);

View File

@ -413,7 +413,7 @@ void WriteRestart::write(const std::string &file)
// invoke any fixes that write their own restart file // invoke any fixes that write their own restart file
for (auto fix : modify->get_fix_list()) for (auto &fix : modify->get_fix_list())
if (fix->restart_file) if (fix->restart_file)
fix->write_restart_file(file.c_str()); fix->write_restart_file(file.c_str());
} }