use accessor function to get and process list of fixes

This commit is contained in:
Axel Kohlmeyer
2022-03-16 14:18:09 -04:00
parent 4be3da727a
commit 7e2fef096f
6 changed files with 31 additions and 53 deletions

View File

@ -140,13 +140,10 @@ void Compute::modify_params(int narg, char **arg)
void Compute::adjust_dof_fix()
{
Fix **fix = modify->fix;
int nfix = modify->nfix;
fix_dof = 0;
for (int i = 0; i < nfix; i++)
if (fix[i]->dof_flag)
fix_dof += fix[i]->dof(igroup);
for (auto &ifix : modify->get_fix_list())
if (ifix->dof_flag)
fix_dof += ifix->dof(igroup);
}
/* ----------------------------------------------------------------------

View File

@ -194,10 +194,9 @@ void ComputeCentroidStressAtom::init()
error->all(FLERR, "KSpace style does not support compute centroid/stress/atom");
if (fixflag) {
for (int ifix = 0; ifix < modify->nfix; ifix++)
if (modify->fix[ifix]->virial_peratom_flag &&
modify->fix[ifix]->centroidstressflag == CENTROID_NOTAVAIL)
error->all(FLERR, "Fix style does not support compute centroid/stress/atom");
for (auto &ifix : modify->get_fix_list())
if (ifix->virial_peratom_flag && (ifix->centroidstressflag == CENTROID_NOTAVAIL))
error->all(FLERR, "Fix {} does not support compute centroid/stress/atom", ifix->style);
}
}
@ -308,17 +307,15 @@ void ComputeCentroidStressAtom::compute_peratom()
// fix styles are CENTROID_SAME, CENTROID_AVAIL or CENTROID_NOTAVAIL
if (fixflag) {
Fix **fix = modify->fix;
int nfix = modify->nfix;
for (int ifix = 0; ifix < nfix; ifix++)
if (fix[ifix]->virial_peratom_flag && fix[ifix]->thermo_virial) {
if (modify->fix[ifix]->centroidstressflag == CENTROID_AVAIL) {
double **cvatom = modify->fix[ifix]->cvatom;
for (auto &ifix : modify->get_fix_list())
if (ifix->virial_peratom_flag && ifix->thermo_virial) {
if (ifix->centroidstressflag == CENTROID_AVAIL) {
double **cvatom = ifix->cvatom;
if (cvatom)
for (i = 0; i < nlocal; i++)
for (j = 0; j < 9; j++) stress[i][j] += cvatom[i][j];
} else {
double **vatom = modify->fix[ifix]->vatom;
double **vatom = ifix->vatom;
if (vatom)
for (i = 0; i < nlocal; i++) {
for (j = 0; j < 6; j++) stress[i][j] += vatom[i][j];

View File

@ -91,8 +91,7 @@ ComputeChunkSpreadAtom(LAMMPS *lmp, int narg, char **arg) :
if (which[i] == ArgInfo::COMPUTE) {
int icompute = modify->find_compute(ids[i]);
if (icompute < 0)
error->all(FLERR,"Compute ID for compute chunk/spread/atom "
"does not exist");
error->all(FLERR,"Compute ID for compute chunk/spread/atom does not exist");
if (!utils::strmatch(modify->compute[icompute]->style,"/chunk$"))
error->all(FLERR,"Compute for compute chunk/spread/atom "
@ -100,32 +99,26 @@ ComputeChunkSpreadAtom(LAMMPS *lmp, int narg, char **arg) :
if (argindex[i] == 0) {
if (!modify->compute[icompute]->vector_flag)
error->all(FLERR,"Compute chunk/spread/atom compute "
"does not calculate global vector");
error->all(FLERR,"Compute chunk/spread/atom compute does not calculate global vector");
} else {
if (!modify->compute[icompute]->array_flag)
error->all(FLERR,"Compute chunk/spread/atom compute "
"does not calculate global array");
error->all(FLERR,"Compute chunk/spread/atom compute does not calculate global array");
if (argindex[i] > modify->compute[icompute]->size_array_cols)
error->all(FLERR,"Compute chunk/spread/atom compute array "
"is accessed out-of-range");
error->all(FLERR,"Compute chunk/spread/atom compute array is accessed out-of-range");
}
} else if (which[i] == ArgInfo::FIX) {
int ifix = modify->find_fix(ids[i]);
if (ifix < 0)
error->all(FLERR,"Fix ID for compute chunk/spread/atom does not exist");
auto ifix = modify->get_fix_by_id(ids[i]);
if (ifix)
error->all(FLERR,"Fix ID {} for compute chunk/spread/atom does not exist", ids[i]);
if (argindex[i] == 0) {
if (!modify->fix[ifix]->vector_flag)
error->all(FLERR,"Compute chunk/spread/atom fix "
"does not calculate global vector");
if (!ifix->vector_flag)
error->all(FLERR,"Compute chunk/spread/atom fix does not calculate global vector");
} else {
if (!modify->fix[ifix]->array_flag)
error->all(FLERR,"Compute chunk/spread/atom fix "
"does not calculate global array");
if (argindex[i] > modify->fix[ifix]->size_array_cols)
error->all(FLERR,"Compute chunk/spread/atom fix array "
"is accessed out-of-range");
if (!ifix->array_flag)
error->all(FLERR,"Compute chunk/spread/atom fix does not calculate global array");
if (argindex[i] > ifix->size_array_cols)
error->all(FLERR,"Compute chunk/spread/atom fix array is accessed out-of-range");
}
}
}
@ -287,7 +280,7 @@ void ComputeChunkSpreadAtom::compute_peratom()
// check if index exceeds fix output length/rows
} else if (which[m] == ArgInfo::FIX) {
Fix *fix = modify->fix[n];
auto &fix = modify->get_fix_list()[n];
if (update->ntimestep % fix->global_freq)
error->all(FLERR,"Fix used in compute chunk/spread/atom not "
"computed at compatible time");

View File

@ -1870,7 +1870,7 @@ void Input::timestep()
if (respaflag) update->integrate->reset_dt();
if (force->pair) force->pair->reset_dt();
for (int i = 0; i < modify->nfix; i++) modify->fix[i]->reset_dt();
for (auto &ifix : modify->get_fix_list()) ifix->reset_dt();
output->reset_dt();
}

View File

@ -998,18 +998,11 @@ void Irregular::destroy_data()
void Irregular::init_exchange()
{
int nfix = modify->nfix;
Fix **fix = modify->fix;
int onefix;
int maxexchange_fix = 0;
for (int i = 0; i < nfix; i++) {
onefix = fix[i]->maxexchange;
maxexchange_fix = MAX(maxexchange_fix,onefix);
}
for (auto &ifix : modify->get_fix_list())
maxexchange_fix = MAX(maxexchange_fix, ifix->maxexchange);
int maxexchange = atom->avec->maxexchange + maxexchange_fix;
bufextra = maxexchange + BUFEXTRA;
bufextra = atom->avec->maxexchange + maxexchange_fix + BUFEXTRA;
}
/* ----------------------------------------------------------------------

View File

@ -4756,10 +4756,8 @@ int lammps_has_id(void *handle, const char *category, const char *name) {
if (strcmp(name,dump[i]->id) == 0) return 1;
}
} else if (strcmp(category,"fix") == 0) {
int nfix = lmp->modify->nfix;
Fix **fix = lmp->modify->fix;
for (int i=0; i < nfix; ++i) {
if (strcmp(name,fix[i]->id) == 0) return 1;
for (auto &ifix : lmp->modify->get_fix_list()) {
if (strcmp(name,ifix->id) == 0) return 1;
}
} else if (strcmp(category,"group") == 0) {
int ngroup = lmp->group->ngroup;