#include "fix_nh_body.h"
#include "math_extra.h"
#include "atom.h"
#include "atom_vec_body.h"
#include "error.h"
using namespace LAMMPS_NS;
using namespace FixConst;
FixNHBody::FixNHBody(LAMMPS *lmp, int narg, char **arg) :
FixNH(lmp, narg, arg)
{
}
void FixNHBody::init()
{
avec = (AtomVecBody *) atom->style_match("body");
if (!avec)
error->all(FLERR,
"Compute nvt/nph/npt body requires atom style body");
int *body = atom->body;
int *mask = atom->mask;
int nlocal = atom->nlocal;
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit)
if (body[i] < 0)
error->one(FLERR,"Fix nvt/nph/npt body requires bodies");
FixNH::init();
}
void FixNHBody::nve_v()
{
FixNH::nve_v();
double **angmom = atom->angmom;
double **torque = atom->torque;
int *mask = atom->mask;
int nlocal = atom->nlocal;
if (igroup == atom->firstgroup) nlocal = atom->nfirst;
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
angmom[i][0] += dtf*torque[i][0];
angmom[i][1] += dtf*torque[i][1];
angmom[i][2] += dtf*torque[i][2];
}
}
}
void FixNHBody::nve_x()
{
double omega[3];
double *quat,*inertia;
FixNH::nve_x();
AtomVecBody::Bonus *bonus = avec->bonus;
int *body = atom->body;
double **angmom = atom->angmom;
int *mask = atom->mask;
int nlocal = atom->nlocal;
if (igroup == atom->firstgroup) nlocal = atom->nfirst;
dtq = 0.5 * dtv;
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
inertia = bonus[body[i]].inertia;
quat = bonus[body[i]].quat;
MathExtra::mq_to_omega(angmom[i],quat,inertia,omega);
MathExtra::richardson(quat,angmom[i],omega,inertia,dtq);
}
}
void FixNHBody::nh_v_temp()
{
FixNH::nh_v_temp();
double **angmom = atom->angmom;
int *mask = atom->mask;
int nlocal = atom->nlocal;
if (igroup == atom->firstgroup) nlocal = atom->nfirst;
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
angmom[i][0] *= factor_eta;
angmom[i][1] *= factor_eta;
angmom[i][2] *= factor_eta;
}
}
}