simplify using new APIs

This commit is contained in:
Axel Kohlmeyer
2021-10-24 18:00:15 -04:00
parent a782f8f8e0
commit d0416757b7
6 changed files with 32 additions and 42 deletions

View File

@ -201,8 +201,9 @@ void Comm::init()
if (ghost_velocity) size_forward += atom->avec->size_velocity;
if (ghost_velocity) size_border += atom->avec->size_velocity;
for (int i = 0; i < modify->nfix; i++)
size_border += modify->fix[i]->comm_border;
const auto &fix_list = modify->get_fix_list();
for (auto fix : fix_list)
size_border += fix->comm_border;
// per-atom limits for communication
// maxexchange = max # of datums in exchange comm, set in exchange()
@ -217,9 +218,9 @@ void Comm::init()
if (force->pair) maxforward = MAX(maxforward,force->pair->comm_forward);
if (force->pair) maxreverse = MAX(maxreverse,force->pair->comm_reverse);
for (int i = 0; i < modify->nfix; i++) {
maxforward = MAX(maxforward,modify->fix[i]->comm_forward);
maxreverse = MAX(maxreverse,modify->fix[i]->comm_reverse);
for (auto fix : fix_list) {
maxforward = MAX(maxforward,fix->comm_forward);
maxreverse = MAX(maxreverse,fix->comm_reverse);
}
for (int i = 0; i < modify->ncompute; i++) {
@ -241,12 +242,9 @@ void Comm::init()
maxexchange_atom = atom->avec->maxexchange;
int nfix = modify->nfix;
Fix **fix = modify->fix;
maxexchange_fix_dynamic = 0;
for (int i = 0; i < nfix; i++)
if (fix[i]->maxexchange_dynamic) maxexchange_fix_dynamic = 1;
for (auto fix : fix_list)
if (fix->maxexchange_dynamic) maxexchange_fix_dynamic = 1;
if ((mode == Comm::MULTI) && (neighbor->style != Neighbor::MULTI))
error->all(FLERR,"Cannot use comm mode multi without multi-style neighbor lists");
@ -267,12 +265,9 @@ void Comm::init()
void Comm::init_exchange()
{
int nfix = modify->nfix;
Fix **fix = modify->fix;
maxexchange_fix = 0;
for (int i = 0; i < nfix; i++)
maxexchange_fix += fix[i]->maxexchange;
for (auto fix : modify->get_fix_list())
maxexchange_fix += fix->maxexchange;
maxexchange = maxexchange_atom + maxexchange_fix;
bufextra = maxexchange + BUFEXTRA;

View File

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

View File

@ -906,10 +906,8 @@ bool Info::is_defined(const char *category, const char *name)
return true;
}
} else if (strcmp(category,"fix") == 0) {
int nfix = modify->nfix;
Fix **fix = modify->fix;
for (int i=0; i < nfix; ++i) {
if (strcmp(fix[i]->id,name) == 0)
for (auto fix : modify->get_fix_list()) {
if (strcmp(fix->id,name) == 0)
return true;
}
} else if (strcmp(category,"group") == 0) {

View File

@ -213,9 +213,9 @@ void WriteData::write(const std::string &file)
// extra sections managed by fixes
if (fixflag)
for (int i = 0; i < modify->nfix; i++)
if (modify->fix[i]->wd_section)
for (int m = 0; m < modify->fix[i]->wd_section; m++) fix(i,m);
for (auto ifix : modify->get_fix_list())
if (ifix->wd_section)
for (int m = 0; m < ifix->wd_section; m++) fix(ifix,m);
// close data file
@ -267,22 +267,19 @@ void WriteData::header()
// fix info
if (fixflag)
for (int i = 0; i < modify->nfix; i++)
if (modify->fix[i]->wd_header)
for (int m = 0; m < modify->fix[i]->wd_header; m++)
modify->fix[i]->write_data_header(fp,m);
for (auto ifix : modify->get_fix_list())
if (ifix->wd_header)
for (int m = 0; m < ifix->wd_header; m++)
ifix->write_data_header(fp,m);
// box info
auto box = fmt::format("\n{} {} xlo xhi"
"\n{} {} ylo yhi"
"\n{} {} zlo zhi\n",
auto box = fmt::format("\n{} {} xlo xhi\n{} {} ylo yhi\n{} {} zlo zhi\n",
domain->boxlo[0],domain->boxhi[0],
domain->boxlo[1],domain->boxhi[1],
domain->boxlo[2],domain->boxhi[2]);
if (domain->triclinic)
box += fmt::format("{} {} {} xy xz yz\n",
domain->xy,domain->xz,domain->yz);
box += fmt::format("{} {} {} xy xz yz\n",domain->xy,domain->xz,domain->yz);
fputs(box.c_str(),fp);
}
@ -722,13 +719,13 @@ void WriteData::bonus(int flag)
write out Mth section of data file owned by Fix ifix
------------------------------------------------------------------------- */
void WriteData::fix(int ifix, int mth)
void WriteData::fix(Fix *ifix, int mth)
{
// communication buffer for Fix info
// maxrow X ncol = largest buffer needed by any proc
int sendrow,ncol;
modify->fix[ifix]->write_data_section_size(mth,sendrow,ncol);
ifix->write_data_section_size(mth,sendrow,ncol);
int maxrow;
MPI_Allreduce(&sendrow,&maxrow,1,MPI_INT,MPI_MAX,world);
@ -738,7 +735,7 @@ void WriteData::fix(int ifix, int mth)
// pack my fix data into buf
modify->fix[ifix]->write_data_section_pack(mth,buf);
ifix->write_data_section_pack(mth,buf);
// write one chunk of info per proc to file
// proc 0 pings each proc, receives its chunk, writes to file
@ -751,7 +748,7 @@ void WriteData::fix(int ifix, int mth)
MPI_Status status;
MPI_Request request;
modify->fix[ifix]->write_data_section_keyword(mth,fp);
ifix->write_data_section_keyword(mth,fp);
for (int iproc = 0; iproc < nprocs; iproc++) {
if (iproc) {
MPI_Irecv(&buf[0][0],maxrow*ncol,MPI_DOUBLE,iproc,0,world,&request);
@ -761,7 +758,7 @@ void WriteData::fix(int ifix, int mth)
recvrow /= ncol;
} else recvrow = sendrow;
modify->fix[ifix]->write_data_section(mth,fp,recvrow,buf,index);
ifix->write_data_section(mth,fp,recvrow,buf,index);
index += recvrow;
}

View File

@ -51,7 +51,7 @@ class WriteData : public Command {
void dihedrals();
void impropers();
void bonus(int);
void fix(int, int);
void fix(class Fix *, int);
};
} // namespace LAMMPS_NS

View File

@ -413,9 +413,9 @@ void WriteRestart::write(const std::string &file)
// invoke any fixes that write their own restart file
for (int ifix = 0; ifix < modify->nfix; ifix++)
if (modify->fix[ifix]->restart_file)
modify->fix[ifix]->write_restart_file(file.c_str());
for (auto fix : modify->get_fix_list())
if (fix->restart_file)
fix->write_restart_file(file.c_str());
}
/* ----------------------------------------------------------------------