use get_(fix|compute)_by_id() instead of find_(fix|compute)()

This commit is contained in:
Axel Kohlmeyer
2021-10-20 02:47:26 -04:00
parent 8cd4460c62
commit 2e362b1f3f
10 changed files with 268 additions and 345 deletions

View File

@ -807,9 +807,8 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix)
// since some fixes access domain settings in their constructor
// nullptr must be last entry in this list
const char *exceptions[] =
{"GPU", "OMP", "INTEL", "property/atom", "cmap", "cmap3", "rx",
"deprecated", "STORE/KIM", nullptr};
const char *exceptions[] = {"GPU", "OMP", "INTEL", "property/atom", "cmap", "cmap3", "rx",
"deprecated", "STORE/KIM", nullptr};
if (domain->box_exist == 0) {
int m;
@ -822,7 +821,7 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix)
// check group ID
int igroup = group->find(arg[1]);
if (igroup == -1) error->all(FLERR,"Could not find fix group ID");
if (igroup == -1) error->all(FLERR,"Could not find fix group ID {}", arg[1]);
// if fix ID exists:
// set newflag = 0 so create new fix in same location in fix list
@ -856,8 +855,7 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix)
if (estyle == fix[ifix]->style) match = 1;
}
}
if (!match)
error->all(FLERR,"Replacing a fix, but new style != old style");
if (!match) error->all(FLERR,"Replacing a fix, but new style != old style");
if (fix[ifix]->igroup != igroup && comm->me == 0)
error->warning(FLERR,"Replacing a fix, but new group != old group");
@ -907,9 +905,12 @@ Fix *Modify::add_fix(int narg, char **arg, int trysuffix)
if (fix[ifix] == nullptr)
error->all(FLERR,utils::check_packages_for_style("fix",arg[2],lmp));
// increment nfix (if new)
// increment nfix and update fix_list vector (if new)
if (newflag) nfix++;
if (newflag) {
nfix++;
fix_list = std::vector<Fix *>(fix, fix+nfix);
}
// post_constructor() can call virtual methods in parent or child
// which would otherwise not yet be visible in child class
@ -983,25 +984,24 @@ Fix *Modify::add_fix(const std::string &fixcmd, int trysuffix)
Fix *Modify::replace_fix(const char *replaceID, int narg, char **arg, int trysuffix)
{
int ifix = find_fix(replaceID);
if (ifix < 0) error->all(FLERR,"Modify replace_fix ID {} could not be found", replaceID);
auto oldfix = get_fix_by_id(replaceID);
if (!oldfix) error->all(FLERR,"Modify replace_fix ID {} could not be found", replaceID);
// change ID, igroup, style of fix being replaced to match new fix
// requires some error checking on arguments for new fix
if (narg < 3) error->all(FLERR,"Illegal replace_fix invocation");
int jfix = find_fix(arg[0]);
if (jfix >= 0) error->all(FLERR,"Replace_fix ID is already in use");
if (!get_fix_by_id(arg[0])) error->all(FLERR,"Replace_fix ID is already in use");
delete [] fix[ifix]->id;
fix[ifix]->id = utils::strdup(arg[0]);
delete[] oldfix->id;
oldfix->id = utils::strdup(arg[0]);
int jgroup = group->find(arg[1]);
if (jgroup == -1) error->all(FLERR,"Could not find replace_fix group ID");
fix[ifix]->igroup = jgroup;
if (jgroup == -1) error->all(FLERR,"Could not find replace_fix group ID {}", arg[1]);
oldfix->igroup = jgroup;
delete [] fix[ifix]->style;
fix[ifix]->style = utils::strdup(arg[2]);
delete[] oldfix->style;
oldfix->style = utils::strdup(arg[2]);
// invoke add_fix
// it will find and overwrite the replaceID fix
@ -1047,7 +1047,7 @@ void Modify::modify_fix(int narg, char **arg)
int ifix;
for (ifix = 0; ifix < nfix; ifix++)
if (strcmp(arg[0],fix[ifix]->id) == 0) break;
if (ifix == nfix) error->all(FLERR,"Could not find fix_modify ID");
if (ifix == nfix) error->all(FLERR,"Could not find fix_modify ID {}", arg[0]);
fix[ifix]->modify_params(narg-1,&arg[1]);
}
@ -1060,7 +1060,7 @@ void Modify::modify_fix(int narg, char **arg)
void Modify::delete_fix(const std::string &id)
{
int ifix = find_fix(id);
if (ifix < 0) error->all(FLERR,"Could not find fix ID to delete");
if (ifix < 0) error->all(FLERR,"Could not find fix ID {} to delete", id);
delete_fix(ifix);
}
@ -1076,6 +1076,7 @@ void Modify::delete_fix(int ifix)
for (int i = ifix+1; i < nfix; i++) fix[i-1] = fix[i];
for (int i = ifix+1; i < nfix; i++) fmask[i-1] = fmask[i];
nfix--;
fix_list = std::vector<Fix *>(fix, fix+nfix);
}
/* ----------------------------------------------------------------------
@ -1252,8 +1253,7 @@ Compute *Modify::add_compute(int narg, char **arg, int trysuffix)
if (ncompute == maxcompute) {
maxcompute += DELTA;
compute = (Compute **)
memory->srealloc(compute,maxcompute*sizeof(Compute *),"modify:compute");
compute = (Compute **) memory->srealloc(compute,maxcompute*sizeof(Compute *),"modify:compute");
}
// create the Compute
@ -1291,6 +1291,7 @@ Compute *Modify::add_compute(int narg, char **arg, int trysuffix)
if (compute[ncompute] == nullptr)
error->all(FLERR,utils::check_packages_for_style("compute",arg[2],lmp));
compute_list = std::vector<Compute *>(compute, compute+ncompute+1);
return compute[ncompute++];
}
@ -1334,7 +1335,7 @@ void Modify::modify_compute(int narg, char **arg)
for (icompute = 0; icompute < ncompute; icompute++)
if (strcmp(arg[0],compute[icompute]->id) == 0) break;
if (icompute == ncompute)
error->all(FLERR,"Could not find compute_modify ID");
error->all(FLERR,"Could not find compute_modify ID {}", arg[0]);
compute[icompute]->modify_params(narg-1,&arg[1]);
}
@ -1346,7 +1347,7 @@ void Modify::modify_compute(int narg, char **arg)
void Modify::delete_compute(const std::string &id)
{
int icompute = find_compute(id);
if (icompute < 0) error->all(FLERR,"Could not find compute ID to delete");
if (icompute < 0) error->all(FLERR,"Could not find compute ID {} to delete", id);
delete_compute(icompute);
}
@ -1359,6 +1360,7 @@ void Modify::delete_compute(int icompute)
delete compute[icompute];
for (int i = icompute+1; i < ncompute; i++) compute[i-1] = compute[i];
ncompute--;
compute_list = std::vector<Compute *>(compute, compute+ncompute);
}
/* ----------------------------------------------------------------------