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() void Compute::adjust_dof_fix()
{ {
Fix **fix = modify->fix;
int nfix = modify->nfix;
fix_dof = 0; fix_dof = 0;
for (int i = 0; i < nfix; i++) for (auto &ifix : modify->get_fix_list())
if (fix[i]->dof_flag) if (ifix->dof_flag)
fix_dof += fix[i]->dof(igroup); 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"); error->all(FLERR, "KSpace style does not support compute centroid/stress/atom");
if (fixflag) { if (fixflag) {
for (int ifix = 0; ifix < modify->nfix; ifix++) for (auto &ifix : modify->get_fix_list())
if (modify->fix[ifix]->virial_peratom_flag && if (ifix->virial_peratom_flag && (ifix->centroidstressflag == CENTROID_NOTAVAIL))
modify->fix[ifix]->centroidstressflag == CENTROID_NOTAVAIL) error->all(FLERR, "Fix {} does not support compute centroid/stress/atom", ifix->style);
error->all(FLERR, "Fix style does not support compute centroid/stress/atom");
} }
} }
@ -308,17 +307,15 @@ void ComputeCentroidStressAtom::compute_peratom()
// fix styles are CENTROID_SAME, CENTROID_AVAIL or CENTROID_NOTAVAIL // fix styles are CENTROID_SAME, CENTROID_AVAIL or CENTROID_NOTAVAIL
if (fixflag) { if (fixflag) {
Fix **fix = modify->fix; for (auto &ifix : modify->get_fix_list())
int nfix = modify->nfix; if (ifix->virial_peratom_flag && ifix->thermo_virial) {
for (int ifix = 0; ifix < nfix; ifix++) if (ifix->centroidstressflag == CENTROID_AVAIL) {
if (fix[ifix]->virial_peratom_flag && fix[ifix]->thermo_virial) { double **cvatom = ifix->cvatom;
if (modify->fix[ifix]->centroidstressflag == CENTROID_AVAIL) {
double **cvatom = modify->fix[ifix]->cvatom;
if (cvatom) if (cvatom)
for (i = 0; i < nlocal; i++) for (i = 0; i < nlocal; i++)
for (j = 0; j < 9; j++) stress[i][j] += cvatom[i][j]; for (j = 0; j < 9; j++) stress[i][j] += cvatom[i][j];
} else { } else {
double **vatom = modify->fix[ifix]->vatom; double **vatom = ifix->vatom;
if (vatom) if (vatom)
for (i = 0; i < nlocal; i++) { for (i = 0; i < nlocal; i++) {
for (j = 0; j < 6; j++) stress[i][j] += vatom[i][j]; 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) { if (which[i] == ArgInfo::COMPUTE) {
int icompute = modify->find_compute(ids[i]); int icompute = modify->find_compute(ids[i]);
if (icompute < 0) if (icompute < 0)
error->all(FLERR,"Compute ID for compute chunk/spread/atom " error->all(FLERR,"Compute ID for compute chunk/spread/atom does not exist");
"does not exist");
if (!utils::strmatch(modify->compute[icompute]->style,"/chunk$")) if (!utils::strmatch(modify->compute[icompute]->style,"/chunk$"))
error->all(FLERR,"Compute for compute chunk/spread/atom " 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 (argindex[i] == 0) {
if (!modify->compute[icompute]->vector_flag) if (!modify->compute[icompute]->vector_flag)
error->all(FLERR,"Compute chunk/spread/atom compute " error->all(FLERR,"Compute chunk/spread/atom compute does not calculate global vector");
"does not calculate global vector");
} else { } else {
if (!modify->compute[icompute]->array_flag) if (!modify->compute[icompute]->array_flag)
error->all(FLERR,"Compute chunk/spread/atom compute " error->all(FLERR,"Compute chunk/spread/atom compute does not calculate global array");
"does not calculate global array");
if (argindex[i] > modify->compute[icompute]->size_array_cols) if (argindex[i] > modify->compute[icompute]->size_array_cols)
error->all(FLERR,"Compute chunk/spread/atom compute array " error->all(FLERR,"Compute chunk/spread/atom compute array is accessed out-of-range");
"is accessed out-of-range");
} }
} else if (which[i] == ArgInfo::FIX) { } else if (which[i] == ArgInfo::FIX) {
int ifix = modify->find_fix(ids[i]); auto ifix = modify->get_fix_by_id(ids[i]);
if (ifix < 0) if (ifix)
error->all(FLERR,"Fix ID for compute chunk/spread/atom does not exist"); error->all(FLERR,"Fix ID {} for compute chunk/spread/atom does not exist", ids[i]);
if (argindex[i] == 0) { if (argindex[i] == 0) {
if (!modify->fix[ifix]->vector_flag) if (!ifix->vector_flag)
error->all(FLERR,"Compute chunk/spread/atom fix " error->all(FLERR,"Compute chunk/spread/atom fix does not calculate global vector");
"does not calculate global vector");
} else { } else {
if (!modify->fix[ifix]->array_flag) if (!ifix->array_flag)
error->all(FLERR,"Compute chunk/spread/atom fix " error->all(FLERR,"Compute chunk/spread/atom fix does not calculate global array");
"does not calculate global array"); if (argindex[i] > ifix->size_array_cols)
if (argindex[i] > modify->fix[ifix]->size_array_cols) error->all(FLERR,"Compute chunk/spread/atom fix array is accessed out-of-range");
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 // check if index exceeds fix output length/rows
} else if (which[m] == ArgInfo::FIX) { } else if (which[m] == ArgInfo::FIX) {
Fix *fix = modify->fix[n]; auto &fix = modify->get_fix_list()[n];
if (update->ntimestep % fix->global_freq) if (update->ntimestep % fix->global_freq)
error->all(FLERR,"Fix used in compute chunk/spread/atom not " error->all(FLERR,"Fix used in compute chunk/spread/atom not "
"computed at compatible time"); "computed at compatible time");

View File

@ -1870,7 +1870,7 @@ void Input::timestep()
if (respaflag) update->integrate->reset_dt(); if (respaflag) update->integrate->reset_dt();
if (force->pair) force->pair->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(); output->reset_dt();
} }

View File

@ -998,18 +998,11 @@ void Irregular::destroy_data()
void Irregular::init_exchange() void Irregular::init_exchange()
{ {
int nfix = modify->nfix;
Fix **fix = modify->fix;
int onefix;
int maxexchange_fix = 0; int maxexchange_fix = 0;
for (int i = 0; i < nfix; i++) { for (auto &ifix : modify->get_fix_list())
onefix = fix[i]->maxexchange; maxexchange_fix = MAX(maxexchange_fix, ifix->maxexchange);
maxexchange_fix = MAX(maxexchange_fix,onefix);
}
int maxexchange = atom->avec->maxexchange + maxexchange_fix; bufextra = atom->avec->maxexchange + maxexchange_fix + BUFEXTRA;
bufextra = maxexchange + 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; if (strcmp(name,dump[i]->id) == 0) return 1;
} }
} else if (strcmp(category,"fix") == 0) { } else if (strcmp(category,"fix") == 0) {
int nfix = lmp->modify->nfix; for (auto &ifix : lmp->modify->get_fix_list()) {
Fix **fix = lmp->modify->fix; if (strcmp(name,ifix->id) == 0) return 1;
for (int i=0; i < nfix; ++i) {
if (strcmp(name,fix[i]->id) == 0) return 1;
} }
} else if (strcmp(category,"group") == 0) { } else if (strcmp(category,"group") == 0) {
int ngroup = lmp->group->ngroup; int ngroup = lmp->group->ngroup;