#include "fix_nve_omp.h"
#include "atom.h"
using namespace LAMMPS_NS;
using namespace FixConst;
typedef struct { double x,y,z; } dbl3_t;
FixNVEOMP::FixNVEOMP(LAMMPS *lmp, int narg, char **arg) :
FixNVE(lmp, narg, arg) { }
void FixNVEOMP::initial_integrate(int )
{
dbl3_t * _noalias const x = (dbl3_t *) atom->x[0];
dbl3_t * _noalias const v = (dbl3_t *) atom->v[0];
const dbl3_t * _noalias const f = (dbl3_t *) atom->f[0];
const int * const mask = atom->mask;
const int nlocal = (igroup == atom->firstgroup) ? atom->nfirst : atom->nlocal;
int i;
if (atom->rmass) {
const double * const rmass = atom->rmass;
#if defined (_OPENMP)
#pragma omp parallel for private(i) default(none) schedule(static)
#endif
for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
const double dtfm = dtf / rmass[i];
v[i].x += dtfm * f[i].x;
v[i].y += dtfm * f[i].y;
v[i].z += dtfm * f[i].z;
x[i].x += dtv * v[i].x;
x[i].y += dtv * v[i].y;
x[i].z += dtv * v[i].z;
}
} else {
const double * const mass = atom->mass;
const int * const type = atom->type;
#if defined (_OPENMP)
#pragma omp parallel for private(i) default(none) schedule(static)
#endif
for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
const double dtfm = dtf / mass[type[i]];
v[i].x += dtfm * f[i].x;
v[i].y += dtfm * f[i].y;
v[i].z += dtfm * f[i].z;
x[i].x += dtv * v[i].x;
x[i].y += dtv * v[i].y;
x[i].z += dtv * v[i].z;
}
}
}
void FixNVEOMP::final_integrate()
{
dbl3_t * _noalias const v = (dbl3_t *) atom->v[0];
const dbl3_t * _noalias const f = (dbl3_t *) atom->f[0];
const int * const mask = atom->mask;
const int nlocal = (igroup == atom->firstgroup) ? atom->nfirst : atom->nlocal;
int i;
if (atom->rmass) {
const double * const rmass = atom->rmass;
#if defined (_OPENMP)
#pragma omp parallel for private(i) default(none) schedule(static)
#endif
for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
const double dtfm = dtf / rmass[i];
v[i].x += dtfm * f[i].x;
v[i].y += dtfm * f[i].y;
v[i].z += dtfm * f[i].z;
}
} else {
const double * const mass = atom->mass;
const int * const type = atom->type;
#if defined (_OPENMP)
#pragma omp parallel for private(i) default(none) schedule(static)
#endif
for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
const double dtfm = dtf / mass[type[i]];
v[i].x += dtfm * f[i].x;
v[i].y += dtfm * f[i].y;
v[i].z += dtfm * f[i].z;
}
}
}