From 6d070c70438410798cb8a2d50f3f37b493aefd26 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 16 Mar 2022 15:24:42 -0400 Subject: [PATCH] more use of modernized APIs --- src/compute_displace_atom.cpp | 5 ++-- src/compute_global_atom.cpp | 55 ++++++++++++++--------------------- src/compute_msd.cpp | 9 +++--- src/compute_msd_chunk.cpp | 9 +++--- src/compute_pressure.cpp | 10 +++---- src/compute_reduce.cpp | 44 ++++++++++++---------------- src/compute_reduce_chunk.cpp | 33 +++++++++------------ src/compute_reduce_region.cpp | 3 +- src/compute_slice.cpp | 53 ++++++++++++++++----------------- src/compute_stress_atom.cpp | 30 +++++++++---------- src/compute_temp_deform.cpp | 14 ++++----- src/compute_vacf.cpp | 8 ++--- 12 files changed, 117 insertions(+), 156 deletions(-) diff --git a/src/compute_displace_atom.cpp b/src/compute_displace_atom.cpp index 821525c53a..c72570b9c6 100644 --- a/src/compute_displace_atom.cpp +++ b/src/compute_displace_atom.cpp @@ -120,9 +120,8 @@ void ComputeDisplaceAtom::init() { // set fix which stores original atom coords - int ifix = modify->find_fix(id_fix); - if (ifix < 0) error->all(FLERR,"Could not find compute displace/atom fix ID"); - fix = (FixStore *) modify->fix[ifix]; + fix = (FixStore *) modify->get_fix_by_id(id_fix); + if (!fix) error->all(FLERR,"Could not find compute displace/atom fix with ID {}", id_fix); if (refreshflag) { ivar = input->variable->find(rvar); diff --git a/src/compute_global_atom.cpp b/src/compute_global_atom.cpp index d64ae5a641..b72f5a28f6 100644 --- a/src/compute_global_atom.cpp +++ b/src/compute_global_atom.cpp @@ -117,22 +117,17 @@ ComputeGlobalAtom::ComputeGlobalAtom(LAMMPS *lmp, int narg, char **arg) : "Compute global/atom compute array is accessed out-of-range"); } else if (whichref == ArgInfo::FIX) { - int ifix = modify->find_fix(idref); - if (ifix < 0) - error->all(FLERR,"Fix ID for compute global/atom does not exist"); - if (!modify->fix[ifix]->peratom_flag) - error->all(FLERR,"Compute global/atom fix does not " - "calculate a per-atom vector or array"); - if (indexref == 0 && - modify->fix[ifix]->size_peratom_cols != 0) - error->all(FLERR,"Compute global/atom fix does not " - "calculate a per-atom vector"); - if (indexref && modify->fix[ifix]->size_peratom_cols == 0) - error->all(FLERR,"Compute global/atom fix does not " - "calculate a per-atom array"); - if (indexref && indexref > modify->fix[ifix]->size_peratom_cols) - error->all(FLERR, - "Compute global/atom fix array is accessed out-of-range"); + auto ifix = modify->get_fix_by_id(idref); + if (!ifix) + error->all(FLERR,"Fix ID {} for compute global/atom does not exist", idref); + if (!ifix->peratom_flag) + error->all(FLERR,"Compute global/atom fix {} does not calculate a per-atom vector or array", idref); + if (indexref == 0 && (ifix->size_peratom_cols != 0)) + error->all(FLERR,"Compute global/atom fix {} does not calculate a per-atom vector", idref); + if (indexref && (ifix->size_peratom_cols == 0)) + error->all(FLERR,"Compute global/atom fix {} does not calculate a per-atom array", idref); + if (indexref && indexref > ifix->size_peratom_cols) + error->all(FLERR, "Compute global/atom fix {} array is accessed out-of-range", idref); } else if (whichref == ArgInfo::VARIABLE) { int ivariable = input->variable->find(idref); @@ -162,30 +157,25 @@ ComputeGlobalAtom::ComputeGlobalAtom(LAMMPS *lmp, int narg, char **arg) : } } else if (which[i] == ArgInfo::FIX) { - int ifix = modify->find_fix(ids[i]); - if (ifix < 0) + auto ifix = modify->get_fix_by_id(ids[i]); + if (!ifix) error->all(FLERR,"Fix ID for compute global/atom does not exist"); if (argindex[i] == 0) { - if (!modify->fix[ifix]->vector_flag) - error->all(FLERR,"Compute global/atom fix does not " - "calculate a global vector"); + if (!ifix->vector_flag) + error->all(FLERR,"Compute global/atom fix {} does not calculate a global vector", ids[i]); } else { - if (!modify->fix[ifix]->array_flag) - error->all(FLERR,"Compute global/atom fix does not " - "calculate a global array"); - if (argindex[i] > modify->fix[ifix]->size_array_cols) - error->all(FLERR,"Compute global/atom fix array is " - "accessed out-of-range"); + if (!ifix->array_flag) + error->all(FLERR,"Compute global/atom fix {} does not calculate a global array", ids[i]); + if (argindex[i] > ifix->size_array_cols) + error->all(FLERR,"Compute global/atom fix {} array is accessed out-of-range", ids[i]); } } else if (which[i] == ArgInfo::VARIABLE) { int ivariable = input->variable->find(ids[i]); if (ivariable < 0) - error->all(FLERR,"Variable name for compute global/atom " - "does not exist"); + error->all(FLERR,"Variable name for compute global/atom does not exist"); if (input->variable->vectorstyle(ivariable) == 0) - error->all(FLERR,"Compute global/atom variable is not " - "vector-style variable"); + error->all(FLERR,"Compute global/atom variable is not vector-style variable"); } } @@ -368,8 +358,7 @@ void ComputeGlobalAtom::compute_peratom() } else if (which[m] == ArgInfo::FIX) { if (update->ntimestep % modify->fix[value2index[m]]->peratom_freq) - error->all(FLERR,"Fix used in compute global/atom not " - "computed at compatible time"); + error->all(FLERR,"Fix used in compute global/atom not computed at compatible time"); Fix *fix = modify->fix[value2index[m]]; vmax = fix->size_vector; diff --git a/src/compute_msd.cpp b/src/compute_msd.cpp index 7eee23a466..229b965761 100644 --- a/src/compute_msd.cpp +++ b/src/compute_msd.cpp @@ -113,8 +113,8 @@ ComputeMSD::~ComputeMSD() if (modify->nfix) modify->delete_fix(id_fix); - delete [] id_fix; - delete [] vector; + delete[] id_fix; + delete[] vector; } /* ---------------------------------------------------------------------- */ @@ -123,9 +123,8 @@ void ComputeMSD::init() { // set fix which stores reference atom coords - int ifix = modify->find_fix(id_fix); - if (ifix < 0) error->all(FLERR,"Could not find compute msd fix ID"); - fix = (FixStore *) modify->fix[ifix]; + fix = (FixStore *) modify->get_fix_by_id(id_fix); + if (!fix) error->all(FLERR,"Could not find compute msd fix with ID {}", id_fix); // nmsd = # of atoms in group diff --git a/src/compute_msd_chunk.cpp b/src/compute_msd_chunk.cpp index 0d5b146338..cea6da100d 100644 --- a/src/compute_msd_chunk.cpp +++ b/src/compute_msd_chunk.cpp @@ -69,8 +69,8 @@ ComputeMSDChunk::~ComputeMSDChunk() if (modify->nfix) modify->delete_fix(id_fix); - delete [] id_fix; - delete [] idchunk; + delete[] id_fix; + delete[] idchunk; memory->destroy(massproc); memory->destroy(masstotal); memory->destroy(com); @@ -93,9 +93,8 @@ void ComputeMSDChunk::init() // if firstflag, will be created in setup() if (!firstflag) { - int ifix = modify->find_fix(id_fix); - if (ifix < 0) error->all(FLERR,"Could not find compute msd/chunk fix ID"); - fix = (FixStore *) modify->fix[ifix]; + fix = (FixStore *) modify->get_fix_by_id(id_fix); + if (!fix) error->all(FLERR,"Could not find compute msd/chunk fix with ID {}", id_fix); } } diff --git a/src/compute_pressure.cpp b/src/compute_pressure.cpp index 26a524dc5a..ef1de29309 100644 --- a/src/compute_pressure.cpp +++ b/src/compute_pressure.cpp @@ -195,8 +195,8 @@ void ComputePressure::init() if (improperflag && force->improper) nvirial++; } if (fixflag) - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->thermo_virial) nvirial++; + for (auto &ifix : modify->get_fix_list()) + if (ifix->thermo_virial) nvirial++; if (nvirial) { vptr = new double*[nvirial]; @@ -214,9 +214,9 @@ void ComputePressure::init() if (improperflag && force->improper) vptr[nvirial++] = force->improper->virial; if (fixflag) - for (int i = 0; i < modify->nfix; i++) - if (modify->fix[i]->virial_global_flag && modify->fix[i]->thermo_virial) - vptr[nvirial++] = modify->fix[i]->virial; + for (auto &ifix : modify->get_fix_list()) + if (ifix->virial_global_flag && ifix->thermo_virial) + vptr[nvirial++] = ifix->virial; } // flag Kspace contribution separately, since not summed across procs diff --git a/src/compute_reduce.cpp b/src/compute_reduce.cpp index a471b954ed..b9800ae94e 100644 --- a/src/compute_reduce.cpp +++ b/src/compute_reduce.cpp @@ -218,34 +218,26 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : "Compute reduce compute calculates global values"); } else if (which[i] == ArgInfo::FIX) { - int ifix = modify->find_fix(ids[i]); - if (ifix < 0) - error->all(FLERR,"Fix ID for compute reduce does not exist"); - if (modify->fix[ifix]->peratom_flag) { + auto ifix = modify->get_fix_by_id(ids[i]); + if (!ifix) + error->all(FLERR,"Fix ID {} for compute reduce does not exist", ids[i]); + if (ifix->peratom_flag) { flavor[i] = PERATOM; - if (argindex[i] == 0 && - modify->fix[ifix]->size_peratom_cols != 0) - error->all(FLERR,"Compute reduce fix does not " - "calculate a per-atom vector"); - if (argindex[i] && modify->fix[ifix]->size_peratom_cols == 0) - error->all(FLERR,"Compute reduce fix does not " - "calculate a per-atom array"); - if (argindex[i] && - argindex[i] > modify->fix[ifix]->size_peratom_cols) - error->all(FLERR,"Compute reduce fix array is accessed out-of-range"); - } else if (modify->fix[ifix]->local_flag) { + if (argindex[i] == 0 && (ifix->size_peratom_cols != 0)) + error->all(FLERR,"Compute reduce fix {} does not calculate a per-atom vector", ids[i]); + if (argindex[i] && (ifix->size_peratom_cols == 0)) + error->all(FLERR,"Compute reduce fix {} does not calculate a per-atom array", ids[i]); + if (argindex[i] && (argindex[i] > ifix->size_peratom_cols)) + error->all(FLERR,"Compute reduce fix {} array is accessed out-of-range", ids[i]); + } else if (ifix->local_flag) { flavor[i] = LOCAL; - if (argindex[i] == 0 && - modify->fix[ifix]->size_local_cols != 0) - error->all(FLERR,"Compute reduce fix does not " - "calculate a local vector"); - if (argindex[i] && modify->fix[ifix]->size_local_cols == 0) - error->all(FLERR,"Compute reduce fix does not " - "calculate a local array"); - if (argindex[i] && - argindex[i] > modify->fix[ifix]->size_local_cols) - error->all(FLERR,"Compute reduce fix array is accessed out-of-range"); - } else error->all(FLERR,"Compute reduce fix calculates global values"); + if (argindex[i] == 0 && (ifix->size_local_cols != 0)) + error->all(FLERR,"Compute reduce fix {} does not calculate a local vector", ids[i]); + if (argindex[i] && (ifix->size_local_cols == 0)) + error->all(FLERR,"Compute reduce fix {} does not calculate a local array", ids[i]); + if (argindex[i] && (argindex[i] > ifix->size_local_cols)) + error->all(FLERR,"Compute reduce fix {} array is accessed out-of-range", ids[i]); + } else error->all(FLERR,"Compute reduce fix {} calculates global values", ids[i]); } else if (which[i] == ArgInfo::VARIABLE) { int ivariable = input->variable->find(ids[i]); diff --git a/src/compute_reduce_chunk.cpp b/src/compute_reduce_chunk.cpp index a2aac9c95c..84af9056aa 100644 --- a/src/compute_reduce_chunk.cpp +++ b/src/compute_reduce_chunk.cpp @@ -123,30 +123,24 @@ ComputeReduceChunk::ComputeReduceChunk(LAMMPS *lmp, int narg, char **arg) : "Compute reduce/chunk 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 reduce/chunk does not exist"); - if (!modify->fix[ifix]->peratom_flag) - error->all(FLERR,"Compute reduce/chunk fix does not " - "calculate per-atom values"); - if (argindex[i] == 0 && - modify->fix[ifix]->size_peratom_cols != 0) - error->all(FLERR,"Compute reduce/chunk fix does not " - "calculate a per-atom vector"); - if (argindex[i] && modify->fix[ifix]->size_peratom_cols == 0) - error->all(FLERR,"Compute reduce/chunk fix does not " - "calculate a per-atom array"); - if (argindex[i] && argindex[i] > modify->fix[ifix]->size_peratom_cols) - error->all(FLERR,"Compute reduce/chunk fix array is " - "accessed out-of-range"); + auto ifix = modify->get_fix_by_id(ids[i]); + if (!ifix) + error->all(FLERR,"Fix ID {} for compute reduce/chunk does not exist", ids[i]); + if (!ifix->peratom_flag) + error->all(FLERR,"Compute reduce/chunk fix {} does not calculate per-atom values", ids[i]); + if ((argindex[i] == 0) && (ifix->size_peratom_cols != 0)) + error->all(FLERR,"Compute reduce/chunk fix {} does not calculate a per-atom vector", ids[i]); + if (argindex[i] && (ifix->size_peratom_cols == 0)) + error->all(FLERR,"Compute reduce/chunk fix {} does not calculate a per-atom array", ids[i]); + if (argindex[i] && (argindex[i] > ifix->size_peratom_cols)) + error->all(FLERR,"Compute reduce/chunk fix {} array is accessed out-of-range", ids[i]); } else if (which[i] == ArgInfo::VARIABLE) { int ivariable = input->variable->find(ids[i]); if (ivariable < 0) error->all(FLERR,"Variable name for compute reduce/chunk does not exist"); if (input->variable->atomstyle(ivariable) == 0) - error->all(FLERR,"Compute reduce/chunk variable is " - "not atom-style variable"); + error->all(FLERR,"Compute reduce/chunk variable is not atom-style variable"); } } @@ -380,8 +374,7 @@ void ComputeReduceChunk::compute_one(int m, double *vchunk, int nstride) } else if (which[m] == ArgInfo::FIX) { Fix *fix = modify->fix[vidx]; if (update->ntimestep % fix->peratom_freq) - error->all(FLERR,"Fix used in compute reduce/chunk not " - "computed at compatible time"); + error->all(FLERR,"Fix used in compute reduce/chunk not computed at compatible time"); if (argindex[m] == 0) { double *vfix = fix->vector_atom; diff --git a/src/compute_reduce_region.cpp b/src/compute_reduce_region.cpp index 1aace48f41..6e634f9e88 100644 --- a/src/compute_reduce_region.cpp +++ b/src/compute_reduce_region.cpp @@ -151,8 +151,7 @@ double ComputeReduceRegion::compute_one(int m, int flag) } else if (which[m] == ArgInfo::FIX) { if (update->ntimestep % modify->fix[n]->peratom_freq) - error->all(FLERR,"Fix used in compute reduce not computed at " - "compatible time"); + error->all(FLERR,"Fix used in compute reduce not computed at compatible time"); Fix *fix = modify->fix[n]; if (flavor[m] == PERATOM) { diff --git a/src/compute_slice.cpp b/src/compute_slice.cpp index 42eacc2523..f37bff1e17 100644 --- a/src/compute_slice.cpp +++ b/src/compute_slice.cpp @@ -92,25 +92,22 @@ ComputeSlice::ComputeSlice(LAMMPS *lmp, int narg, char **arg) : "global vector or array"); } else if (which[i] == ArgInfo::FIX) { - int ifix = modify->find_fix(ids[i]); - if (ifix < 0) - error->all(FLERR,"Fix ID for compute slice does not exist"); - if (modify->fix[ifix]->vector_flag) { + auto ifix = modify->get_fix_by_id(ids[i]); + if (!ifix) + error->all(FLERR,"Fix ID {} for compute slice does not exist", ids[i]); + if (ifix->vector_flag) { if (argindex[i]) - error->all(FLERR,"Compute slice fix does not " - "calculate a global array"); - if (nstop > modify->fix[ifix]->size_vector) - error->all(FLERR,"Compute slice fix vector is accessed out-of-range"); - } else if (modify->fix[ifix]->array_flag) { + error->all(FLERR,"Compute slice fix {} does not calculate a global array", ids[i]); + if (nstop > ifix->size_vector) + error->all(FLERR,"Compute slice fix {} vector is accessed out-of-range", ids[i]); + } else if (ifix->array_flag) { if (argindex[i] == 0) - error->all(FLERR,"Compute slice fix does not " - "calculate a global vector"); - if (argindex[i] > modify->fix[ifix]->size_array_cols) - error->all(FLERR,"Compute slice fix array is accessed out-of-range"); - if (nstop > modify->fix[ifix]->size_array_rows) - error->all(FLERR,"Compute slice fix array is accessed out-of-range"); - } else error->all(FLERR,"Compute slice fix does not calculate " - "global vector or array"); + error->all(FLERR,"Compute slice fix {} does not calculate a global vector", ids[i]); + if (argindex[i] > ifix->size_array_cols) + error->all(FLERR,"Compute slice fix {} array is accessed out-of-range", ids[i]); + if (nstop > ifix->size_array_rows) + error->all(FLERR,"Compute slice fix {} array is accessed out-of-range", ids[i]); + } else error->all(FLERR,"Compute slice fix {} does not calculate global vector or array", ids[i]); } else if (which[i] == ArgInfo::VARIABLE) { int ivariable = input->variable->find(ids[i]); @@ -144,16 +141,16 @@ ComputeSlice::ComputeSlice(LAMMPS *lmp, int narg, char **arg) : } } else extvector = modify->compute[icompute]->extarray; } else if (which[0] == ArgInfo::FIX) { - int ifix = modify->find_fix(ids[0]); + auto ifix = modify->get_fix_by_id(ids[0]); if (argindex[0] == 0) { - extvector = modify->fix[ifix]->extvector; - if (modify->fix[ifix]->extvector == -1) { + extvector = ifix->extvector; + if (ifix->extvector == -1) { extlist = new int[size_vector]; int j = 0; for (int i = nstart; i < nstop; i += nskip) - extlist[j++] = modify->fix[ifix]->extlist[i-1]; + extlist[j++] = ifix->extlist[i-1]; } - } else extvector = modify->fix[ifix]->extarray; + } else extvector = ifix->extarray; } else if (which[0] == ArgInfo::VARIABLE) { extvector = 0; } @@ -178,15 +175,15 @@ ComputeSlice::ComputeSlice(LAMMPS *lmp, int narg, char **arg) : if (modify->compute[icompute]->extarray) extarray = 1; } } else if (which[i] == ArgInfo::FIX) { - int ifix = modify->find_fix(ids[i]); + auto ifix = modify->get_fix_by_id(ids[i]); if (argindex[i] == 0) { - if (modify->fix[ifix]->extvector == 1) extarray = 1; - if (modify->fix[ifix]->extvector == -1) { - for (int j = 0; j < modify->fix[ifix]->size_vector; j++) - if (modify->fix[ifix]->extlist[j]) extarray = 1; + if (ifix->extvector == 1) extarray = 1; + if (ifix->extvector == -1) { + for (int j = 0; j < ifix->size_vector; j++) + if (ifix->extlist[j]) extarray = 1; } } else { - if (modify->fix[ifix]->extarray) extarray = 1; + if (ifix->extarray) extarray = 1; } } else if (which[i] == ArgInfo::VARIABLE) { // variable is always intensive, does not change extarray diff --git a/src/compute_stress_atom.cpp b/src/compute_stress_atom.cpp index ab36200833..ac69667294 100644 --- a/src/compute_stress_atom.cpp +++ b/src/compute_stress_atom.cpp @@ -13,21 +13,23 @@ ------------------------------------------------------------------------- */ #include "compute_stress_atom.h" -#include -#include "atom.h" -#include "update.h" -#include "comm.h" -#include "force.h" -#include "pair.h" -#include "bond.h" + #include "angle.h" +#include "atom.h" +#include "bond.h" +#include "comm.h" #include "dihedral.h" +#include "error.h" +#include "fix.h" +#include "force.h" #include "improper.h" #include "kspace.h" -#include "modify.h" -#include "fix.h" #include "memory.h" -#include "error.h" +#include "modify.h" +#include "pair.h" +#include "update.h" + +#include using namespace LAMMPS_NS; @@ -218,11 +220,9 @@ void ComputeStressAtom::compute_peratom() // and fix ave/spatial uses a per-atom stress from this compute as input 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) { - double **vatom = fix[ifix]->vatom; + for (auto &ifix : modify->get_fix_list()) + if (ifix->virial_peratom_flag && ifix->thermo_virial) { + double **vatom = ifix->vatom; if (vatom) for (i = 0; i < nlocal; i++) for (j = 0; j < 6; j++) diff --git a/src/compute_temp_deform.cpp b/src/compute_temp_deform.cpp index 83875febcc..c7b8e14d9e 100644 --- a/src/compute_temp_deform.cpp +++ b/src/compute_temp_deform.cpp @@ -67,15 +67,11 @@ void ComputeTempDeform::init() // check fix deform remap settings - for (i = 0; i < modify->nfix; i++) - if (utils::strmatch(modify->fix[i]->style, "^deform")) { - if (((FixDeform *) modify->fix[i])->remapflag == Domain::X_REMAP && comm->me == 0) - error->warning(FLERR, - "Using compute temp/deform with inconsistent fix deform remap option"); - break; - } - if (i == modify->nfix && comm->me == 0) - error->warning(FLERR, "Using compute temp/deform with no fix deform defined"); + auto fixes = modify->get_fix_by_style("^deform"); + if (fixes.size() > 0) { + if (((FixDeform *) fixes[0])->remapflag == Domain::X_REMAP && comm->me == 0) + error->warning(FLERR, "Using compute temp/deform with inconsistent fix deform remap option"); + } else error->warning(FLERR, "Using compute temp/deform with no fix deform defined"); } /* ---------------------------------------------------------------------- */ diff --git a/src/compute_vacf.cpp b/src/compute_vacf.cpp index 64d5ddb3f7..b6fbbedc48 100644 --- a/src/compute_vacf.cpp +++ b/src/compute_vacf.cpp @@ -40,8 +40,7 @@ ComputeVACF::ComputeVACF(LAMMPS *lmp, int narg, char **arg) : // id = compute-ID + COMPUTE_STORE, fix group = compute group id_fix = utils::strdup(id + std::string("_COMPUTE_STORE")); - fix = (FixStore *) modify->add_fix(fmt::format("{} {} STORE peratom 1 3", - id_fix, group->names[igroup])); + fix = (FixStore *) modify->add_fix(fmt::format("{} {} STORE peratom 1 3", id_fix, group->names[igroup])); // store current velocities in fix store array // skip if reset from restart file @@ -85,9 +84,8 @@ void ComputeVACF::init() { // set fix which stores original atom velocities - int ifix = modify->find_fix(id_fix); - if (ifix < 0) error->all(FLERR,"Could not find compute vacf fix ID"); - fix = (FixStore *) modify->fix[ifix]; + fix = (FixStore *) modify->get_fix_by_id(id_fix); + if (!fix) error->all(FLERR,"Could not find compute vacf fix ID {}", id_fix); // nvacf = # of atoms in group