diff --git a/src/COLVARS/fix_colvars.cpp b/src/COLVARS/fix_colvars.cpp index 3a613a6785..0fd7bc9857 100644 --- a/src/COLVARS/fix_colvars.cpp +++ b/src/COLVARS/fix_colvars.cpp @@ -324,7 +324,7 @@ FixColvars::FixColvars(LAMMPS *lmp, int narg, char **arg) : if (!out_name) out_name = utils::strdup("out"); /* initialize various state variables. */ - tstat_id = -1; + tstat_fix = nullptr; energy = 0.0; nlevels_respa = 0; init_flag = 0; @@ -432,12 +432,13 @@ void FixColvars::one_time_init() double t_target = 0.0; if (tmp_name) { if (strcmp(tmp_name,"NULL") == 0) { - tstat_id = -1; + tstat_fix = nullptr; } else { - tstat_id = modify->find_fix(tmp_name); - if (tstat_id < 0) error->one(FLERR,"Could not find tstat fix ID"); - double *tt = (double*)modify->fix[tstat_id]->extract("t_target",tmp); + tstat_fix = modify->get_fix_by_id(tmp_name); + if (!tstat_fix) error->one(FLERR, "Could not find thermostat fix ID {}", tmp_name); + double *tt = (double*) tstat_fix->extract("t_target", tmp); if (tt) t_target = *tt; + else error->one(FLERR, "Fix ID {} is not a thermostat fix", tmp_name); } } @@ -675,13 +676,13 @@ void FixColvars::post_force(int /*vflag*/) if (proxy->want_exit()) error->one(FLERR,"Run aborted on request from colvars module.\n"); - if (tstat_id < 0) { + if (!tstat_fix) { proxy->set_temperature(0.0); } else { int tmp; // get thermostat target temperature from corresponding fix, // if the fix supports extraction. - double *tt = (double *) modify->fix[tstat_id]->extract("t_target",tmp); + double *tt = (double *) tstat_fix->extract("t_target", tmp); if (tt) proxy->set_temperature(*tt); else diff --git a/src/COLVARS/fix_colvars.h b/src/COLVARS/fix_colvars.h index 715ee64a7f..45fe09af78 100644 --- a/src/COLVARS/fix_colvars.h +++ b/src/COLVARS/fix_colvars.h @@ -68,7 +68,7 @@ class FixColvars : public Fix { char *out_name; // prefix string for all output files char *tmp_name; // name of thermostat fix. int rng_seed; // seed to initialize random number generator - int tstat_id; // id of the thermostat fix + Fix *tstat_fix; // pointer to thermostat fix double energy; // biasing energy of the fix int me; // my MPI rank in this "world". diff --git a/src/EXTRA-COMPUTE/compute_hma.cpp b/src/EXTRA-COMPUTE/compute_hma.cpp index 4b949f6592..592c8501c1 100644 --- a/src/EXTRA-COMPUTE/compute_hma.cpp +++ b/src/EXTRA-COMPUTE/compute_hma.cpp @@ -188,11 +188,11 @@ void ComputeHMA::init_list(int /* id */, NeighList *ptr) void ComputeHMA::setup() { int dummy=0; - int ifix = modify->find_fix(id_temp); - if (ifix < 0) error->all(FLERR,"Could not find compute hma temperature ID"); - auto temperat = (double *) modify->fix[ifix]->extract("t_target",dummy); - if (temperat==nullptr) error->all(FLERR,"Could not find compute hma temperature ID"); - finaltemp = * temperat; + Fix *ifix = modify->get_fix_by_id(id_temp); + if (!ifix) error->all(FLERR,"Could not find compute hma temperature fix ID {}", id_temp); + auto temperat = (double *) ifix->extract("t_target",dummy); + if (temperat == nullptr) error->all(FLERR,"Fix ID {} is not a thermostat {}", id_temp); + finaltemp = *temperat; // set fix which stores original atom coords diff --git a/src/EXTRA-FIX/fix_controller.cpp b/src/EXTRA-FIX/fix_controller.cpp index 22aecd0c13..d7989c79d7 100644 --- a/src/EXTRA-FIX/fix_controller.cpp +++ b/src/EXTRA-FIX/fix_controller.cpp @@ -71,28 +71,22 @@ FixController::FixController(LAMMPS *lmp, int narg, char **arg) : // error check if (pvwhich == ArgInfo::COMPUTE) { - int icompute = modify->find_compute(pvID); - if (icompute < 0) - error->all(FLERR,"Compute ID for fix controller does not exist"); - Compute *c = modify->compute[icompute]; + Compute *c = modify->get_compute_by_id(pvID); + if (!c) error->all(FLERR,"Compute ID {} for fix controller does not exist", pvID); int flag = 0; if (c->scalar_flag && pvindex == 0) flag = 1; else if (c->vector_flag && pvindex > 0) flag = 1; - if (!flag) error->all(FLERR,"Fix controller compute does not " - "calculate a global scalar or vector"); + if (!flag) + error->all(FLERR,"Fix controller compute does not calculate a global scalar or vector"); if (pvindex && pvindex > c->size_vector) - error->all(FLERR,"Fix controller compute vector is " - "accessed out-of-range"); + error->all(FLERR,"Fix controller compute vector is accessed out-of-range"); } else if (pvwhich == ArgInfo::FIX) { - int ifix = modify->find_fix(pvID); - if (ifix < 0) - error->all(FLERR,"Fix ID for fix controller does not exist"); - Fix *f = modify->fix[ifix]; + Fix *f = modify->get_fix_by_id(pvID); + if (!f) error->all(FLERR,"Fix ID {} for fix controller does not exist", pvID); int flag = 0; if (f->scalar_flag && pvindex == 0) flag = 1; else if (f->vector_flag && pvindex > 0) flag = 1; - if (!flag) error->all(FLERR,"Fix controller fix does not " - "calculate a global scalar or vector"); + if (!flag) error->all(FLERR,"Fix controller fix does not calculate a global scalar or vector"); if (pvindex && pvindex > f->size_vector) error->all(FLERR,"Fix controller fix vector is accessed out-of-range"); } else if (pvwhich == ArgInfo::VARIABLE) { @@ -135,25 +129,20 @@ int FixController::setmask() void FixController::init() { if (pvwhich == ArgInfo::COMPUTE) { - int icompute = modify->find_compute(pvID); - if (icompute < 0) - error->all(FLERR,"Compute ID for fix controller does not exist"); - pcompute = modify->compute[icompute]; + pcompute = modify->get_compute_by_id(pvID); + if (!pcompute) error->all(FLERR,"Compute ID {} for fix controller does not exist", pvID); } else if (pvwhich == ArgInfo::FIX) { - int ifix = modify->find_fix(pvID); - if (ifix < 0) error->all(FLERR,"Fix ID for fix controller does not exist"); - pfix = modify->fix[ifix]; + pfix = modify->get_fix_by_id(pvID); + if (!pfix) error->all(FLERR,"Fix ID {} for fix controller does not exist", pvID); } else if (pvwhich == ArgInfo::VARIABLE) { pvar = input->variable->find(pvID); - if (pvar < 0) - error->all(FLERR,"Variable name for fix controller does not exist"); + if (pvar < 0) error->all(FLERR,"Variable name for fix controller does not exist"); } cvar = input->variable->find(cvID); - if (cvar < 0) - error->all(FLERR,"Variable name for fix controller does not exist"); + if (cvar < 0) error->all(FLERR,"Variable name for fix controller does not exist"); // set sampling time diff --git a/src/MC/fix_charge_regulation.cpp b/src/MC/fix_charge_regulation.cpp index 8fb3efcbdc..0626762faf 100644 --- a/src/MC/fix_charge_regulation.cpp +++ b/src/MC/fix_charge_regulation.cpp @@ -1294,16 +1294,13 @@ void FixChargeRegulation::restart(char *buf) /* ---------------------------------------------------------------------- */ void FixChargeRegulation::setThermoTemperaturePointer() { - int ifix = -1; - ifix = modify->find_fix(idftemp); - if (ifix == -1) { - error->all(FLERR, "fix charge/regulation regulation could not find " - "a temperature fix id provided by tempfixid\n"); - } - Fix *temperature_fix = modify->fix[ifix]; - int dim; - target_temperature_tcp = (double *) temperature_fix->extract("t_target", dim); + Fix *ifix = modify->get_fix_by_id(idftemp); + if (!ifix) + error->all(FLERR, "fix charge/regulation could not find thermostat fix id {}", idftemp); + int dim; + target_temperature_tcp = (double *) ifix->extract("t_target", dim); + if (!target_temperature_tcp) error->all(FLERR, "Fix id {} does not control temperature", idftemp); } /* ---------------------------------------------------------------------- */ diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index b3267bbd02..f8193f6235 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -565,9 +565,8 @@ void FixGCMC::init() fixrigid = nullptr; if (rigidflag) { - int ifix = modify->find_fix(idrigid); - if (ifix < 0) error->all(FLERR,"Fix gcmc rigid fix does not exist"); - fixrigid = modify->fix[ifix]; + fixrigid = modify->get_fix_by_id(idrigid); + if (!fixrigid) error->all(FLERR,"Fix gcmc rigid fix ID {} does not exist", idrigid); int tmp; if (&onemols[imol] != (Molecule **) fixrigid->extract("onemol",tmp)) error->all(FLERR, "Fix gcmc and fix rigid/small not using same molecule template ID"); @@ -578,9 +577,8 @@ void FixGCMC::init() fixshake = nullptr; if (shakeflag) { - int ifix = modify->find_fix(idshake); - if (ifix < 0) error->all(FLERR,"Fix gcmc shake fix does not exist"); - fixshake = modify->fix[ifix]; + fixshake = modify->get_fix_by_id(idshake); + if (!fixshake) error->all(FLERR,"Fix gcmc shake fix ID {} does not exist", idshake); int tmp; if (&onemols[imol] != (Molecule **) fixshake->extract("onemol",tmp)) error->all(FLERR,"Fix gcmc and fix shake not using same molecule template ID"); diff --git a/src/OPENMP/thr_omp.cpp b/src/OPENMP/thr_omp.cpp index 7bcb75130f..c27a99028d 100644 --- a/src/OPENMP/thr_omp.cpp +++ b/src/OPENMP/thr_omp.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ------------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -17,42 +16,37 @@ OpenMP based threading support for LAMMPS ------------------------------------------------------------------------- */ -#include - -#include "atom.h" -#include "comm.h" -#include "error.h" -#include "force.h" -#include "modify.h" -#include "neighbor.h" - - #include "thr_omp.h" -#include "pair.h" -#include "bond.h" #include "angle.h" -#include "dihedral.h" -#include "improper.h" +#include "atom.h" +#include "bond.h" +#include "comm.h" #include "compute.h" - +#include "dihedral.h" +#include "error.h" +#include "force.h" +#include "improper.h" #include "math_const.h" +#include "modify.h" +#include "neighbor.h" +#include "pair.h" + +#include using namespace LAMMPS_NS; -using namespace MathConst; +using MathConst::THIRD; /* ---------------------------------------------------------------------- */ -ThrOMP::ThrOMP(LAMMPS *ptr, int style) - : lmp(ptr), fix(nullptr), thr_style(style), thr_error(0) +ThrOMP::ThrOMP(LAMMPS *ptr, int style) : lmp(ptr), fix(nullptr), thr_style(style), thr_error(0) { // register fix omp with this class - int ifix = lmp->modify->find_fix("package_omp"); - if (ifix < 0) - lmp->error->all(FLERR,"The 'package omp' command is required for /omp styles"); - fix = static_cast(lmp->modify->fix[ifix]); + fix = static_cast(lmp->modify->get_fix_by_id("package_omp")); + if (!fix) lmp->error->all(FLERR, "The 'package omp' command is required for /omp styles"); } +// clang-format off /* ---------------------------------------------------------------------- Hook up per thread per atom arrays into the tally infrastructure ---------------------------------------------------------------------- */ @@ -154,7 +148,6 @@ void ThrOMP::ev_setup_thr(int eflag, int vflag, int nall, double *eatom, memset(&(thr->cvatom_imprp[0][0]),0,nall*9*sizeof(double)); } } - // nothing to do for THR_KSPACE } @@ -1312,7 +1305,6 @@ void ThrOMP::ev_tally_thr(Dihedral * const dihed, const int i1, const int i2, if (i4 < nlocal) v_tally9(thr->cvatom_dihed[i4],v4); } } - } /* ----------------------------------------------------------------------