modernize lookup of fixes

This commit is contained in:
Axel Kohlmeyer
2023-04-02 17:46:42 -04:00
parent eb13217498
commit 09deafd6d4
7 changed files with 55 additions and 78 deletions

View File

@ -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

View File

@ -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".

View File

@ -188,10 +188,10 @@ 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");
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

View File

@ -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

View File

@ -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);
}
/* ---------------------------------------------------------------------- */

View File

@ -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");

View File

@ -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 <cstring>
#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 <cstring>
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<FixOMP *>(lmp->modify->fix[ifix]);
fix = static_cast<FixOMP *>(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);
}
}
}
/* ----------------------------------------------------------------------