2006-09-28 03:51:33 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
2007-01-30 08:22:05 +08:00
|
|
|
http://lammps.sandia.gov, Sandia National Laboratories
|
|
|
|
Steve Plimpton, sjplimp@sandia.gov
|
2006-09-28 03:51:33 +08:00
|
|
|
|
|
|
|
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
|
|
|
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
2012-06-07 06:47:51 +08:00
|
|
|
certain rights in this software. This software is distributed under
|
2006-09-28 03:51:33 +08:00
|
|
|
the GNU General Public License.
|
|
|
|
|
|
|
|
See the README file in the top-level LAMMPS directory.
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#include "stdio.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "fix_nve.h"
|
|
|
|
#include "atom.h"
|
|
|
|
#include "force.h"
|
|
|
|
#include "update.h"
|
|
|
|
#include "respa.h"
|
|
|
|
#include "error.h"
|
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
using namespace LAMMPS_NS;
|
2012-02-02 00:27:41 +08:00
|
|
|
using namespace FixConst;
|
2007-01-30 08:22:05 +08:00
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
FixNVE::FixNVE(LAMMPS *lmp, int narg, char **arg) :
|
|
|
|
Fix(lmp, narg, arg)
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
2008-05-17 03:33:24 +08:00
|
|
|
if (strcmp(style,"nve/sphere") != 0 && narg < 3)
|
2011-09-24 02:06:55 +08:00
|
|
|
error->all(FLERR,"Illegal fix nve command");
|
2008-04-05 07:18:14 +08:00
|
|
|
|
2014-05-02 23:56:16 +08:00
|
|
|
dynamic_group_allow = 1;
|
2008-04-05 07:18:14 +08:00
|
|
|
time_integrate = 1;
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int FixNVE::setmask()
|
|
|
|
{
|
|
|
|
int mask = 0;
|
|
|
|
mask |= INITIAL_INTEGRATE;
|
|
|
|
mask |= FINAL_INTEGRATE;
|
|
|
|
mask |= INITIAL_INTEGRATE_RESPA;
|
|
|
|
mask |= FINAL_INTEGRATE_RESPA;
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixNVE::init()
|
|
|
|
{
|
|
|
|
dtv = update->dt;
|
|
|
|
dtf = 0.5 * update->dt * force->ftm2v;
|
|
|
|
|
2011-06-21 00:42:39 +08:00
|
|
|
if (strstr(update->integrate_style,"respa"))
|
2006-09-28 03:51:33 +08:00
|
|
|
step_respa = ((Respa *) update->integrate)->step;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
allow for both per-type and per-atom mass
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2008-01-10 05:56:57 +08:00
|
|
|
void FixNVE::initial_integrate(int vflag)
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
|
|
|
double dtfm;
|
|
|
|
|
2009-11-18 05:18:23 +08:00
|
|
|
// update v and x of atoms in group
|
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
double **x = atom->x;
|
|
|
|
double **v = atom->v;
|
|
|
|
double **f = atom->f;
|
2007-01-30 08:22:05 +08:00
|
|
|
double *rmass = atom->rmass;
|
2009-11-30 23:48:56 +08:00
|
|
|
double *mass = atom->mass;
|
2006-09-28 03:51:33 +08:00
|
|
|
int *type = atom->type;
|
|
|
|
int *mask = atom->mask;
|
|
|
|
int nlocal = atom->nlocal;
|
2008-02-16 03:06:53 +08:00
|
|
|
if (igroup == atom->firstgroup) nlocal = atom->nfirst;
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2009-02-13 05:36:52 +08:00
|
|
|
if (rmass) {
|
2010-09-30 07:38:32 +08:00
|
|
|
for (int i = 0; i < nlocal; i++)
|
2006-09-28 03:51:33 +08:00
|
|
|
if (mask[i] & groupbit) {
|
2012-06-07 06:47:51 +08:00
|
|
|
dtfm = dtf / rmass[i];
|
|
|
|
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];
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2010-09-30 07:38:32 +08:00
|
|
|
for (int i = 0; i < nlocal; i++)
|
2006-09-28 03:51:33 +08:00
|
|
|
if (mask[i] & groupbit) {
|
2012-06-07 06:47:51 +08:00
|
|
|
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];
|
|
|
|
x[i][0] += dtv * v[i][0];
|
|
|
|
x[i][1] += dtv * v[i][1];
|
|
|
|
x[i][2] += dtv * v[i][2];
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixNVE::final_integrate()
|
|
|
|
{
|
|
|
|
double dtfm;
|
|
|
|
|
2009-11-18 05:18:23 +08:00
|
|
|
// update v of atoms in group
|
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
double **v = atom->v;
|
|
|
|
double **f = atom->f;
|
2007-01-30 08:22:05 +08:00
|
|
|
double *rmass = atom->rmass;
|
2009-11-30 23:48:56 +08:00
|
|
|
double *mass = atom->mass;
|
2006-09-28 03:51:33 +08:00
|
|
|
int *type = atom->type;
|
|
|
|
int *mask = atom->mask;
|
|
|
|
int nlocal = atom->nlocal;
|
2008-02-16 03:06:53 +08:00
|
|
|
if (igroup == atom->firstgroup) nlocal = atom->nfirst;
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2009-02-13 05:36:52 +08:00
|
|
|
if (rmass) {
|
2010-09-30 07:38:32 +08:00
|
|
|
for (int i = 0; i < nlocal; i++)
|
2006-09-28 03:51:33 +08:00
|
|
|
if (mask[i] & groupbit) {
|
2012-06-07 06:47:51 +08:00
|
|
|
dtfm = dtf / rmass[i];
|
|
|
|
v[i][0] += dtfm * f[i][0];
|
|
|
|
v[i][1] += dtfm * f[i][1];
|
|
|
|
v[i][2] += dtfm * f[i][2];
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2010-09-30 07:38:32 +08:00
|
|
|
for (int i = 0; i < nlocal; i++)
|
2006-09-28 03:51:33 +08:00
|
|
|
if (mask[i] & groupbit) {
|
2012-06-07 06:47:51 +08:00
|
|
|
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];
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2010-03-26 00:24:30 +08:00
|
|
|
void FixNVE::initial_integrate_respa(int vflag, int ilevel, int iloop)
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
|
|
|
dtv = step_respa[ilevel];
|
|
|
|
dtf = 0.5 * step_respa[ilevel] * force->ftm2v;
|
|
|
|
|
2008-03-12 01:15:30 +08:00
|
|
|
// innermost level - NVE update of v and x
|
|
|
|
// all other levels - NVE update of v
|
|
|
|
|
2008-01-10 05:56:57 +08:00
|
|
|
if (ilevel == 0) initial_integrate(vflag);
|
2006-09-28 03:51:33 +08:00
|
|
|
else final_integrate();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2010-03-26 00:24:30 +08:00
|
|
|
void FixNVE::final_integrate_respa(int ilevel, int iloop)
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
|
|
|
dtf = 0.5 * step_respa[ilevel] * force->ftm2v;
|
|
|
|
final_integrate();
|
|
|
|
}
|
2007-10-11 06:22:16 +08:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixNVE::reset_dt()
|
|
|
|
{
|
|
|
|
dtv = update->dt;
|
|
|
|
dtf = 0.5 * update->dt * force->ftm2v;
|
|
|
|
}
|