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

View File

@ -105,8 +105,8 @@ 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 (i = 0; i < modify->nfix; i++) for (auto fix : modify->get_fix_list())
if (modify->fix[i]->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++)
if (modify->compute[i]->igroup == igroup) if (modify->compute[i]->igroup == igroup)

View File

@ -906,10 +906,8 @@ 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) {
int nfix = modify->nfix; for (auto fix : modify->get_fix_list()) {
Fix **fix = modify->fix; if (strcmp(fix->id,name) == 0)
for (int i=0; i < nfix; ++i) {
if (strcmp(fix[i]->id,name) == 0)
return true; return true;
} }
} else if (strcmp(category,"group") == 0) { } else if (strcmp(category,"group") == 0) {

View File

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

View File

@ -51,7 +51,7 @@ class WriteData : public Command {
void dihedrals(); void dihedrals();
void impropers(); void impropers();
void bonus(int); void bonus(int);
void fix(int, int); void fix(class Fix *, int);
}; };
} // namespace LAMMPS_NS } // 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 // invoke any fixes that write their own restart file
for (int ifix = 0; ifix < modify->nfix; ifix++) for (auto fix : modify->get_fix_list())
if (modify->fix[ifix]->restart_file) if (fix->restart_file)
modify->fix[ifix]->write_restart_file(file.c_str()); fix->write_restart_file(file.c_str());
} }
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------