#include "fix_meso.h"
#include "atom.h"
#include "force.h"
#include "update.h"
#include "error.h"
using namespace LAMMPS_NS;
using namespace FixConst;
FixMeso::FixMeso(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg) {
if ((atom->e_flag != 1) || (atom->rho_flag != 1))
error->all(FLERR,
"fix meso command requires atom_style with both energy and density");
if (narg != 3)
error->all(FLERR,"Illegal number of arguments for fix meso command");
time_integrate = 1;
}
int FixMeso::setmask() {
int mask = 0;
mask |= INITIAL_INTEGRATE;
mask |= FINAL_INTEGRATE;
mask |= PRE_FORCE;
return mask;
}
void FixMeso::init() {
dtv = update->dt;
dtf = 0.5 * update->dt * force->ftm2v;
}
void FixMeso::setup_pre_force(int )
{
double **v = atom->v;
double **vest = atom->vest;
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) {
vest[i][0] = v[i][0];
vest[i][1] = v[i][1];
vest[i][2] = v[i][2];
}
}
}
void FixMeso::initial_integrate(int ) {
double **x = atom->x;
double **v = atom->v;
double **f = atom->f;
double **vest = atom->vest;
double *rho = atom->rho;
double *drho = atom->drho;
double *e = atom->e;
double *de = atom->de;
double *mass = atom->mass;
double *rmass = atom->rmass;
int rmass_flag = atom->rmass_flag;
int *type = atom->type;
int *mask = atom->mask;
int nlocal = atom->nlocal;
int i;
double dtfm;
if (igroup == atom->firstgroup)
nlocal = atom->nfirst;
for (i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
if (rmass_flag) {
dtfm = dtf / rmass[i];
} else {
dtfm = dtf / mass[type[i]];
}
e[i] += dtf * de[i]; rho[i] += dtf * drho[i];
vest[i][0] = v[i][0] + 2.0 * dtfm * f[i][0];
vest[i][1] = v[i][1] + 2.0 * dtfm * f[i][1];
vest[i][2] = v[i][2] + 2.0 * dtfm * f[i][2];
v[i][0] += dtfm * f[i][0];
v[i][1] += dtfm * f[i][1];
v[i][2] += dtfm * f[i][2];
x[i][0] += dtv * v[i][0];
x[i][1] += dtv * v[i][1];
x[i][2] += dtv * v[i][2];
}
}
}
void FixMeso::final_integrate() {
double **v = atom->v;
double **f = atom->f;
double *e = atom->e;
double *de = atom->de;
double *rho = atom->rho;
double *drho = atom->drho;
int *type = atom->type;
int *mask = atom->mask;
double *mass = atom->mass;
int nlocal = atom->nlocal;
if (igroup == atom->firstgroup)
nlocal = atom->nfirst;
double dtfm;
double *rmass = atom->rmass;
int rmass_flag = atom->rmass_flag;
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
if (rmass_flag) {
dtfm = dtf / rmass[i];
} else {
dtfm = dtf / mass[type[i]];
}
v[i][0] += dtfm * f[i][0];
v[i][1] += dtfm * f[i][1];
v[i][2] += dtfm * f[i][2];
e[i] += dtf * de[i];
rho[i] += dtf * drho[i];
}
}
}
void FixMeso::reset_dt() {
dtv = update->dt;
dtf = 0.5 * update->dt * force->ftm2v;
}