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.
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2009-08-09 06:58:52 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
2013-06-07 02:10:38 +08:00
|
|
|
Contributing authors: Carolyn Phillips (U Mich), reservoir energy tally
|
|
|
|
Aidan Thompson (SNL) GJF formulation
|
2009-08-09 06:58:52 +08:00
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
#include "mpi.h"
|
|
|
|
#include "math.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
#include "fix_langevin.h"
|
2011-04-29 23:52:26 +08:00
|
|
|
#include "math_extra.h"
|
2006-09-28 03:51:33 +08:00
|
|
|
#include "atom.h"
|
2011-04-29 23:52:26 +08:00
|
|
|
#include "atom_vec_ellipsoid.h"
|
2006-09-28 03:51:33 +08:00
|
|
|
#include "force.h"
|
|
|
|
#include "update.h"
|
2008-03-12 01:15:30 +08:00
|
|
|
#include "modify.h"
|
|
|
|
#include "compute.h"
|
2006-09-28 03:51:33 +08:00
|
|
|
#include "domain.h"
|
|
|
|
#include "region.h"
|
|
|
|
#include "respa.h"
|
|
|
|
#include "comm.h"
|
2011-11-29 06:41:16 +08:00
|
|
|
#include "input.h"
|
|
|
|
#include "variable.h"
|
2006-09-28 03:51:33 +08:00
|
|
|
#include "random_mars.h"
|
2009-08-09 06:58:52 +08:00
|
|
|
#include "memory.h"
|
2006-09-28 03:51:33 +08:00
|
|
|
#include "error.h"
|
2011-03-28 07:34:04 +08:00
|
|
|
#include "group.h"
|
2006-09-28 03:51:33 +08:00
|
|
|
|
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
|
|
|
|
2008-03-12 01:15:30 +08:00
|
|
|
enum{NOBIAS,BIAS};
|
2011-11-29 06:41:16 +08:00
|
|
|
enum{CONSTANT,EQUAL,ATOM};
|
2008-03-12 01:15:30 +08:00
|
|
|
|
2011-04-30 05:05:35 +08:00
|
|
|
#define SINERTIA 0.4 // moment of inertia prefactor for sphere
|
|
|
|
#define EINERTIA 0.2 // moment of inertia prefactor for ellipsoid
|
2011-04-29 23:52:26 +08:00
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
FixLangevin::FixLangevin(LAMMPS *lmp, int narg, char **arg) :
|
|
|
|
Fix(lmp, narg, arg)
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
2011-09-24 02:06:55 +08:00
|
|
|
if (narg < 7) error->all(FLERR,"Illegal fix langevin command");
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2009-08-09 06:58:52 +08:00
|
|
|
scalar_flag = 1;
|
2009-12-05 05:03:54 +08:00
|
|
|
global_freq = 1;
|
2009-08-09 06:58:52 +08:00
|
|
|
extscalar = 1;
|
|
|
|
nevery = 1;
|
2009-01-06 06:26:08 +08:00
|
|
|
|
2011-11-29 06:41:16 +08:00
|
|
|
tstr = NULL;
|
|
|
|
if (strstr(arg[3],"v_") == arg[3]) {
|
|
|
|
int n = strlen(&arg[3][2]) + 1;
|
|
|
|
tstr = new char[n];
|
|
|
|
strcpy(tstr,&arg[3][2]);
|
|
|
|
} else {
|
|
|
|
t_start = atof(arg[3]);
|
2012-05-24 00:24:30 +08:00
|
|
|
t_target = t_start;
|
2011-11-29 06:41:16 +08:00
|
|
|
tstyle = CONSTANT;
|
|
|
|
}
|
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
t_stop = atof(arg[4]);
|
|
|
|
t_period = atof(arg[5]);
|
|
|
|
int seed = atoi(arg[6]);
|
|
|
|
|
2011-09-24 02:06:55 +08:00
|
|
|
if (t_period <= 0.0) error->all(FLERR,"Fix langevin period must be > 0.0");
|
|
|
|
if (seed <= 0) error->all(FLERR,"Illegal fix langevin command");
|
2006-09-28 03:51:33 +08:00
|
|
|
|
|
|
|
// initialize Marsaglia RNG with processor-unique seed
|
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
random = new RanMars(lmp,seed + comm->me);
|
2006-09-28 03:51:33 +08:00
|
|
|
|
|
|
|
// allocate per-type arrays for force prefactors
|
|
|
|
|
|
|
|
gfactor1 = new double[atom->ntypes+1];
|
|
|
|
gfactor2 = new double[atom->ntypes+1];
|
|
|
|
ratio = new double[atom->ntypes+1];
|
2012-06-07 06:47:51 +08:00
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
// optional args
|
|
|
|
|
|
|
|
for (int i = 1; i <= atom->ntypes; i++) ratio[i] = 1.0;
|
2013-04-24 05:57:35 +08:00
|
|
|
ascale = 0.0;
|
2013-06-07 02:10:38 +08:00
|
|
|
gjfflag = 0;
|
|
|
|
oflag = 0;
|
|
|
|
tallyflag = 0;
|
2011-03-30 07:41:25 +08:00
|
|
|
zeroflag = 0;
|
2006-09-28 03:51:33 +08:00
|
|
|
|
|
|
|
int iarg = 7;
|
|
|
|
while (iarg < narg) {
|
2011-04-30 00:28:42 +08:00
|
|
|
if (strcmp(arg[iarg],"angmom") == 0) {
|
2011-09-24 02:06:55 +08:00
|
|
|
if (iarg+2 > narg) error->all(FLERR,"Illegal fix langevin command");
|
2013-04-24 05:57:35 +08:00
|
|
|
if (strcmp(arg[iarg+1],"no") == 0) ascale = 0.0;
|
2013-06-28 04:02:55 +08:00
|
|
|
else ascale = force->numeric(FLERR,arg[iarg+1]);
|
2011-04-30 00:28:42 +08:00
|
|
|
iarg += 2;
|
2013-06-07 02:10:38 +08:00
|
|
|
} else if (strcmp(arg[iarg],"gjf") == 0) {
|
|
|
|
if (iarg+2 > narg) error->all(FLERR,"Illegal fix langevin command");
|
|
|
|
if (strcmp(arg[iarg+1],"no") == 0) gjfflag = 0;
|
|
|
|
else if (strcmp(arg[iarg+1],"yes") == 0) gjfflag = 1;
|
|
|
|
else error->all(FLERR,"Illegal fix langevin command");
|
|
|
|
iarg += 2;
|
2011-04-30 00:28:42 +08:00
|
|
|
} else if (strcmp(arg[iarg],"omega") == 0) {
|
2011-09-24 02:06:55 +08:00
|
|
|
if (iarg+2 > narg) error->all(FLERR,"Illegal fix langevin command");
|
2011-04-30 00:28:42 +08:00
|
|
|
if (strcmp(arg[iarg+1],"no") == 0) oflag = 0;
|
|
|
|
else if (strcmp(arg[iarg+1],"yes") == 0) oflag = 1;
|
2011-09-24 02:06:55 +08:00
|
|
|
else error->all(FLERR,"Illegal fix langevin command");
|
2011-04-30 00:28:42 +08:00
|
|
|
iarg += 2;
|
|
|
|
} else if (strcmp(arg[iarg],"scale") == 0) {
|
2011-09-24 02:06:55 +08:00
|
|
|
if (iarg+3 > narg) error->all(FLERR,"Illegal fix langevin command");
|
2006-09-28 03:51:33 +08:00
|
|
|
int itype = atoi(arg[iarg+1]);
|
|
|
|
double scale = atof(arg[iarg+2]);
|
|
|
|
if (itype <= 0 || itype > atom->ntypes)
|
2012-06-07 06:47:51 +08:00
|
|
|
error->all(FLERR,"Illegal fix langevin command");
|
2006-09-28 03:51:33 +08:00
|
|
|
ratio[itype] = scale;
|
|
|
|
iarg += 3;
|
2009-08-09 06:58:52 +08:00
|
|
|
} else if (strcmp(arg[iarg],"tally") == 0) {
|
2011-09-24 02:06:55 +08:00
|
|
|
if (iarg+2 > narg) error->all(FLERR,"Illegal fix langevin command");
|
2013-06-07 02:10:38 +08:00
|
|
|
if (strcmp(arg[iarg+1],"no") == 0) tallyflag = 0;
|
|
|
|
else if (strcmp(arg[iarg+1],"yes") == 0) tallyflag = 1;
|
2011-09-24 02:06:55 +08:00
|
|
|
else error->all(FLERR,"Illegal fix langevin command");
|
2009-08-09 06:58:52 +08:00
|
|
|
iarg += 2;
|
2011-03-28 22:43:00 +08:00
|
|
|
} else if (strcmp(arg[iarg],"zero") == 0) {
|
2011-09-24 02:06:55 +08:00
|
|
|
if (iarg+2 > narg) error->all(FLERR,"Illegal fix langevin command");
|
2011-03-28 22:43:00 +08:00
|
|
|
if (strcmp(arg[iarg+1],"no") == 0) zeroflag = 0;
|
|
|
|
else if (strcmp(arg[iarg+1],"yes") == 0) zeroflag = 1;
|
2011-09-24 02:06:55 +08:00
|
|
|
else error->all(FLERR,"Illegal fix langevin command");
|
2011-03-28 07:34:04 +08:00
|
|
|
iarg += 2;
|
2011-09-24 02:06:55 +08:00
|
|
|
} else error->all(FLERR,"Illegal fix langevin command");
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
2008-03-12 01:15:30 +08:00
|
|
|
|
|
|
|
// set temperature = NULL, user can override via fix_modify if wants bias
|
|
|
|
|
|
|
|
id_temp = NULL;
|
|
|
|
temperature = NULL;
|
2009-08-09 06:58:52 +08:00
|
|
|
|
2010-09-28 00:48:24 +08:00
|
|
|
// flangevin is unallocated until first call to setup()
|
|
|
|
// compute_scalar checks for this and returns 0.0 if flangevin is NULL
|
|
|
|
|
2009-08-09 06:58:52 +08:00
|
|
|
energy = 0.0;
|
2011-11-29 06:41:16 +08:00
|
|
|
flangevin = NULL;
|
2013-06-07 02:10:38 +08:00
|
|
|
franprev = NULL;
|
2011-11-29 06:41:16 +08:00
|
|
|
tforce = NULL;
|
|
|
|
maxatom1 = maxatom2 = 0;
|
2013-06-07 02:10:38 +08:00
|
|
|
|
|
|
|
// Setup atom-based array for franprev
|
|
|
|
// register with Atom class
|
|
|
|
// No need to set peratom_flag
|
|
|
|
// as this data is for internal use only
|
|
|
|
|
|
|
|
if (gjfflag) {
|
|
|
|
nvalues = 3;
|
2013-06-07 04:18:08 +08:00
|
|
|
grow_arrays(atom->nmax);
|
2013-06-07 02:10:38 +08:00
|
|
|
atom->add_callback(0);
|
|
|
|
|
|
|
|
// initialize franprev to zero
|
|
|
|
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
franprev[i][0] = 0.0;
|
|
|
|
franprev[i][1] = 0.0;
|
|
|
|
franprev[i][2] = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
FixLangevin::~FixLangevin()
|
|
|
|
{
|
|
|
|
delete random;
|
2011-11-29 06:41:16 +08:00
|
|
|
delete [] tstr;
|
2006-09-28 03:51:33 +08:00
|
|
|
delete [] gfactor1;
|
|
|
|
delete [] gfactor2;
|
|
|
|
delete [] ratio;
|
2008-03-12 01:15:30 +08:00
|
|
|
delete [] id_temp;
|
2011-03-26 05:13:51 +08:00
|
|
|
memory->destroy(flangevin);
|
2011-11-29 06:41:16 +08:00
|
|
|
memory->destroy(tforce);
|
2013-06-07 02:10:38 +08:00
|
|
|
|
|
|
|
if (gjfflag) {
|
|
|
|
memory->destroy(franprev);
|
|
|
|
atom->delete_callback(id,0);
|
|
|
|
}
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int FixLangevin::setmask()
|
|
|
|
{
|
|
|
|
int mask = 0;
|
|
|
|
mask |= POST_FORCE;
|
|
|
|
mask |= POST_FORCE_RESPA;
|
2013-06-07 02:10:38 +08:00
|
|
|
mask |= POST_INTEGRATE;
|
2009-08-09 06:58:52 +08:00
|
|
|
mask |= END_OF_STEP;
|
|
|
|
mask |= THERMO_ENERGY;
|
2006-09-28 03:51:33 +08:00
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixLangevin::init()
|
|
|
|
{
|
2011-04-29 23:52:26 +08:00
|
|
|
if (oflag && !atom->sphere_flag)
|
2012-02-13 23:33:29 +08:00
|
|
|
error->all(FLERR,"Fix langevin omega requires atom style sphere");
|
2013-04-24 05:57:35 +08:00
|
|
|
if (ascale && !atom->ellipsoid_flag)
|
2012-02-13 23:33:29 +08:00
|
|
|
error->all(FLERR,"Fix langevin angmom requires atom style ellipsoid");
|
2011-04-29 23:52:26 +08:00
|
|
|
|
2011-11-29 06:41:16 +08:00
|
|
|
// check variable
|
|
|
|
|
|
|
|
if (tstr) {
|
|
|
|
tvar = input->variable->find(tstr);
|
2012-06-07 06:47:51 +08:00
|
|
|
if (tvar < 0)
|
2011-11-29 06:41:16 +08:00
|
|
|
error->all(FLERR,"Variable name for fix langevin does not exist");
|
|
|
|
if (input->variable->equalstyle(tvar)) tstyle = EQUAL;
|
|
|
|
else if (input->variable->atomstyle(tvar)) tstyle = ATOM;
|
|
|
|
else error->all(FLERR,"Variable for fix langevin is invalid style");
|
|
|
|
}
|
|
|
|
|
2013-04-24 05:57:35 +08:00
|
|
|
// if oflag or ascale set, check that all group particles are finite-size
|
2011-04-29 23:52:26 +08:00
|
|
|
|
|
|
|
if (oflag) {
|
|
|
|
double *radius = atom->radius;
|
|
|
|
int *mask = atom->mask;
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
|
|
|
|
for (int i = 0; i < nlocal; i++)
|
|
|
|
if (mask[i] & groupbit)
|
2012-06-07 06:47:51 +08:00
|
|
|
if (radius[i] == 0.0)
|
|
|
|
error->one(FLERR,"Fix langevin omega requires extended particles");
|
2011-04-29 23:52:26 +08:00
|
|
|
}
|
|
|
|
|
2013-04-24 05:57:35 +08:00
|
|
|
if (ascale) {
|
2013-01-14 23:56:34 +08:00
|
|
|
avec = (AtomVecEllipsoid *) atom->style_match("ellipsoid");
|
|
|
|
if (!avec)
|
|
|
|
error->all(FLERR,"Fix langevin angmom requires atom style ellipsoid");
|
|
|
|
|
2011-04-29 23:52:26 +08:00
|
|
|
int *ellipsoid = atom->ellipsoid;
|
|
|
|
int *mask = atom->mask;
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
|
|
|
|
for (int i = 0; i < nlocal; i++)
|
|
|
|
if (mask[i] & groupbit)
|
2012-06-07 06:47:51 +08:00
|
|
|
if (ellipsoid[i] < 0)
|
|
|
|
error->one(FLERR,"Fix langevin angmom requires extended particles");
|
2011-04-29 23:52:26 +08:00
|
|
|
}
|
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
// set force prefactors
|
|
|
|
|
2009-08-09 06:58:52 +08:00
|
|
|
if (!atom->rmass) {
|
2008-03-20 00:02:28 +08:00
|
|
|
for (int i = 1; i <= atom->ntypes; i++) {
|
|
|
|
gfactor1[i] = -atom->mass[i] / t_period / force->ftm2v;
|
2012-06-07 06:47:51 +08:00
|
|
|
gfactor2[i] = sqrt(atom->mass[i]) *
|
|
|
|
sqrt(24.0*force->boltz/t_period/update->dt/force->mvv2e) /
|
|
|
|
force->ftm2v;
|
2008-03-20 00:02:28 +08:00
|
|
|
gfactor1[i] *= 1.0/ratio[i];
|
|
|
|
gfactor2[i] *= 1.0/sqrt(ratio[i]);
|
|
|
|
}
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
if (temperature && temperature->tempbias) tbiasflag = BIAS;
|
|
|
|
else tbiasflag = NOBIAS;
|
2008-03-12 01:15:30 +08:00
|
|
|
|
2011-06-21 00:42:39 +08:00
|
|
|
if (strstr(update->integrate_style,"respa"))
|
2006-09-28 03:51:33 +08:00
|
|
|
nlevels_respa = ((Respa *) update->integrate)->nlevels;
|
2013-06-07 02:10:38 +08:00
|
|
|
|
|
|
|
if (gjfflag) gjffac = 1.0/(1.0+update->dt/2.0/t_period);
|
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2008-01-10 05:56:57 +08:00
|
|
|
void FixLangevin::setup(int vflag)
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
2011-06-21 00:42:39 +08:00
|
|
|
if (strstr(update->integrate_style,"verlet"))
|
2008-01-10 05:56:57 +08:00
|
|
|
post_force(vflag);
|
2006-09-28 03:51:33 +08:00
|
|
|
else {
|
|
|
|
((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1);
|
2008-01-10 05:56:57 +08:00
|
|
|
post_force_respa(vflag,nlevels_respa-1,0);
|
2006-09-28 03:51:33 +08:00
|
|
|
((Respa *) update->integrate)->copy_f_flevel(nlevels_respa-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixLangevin::post_force(int vflag)
|
2009-08-09 06:58:52 +08:00
|
|
|
{
|
2013-06-07 02:10:38 +08:00
|
|
|
double *rmass = atom->rmass;
|
|
|
|
|
|
|
|
// enumerate all 2^6 possibilities for template parameters
|
|
|
|
// this avoids testing them inside inner loop:
|
|
|
|
// TSTYLEATOM, GJF, TALLY, BIAS, RMASS, ZERO
|
|
|
|
|
|
|
|
#ifdef TEMPLATED_FIX_LANGEVIN
|
|
|
|
if (tstyle == ATOM)
|
|
|
|
if (gjfflag)
|
|
|
|
if (tallyflag)
|
|
|
|
if (tbiasflag == BIAS)
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<1,1,1,1,1,1>();
|
2013-06-07 04:18:08 +08:00
|
|
|
else post_force_templated<1,1,1,1,1,0>();
|
2013-06-07 02:10:38 +08:00
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<1,1,1,1,0,1>();
|
2013-06-07 04:18:08 +08:00
|
|
|
else post_force_templated<1,1,1,1,0,0>();
|
2013-06-07 02:10:38 +08:00
|
|
|
else
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<1,1,1,0,1,1>();
|
|
|
|
else post_force_templated<1,1,1,0,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<1,1,1,0,0,1>();
|
|
|
|
else post_force_templated<1,1,1,0,0,0>();
|
|
|
|
else
|
|
|
|
if (tbiasflag == BIAS)
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<1,1,0,1,1,1>();
|
|
|
|
else post_force_templated<1,1,0,1,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<1,1,0,1,0,1>();
|
|
|
|
else post_force_templated<1,1,0,1,0,0>();
|
|
|
|
else
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<1,1,0,0,1,1>();
|
|
|
|
else post_force_templated<1,1,0,0,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<1,1,0,0,0,1>();
|
|
|
|
else post_force_templated<1,1,0,0,0,0>();
|
|
|
|
else
|
|
|
|
if (tallyflag)
|
|
|
|
if (tbiasflag == BIAS)
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<1,0,1,1,1,1>();
|
|
|
|
else post_force_templated<1,0,1,1,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<1,0,1,1,0,1>();
|
|
|
|
else post_force_templated<1,0,1,1,0,0>();
|
|
|
|
else
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<1,0,1,0,1,1>();
|
|
|
|
else post_force_templated<1,0,1,0,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<1,0,1,0,0,1>();
|
|
|
|
else post_force_templated<1,0,1,0,0,0>();
|
|
|
|
else
|
|
|
|
if (tbiasflag == BIAS)
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<1,0,0,1,1,1>();
|
|
|
|
else post_force_templated<1,0,0,1,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<1,0,0,1,0,1>();
|
|
|
|
else post_force_templated<1,0,0,1,0,0>();
|
|
|
|
else
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<1,0,0,0,1,1>();
|
|
|
|
else post_force_templated<1,0,0,0,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<1,0,0,0,0,1>();
|
|
|
|
else post_force_templated<1,0,0,0,0,0>();
|
|
|
|
else
|
|
|
|
if (gjfflag)
|
|
|
|
if (tallyflag)
|
|
|
|
if (tbiasflag == BIAS)
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<0,1,1,1,1,1>();
|
|
|
|
else post_force_templated<0,1,1,1,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<0,1,1,1,0,1>();
|
|
|
|
else post_force_templated<0,1,1,1,0,0>();
|
|
|
|
else
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<0,1,1,0,1,1>();
|
|
|
|
else post_force_templated<0,1,1,0,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<0,1,1,0,0,1>();
|
|
|
|
else post_force_templated<0,1,1,0,0,0>();
|
|
|
|
else
|
|
|
|
if (tbiasflag == BIAS)
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<0,1,0,1,1,1>();
|
|
|
|
else post_force_templated<0,1,0,1,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<0,1,0,1,0,1>();
|
|
|
|
else post_force_templated<0,1,0,1,0,0>();
|
|
|
|
else
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<0,1,0,0,1,1>();
|
|
|
|
else post_force_templated<0,1,0,0,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<0,1,0,0,0,1>();
|
|
|
|
else post_force_templated<0,1,0,0,0,0>();
|
|
|
|
else
|
|
|
|
if (tallyflag)
|
|
|
|
if (tbiasflag == BIAS)
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<0,0,1,1,1,1>();
|
|
|
|
else post_force_templated<0,0,1,1,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<0,0,1,1,0,1>();
|
|
|
|
else post_force_templated<0,0,1,1,0,0>();
|
|
|
|
else
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<0,0,1,0,1,1>();
|
|
|
|
else post_force_templated<0,0,1,0,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<0,0,1,0,0,1>();
|
|
|
|
else post_force_templated<0,0,1,0,0,0>();
|
|
|
|
else
|
|
|
|
if (tbiasflag == BIAS)
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<0,0,0,1,1,1>();
|
|
|
|
else post_force_templated<0,0,0,1,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<0,0,0,1,0,1>();
|
|
|
|
else post_force_templated<0,0,0,1,0,0>();
|
|
|
|
else
|
|
|
|
if (rmass)
|
|
|
|
if (zeroflag) post_force_templated<0,0,0,0,1,1>();
|
|
|
|
else post_force_templated<0,0,0,0,1,0>();
|
|
|
|
else
|
|
|
|
if (zeroflag) post_force_templated<0,0,0,0,0,1>();
|
|
|
|
else post_force_templated<0,0,0,0,0,0>();
|
|
|
|
#else
|
|
|
|
post_force_untemplated(int(tstyle==ATOM), gjfflag, tallyflag,
|
|
|
|
int(tbiasflag==BIAS), int(rmass!=NULL), zeroflag);
|
|
|
|
#endif
|
2009-08-09 06:58:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixLangevin::post_force_respa(int vflag, int ilevel, int iloop)
|
|
|
|
{
|
|
|
|
if (ilevel == nlevels_respa-1) post_force(vflag);
|
|
|
|
}
|
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
modify forces using one of the many Langevin styles
|
|
|
|
------------------------------------------------------------------------- */
|
2009-08-09 06:58:52 +08:00
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
#ifdef TEMPLATED_FIX_LANGEVIN
|
|
|
|
template < int Tp_TSTYLEATOM, int Tp_GJF, int Tp_TALLY,
|
|
|
|
int Tp_BIAS, int Tp_RMASS, int Tp_ZERO >
|
|
|
|
void FixLangevin::post_force_templated()
|
|
|
|
#else
|
2013-06-14 03:08:12 +08:00
|
|
|
void FixLangevin::post_force_untemplated
|
|
|
|
(int Tp_TSTYLEATOM, int Tp_GJF, int Tp_TALLY,
|
|
|
|
int Tp_BIAS, int Tp_RMASS, int Tp_ZERO)
|
2013-06-07 02:10:38 +08:00
|
|
|
#endif
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
2012-05-24 00:24:30 +08:00
|
|
|
double gamma1,gamma2;
|
2008-03-12 01:15:30 +08:00
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
double **v = atom->v;
|
|
|
|
double **f = atom->f;
|
2009-08-09 06:58:52 +08:00
|
|
|
double *rmass = atom->rmass;
|
2006-09-28 03:51:33 +08:00
|
|
|
int *type = atom->type;
|
|
|
|
int *mask = atom->mask;
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
|
2009-11-18 05:18:23 +08:00
|
|
|
// apply damping and thermostat to atoms in group
|
2013-06-07 02:10:38 +08:00
|
|
|
|
|
|
|
// for Tp_TSTYLEATOM:
|
|
|
|
// use per-atom per-coord target temperature
|
|
|
|
// for Tp_GJF:
|
|
|
|
// use Gronbech-Jensen/Farago algorithm
|
|
|
|
// else use regular algorithm
|
|
|
|
// for Tp_TALLY:
|
|
|
|
// store drag plus random forces in flangevin[nlocal][3]
|
|
|
|
// for Tp_BIAS:
|
2009-11-18 05:18:23 +08:00
|
|
|
// calculate temperature since some computes require temp
|
|
|
|
// computed on current nlocal atoms to remove bias
|
|
|
|
// test v = 0 since some computes mask non-participating atoms via v = 0
|
|
|
|
// and added force has extra term not multiplied by v = 0
|
2013-06-07 02:10:38 +08:00
|
|
|
// for Tp_RMASS:
|
|
|
|
// use per-atom masses
|
|
|
|
// else use per-type masses
|
|
|
|
// for Tp_ZERO:
|
2011-03-28 22:43:00 +08:00
|
|
|
// sum random force over all atoms in group
|
2012-06-07 06:47:51 +08:00
|
|
|
// subtract sum/count from each atom in group
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
double fdrag[3],fran[3],fsum[3],fsumall[3];
|
2011-03-28 07:34:04 +08:00
|
|
|
bigint count;
|
2013-06-07 02:10:38 +08:00
|
|
|
double fswap;
|
2011-04-29 23:52:26 +08:00
|
|
|
|
|
|
|
double boltz = force->boltz;
|
|
|
|
double dt = update->dt;
|
|
|
|
double mvv2e = force->mvv2e;
|
|
|
|
double ftm2v = force->ftm2v;
|
2012-06-07 06:47:51 +08:00
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
compute_target();
|
|
|
|
|
|
|
|
if (Tp_ZERO) {
|
|
|
|
fsum[0] = fsum[1] = fsum[2] = 0.0;
|
2011-03-28 07:34:04 +08:00
|
|
|
count = group->count(igroup);
|
|
|
|
if (count == 0)
|
2011-09-24 02:06:55 +08:00
|
|
|
error->all(FLERR,"Cannot zero Langevin force of 0 atoms");
|
2011-03-28 07:34:04 +08:00
|
|
|
}
|
2012-06-07 06:47:51 +08:00
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
// reallocate flangevin if necessary
|
|
|
|
|
|
|
|
if (Tp_TALLY) {
|
|
|
|
if (atom->nlocal > maxatom1) {
|
|
|
|
memory->destroy(flangevin);
|
|
|
|
maxatom1 = atom->nmax;
|
|
|
|
memory->create(flangevin,maxatom1,3,"langevin:flangevin");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 22:41:46 +08:00
|
|
|
if (Tp_BIAS) temperature->compute_scalar();
|
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
if (mask[i] & groupbit) {
|
|
|
|
if (Tp_TSTYLEATOM) tsqrt = sqrt(tforce[i]);
|
|
|
|
if (Tp_RMASS) {
|
|
|
|
gamma1 = -rmass[i] / t_period / ftm2v;
|
|
|
|
gamma2 = sqrt(rmass[i]) * sqrt(24.0*boltz/t_period/dt/mvv2e) / ftm2v;
|
|
|
|
gamma1 *= 1.0/ratio[type[i]];
|
|
|
|
gamma2 *= 1.0/sqrt(ratio[type[i]]) * tsqrt;
|
|
|
|
} else {
|
|
|
|
gamma1 = gfactor1[type[i]];
|
|
|
|
gamma2 = gfactor2[type[i]] * tsqrt;
|
2009-08-09 06:58:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
fran[0] = gamma2*(random->uniform()-0.5);
|
|
|
|
fran[1] = gamma2*(random->uniform()-0.5);
|
|
|
|
fran[2] = gamma2*(random->uniform()-0.5);
|
|
|
|
|
|
|
|
if (Tp_BIAS) {
|
|
|
|
temperature->remove_bias(i,v[i]);
|
|
|
|
fdrag[1] = gamma1*v[i][1];
|
|
|
|
fdrag[2] = gamma1*v[i][2];
|
|
|
|
fdrag[0] = gamma1*v[i][0];
|
|
|
|
if (v[i][0] != 0.0) f[i][0] += fdrag[0] + fran[0];
|
|
|
|
else fran[0] = 0.0;
|
|
|
|
if (v[i][1] != 0.0) f[i][1] += fdrag[1] + fran[1];
|
|
|
|
else fran[1] = 0.0;
|
|
|
|
if (v[i][2] != 0.0) f[i][2] += fdrag[2] + fran[2];
|
|
|
|
else fran[2] = 0.0;
|
|
|
|
temperature->restore_bias(i,v[i]);
|
|
|
|
} else {
|
|
|
|
fdrag[0] = gamma1*v[i][0];
|
|
|
|
fdrag[1] = gamma1*v[i][1];
|
|
|
|
fdrag[2] = gamma1*v[i][2];
|
2009-08-09 06:58:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
if (Tp_GJF) {
|
|
|
|
fswap = 0.5*(fran[0]+franprev[i][0]);
|
|
|
|
franprev[i][0] = fran[0];
|
|
|
|
fran[0] = fswap;
|
|
|
|
fswap = 0.5*(fran[1]+franprev[i][1]);
|
|
|
|
franprev[i][1] = fran[1];
|
|
|
|
fran[1] = fswap;
|
|
|
|
fswap = 0.5*(fran[2]+franprev[i][2]);
|
|
|
|
franprev[i][2] = fran[2];
|
|
|
|
fran[2] = fswap;
|
|
|
|
|
|
|
|
fdrag[0] *= gjffac;
|
|
|
|
fdrag[1] *= gjffac;
|
|
|
|
fdrag[2] *= gjffac;
|
|
|
|
fran[0] *= gjffac;
|
|
|
|
fran[1] *= gjffac;
|
|
|
|
fran[2] *= gjffac;
|
|
|
|
f[i][0] *= gjffac;
|
|
|
|
f[i][1] *= gjffac;
|
|
|
|
f[i][2] *= gjffac;
|
|
|
|
}
|
2012-06-07 06:47:51 +08:00
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
f[i][0] += fdrag[0] + fran[0];
|
|
|
|
f[i][1] += fdrag[1] + fran[1];
|
|
|
|
f[i][2] += fdrag[2] + fran[2];
|
|
|
|
|
|
|
|
if (Tp_TALLY) {
|
|
|
|
flangevin[i][0] = fdrag[0] + fran[0];
|
|
|
|
flangevin[i][1] = fdrag[1] + fran[1];
|
|
|
|
flangevin[i][2] = fdrag[2] + fran[2];
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
if (Tp_ZERO) {
|
|
|
|
fsum[0] += fran[0];
|
|
|
|
fsum[1] += fran[1];
|
|
|
|
fsum[2] += fran[2];
|
2008-03-20 00:02:28 +08:00
|
|
|
}
|
|
|
|
}
|
2009-08-09 06:58:52 +08:00
|
|
|
}
|
2011-03-28 07:34:04 +08:00
|
|
|
|
2011-03-28 22:43:00 +08:00
|
|
|
// set total force to zero
|
2011-03-28 07:34:04 +08:00
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
if (Tp_ZERO) {
|
2011-03-28 07:34:04 +08:00
|
|
|
MPI_Allreduce(fsum,fsumall,3,MPI_DOUBLE,MPI_SUM,world);
|
|
|
|
fsumall[0] /= count;
|
|
|
|
fsumall[1] /= count;
|
|
|
|
fsumall[2] /= count;
|
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
if (mask[i] & groupbit) {
|
2012-06-07 06:47:51 +08:00
|
|
|
f[i][0] -= fsumall[0];
|
|
|
|
f[i][1] -= fsumall[1];
|
|
|
|
f[i][2] -= fsumall[2];
|
2011-03-28 07:34:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-29 23:52:26 +08:00
|
|
|
|
|
|
|
// thermostat omega and angmom
|
|
|
|
|
2011-11-29 06:41:16 +08:00
|
|
|
if (oflag) omega_thermostat();
|
2013-04-24 05:57:35 +08:00
|
|
|
if (ascale) angmom_thermostat();
|
2009-08-09 06:58:52 +08:00
|
|
|
}
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
set current t_target and t_sqrt
|
|
|
|
------------------------------------------------------------------------- */
|
2009-08-09 06:58:52 +08:00
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
void FixLangevin::compute_target()
|
2009-08-09 06:58:52 +08:00
|
|
|
{
|
|
|
|
int *mask = atom->mask;
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
|
|
|
|
double delta = update->ntimestep - update->beginstep;
|
2013-01-12 00:50:56 +08:00
|
|
|
if (delta != 0.0) delta /= update->endstep - update->beginstep;
|
2011-11-29 06:41:16 +08:00
|
|
|
|
|
|
|
// if variable temp, evaluate variable, wrap with clear/add
|
|
|
|
// reallocate tforce array if necessary
|
|
|
|
|
|
|
|
if (tstyle == CONSTANT) {
|
|
|
|
t_target = t_start + delta * (t_stop-t_start);
|
|
|
|
tsqrt = sqrt(t_target);
|
|
|
|
} else {
|
|
|
|
modify->clearstep_compute();
|
|
|
|
if (tstyle == EQUAL) {
|
|
|
|
t_target = input->variable->compute_equal(tvar);
|
|
|
|
if (t_target < 0.0)
|
2012-06-07 06:47:51 +08:00
|
|
|
error->one(FLERR,"Fix langevin variable returned negative temperature");
|
2011-11-29 06:41:16 +08:00
|
|
|
tsqrt = sqrt(t_target);
|
|
|
|
} else {
|
|
|
|
if (nlocal > maxatom2) {
|
2012-06-07 06:47:51 +08:00
|
|
|
maxatom2 = atom->nmax;
|
|
|
|
memory->destroy(tforce);
|
|
|
|
memory->create(tforce,maxatom2,"langevin:tforce");
|
2011-11-29 06:41:16 +08:00
|
|
|
}
|
|
|
|
input->variable->compute_atom(tvar,igroup,tforce,1,0);
|
|
|
|
for (int i = 0; i < nlocal; i++)
|
2012-06-07 06:47:51 +08:00
|
|
|
if (mask[i] & groupbit)
|
|
|
|
if (tforce[i] < 0.0)
|
|
|
|
error->one(FLERR,
|
|
|
|
"Fix langevin variable returned negative temperature");
|
2011-11-29 06:41:16 +08:00
|
|
|
}
|
|
|
|
modify->addstep_compute(update->ntimestep + 1);
|
|
|
|
}
|
2011-04-29 23:52:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
thermostat rotational dof via omega
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2011-11-29 06:41:16 +08:00
|
|
|
void FixLangevin::omega_thermostat()
|
2011-04-29 23:52:26 +08:00
|
|
|
{
|
|
|
|
double gamma1,gamma2;
|
|
|
|
|
|
|
|
double boltz = force->boltz;
|
|
|
|
double dt = update->dt;
|
|
|
|
double mvv2e = force->mvv2e;
|
|
|
|
double ftm2v = force->ftm2v;
|
|
|
|
|
|
|
|
double **torque = atom->torque;
|
|
|
|
double **omega = atom->omega;
|
|
|
|
double *radius = atom->radius;
|
|
|
|
double *rmass = atom->rmass;
|
|
|
|
int *mask = atom->mask;
|
|
|
|
int *type = atom->type;
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
|
2013-04-24 05:57:35 +08:00
|
|
|
// rescale gamma1/gamma2 by 10/3 & sqrt(10/3) for spherical particles
|
|
|
|
// does not affect rotational thermosatting
|
|
|
|
// gives correct rotational diffusivity behavior
|
2013-01-26 06:38:26 +08:00
|
|
|
|
|
|
|
double tendivthree = 10.0/3.0;
|
2011-04-29 23:52:26 +08:00
|
|
|
double tran[3];
|
|
|
|
double inertiaone;
|
2013-01-26 06:38:26 +08:00
|
|
|
|
2011-04-29 23:52:26 +08:00
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
if (mask[i] & groupbit) {
|
|
|
|
inertiaone = SINERTIA*radius[i]*radius[i]*rmass[i];
|
2011-11-29 06:41:16 +08:00
|
|
|
if (tstyle == ATOM) tsqrt = sqrt(tforce[i]);
|
2013-01-26 06:38:26 +08:00
|
|
|
gamma1 = -tendivthree*inertiaone / t_period / ftm2v;
|
|
|
|
gamma2 = sqrt(inertiaone) * sqrt(80.0*boltz/t_period/dt/mvv2e) / ftm2v;
|
2011-04-29 23:52:26 +08:00
|
|
|
gamma1 *= 1.0/ratio[type[i]];
|
|
|
|
gamma2 *= 1.0/sqrt(ratio[type[i]]) * tsqrt;
|
|
|
|
tran[0] = gamma2*(random->uniform()-0.5);
|
|
|
|
tran[1] = gamma2*(random->uniform()-0.5);
|
|
|
|
tran[2] = gamma2*(random->uniform()-0.5);
|
|
|
|
torque[i][0] += gamma1*omega[i][0] + tran[0];
|
|
|
|
torque[i][1] += gamma1*omega[i][1] + tran[1];
|
|
|
|
torque[i][2] += gamma1*omega[i][2] + tran[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
thermostat rotational dof via angmom
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2011-11-29 06:41:16 +08:00
|
|
|
void FixLangevin::angmom_thermostat()
|
2011-04-29 23:52:26 +08:00
|
|
|
{
|
|
|
|
double gamma1,gamma2;
|
|
|
|
|
|
|
|
double boltz = force->boltz;
|
|
|
|
double dt = update->dt;
|
|
|
|
double mvv2e = force->mvv2e;
|
|
|
|
double ftm2v = force->ftm2v;
|
|
|
|
|
|
|
|
AtomVecEllipsoid::Bonus *bonus = avec->bonus;
|
|
|
|
double **torque = atom->torque;
|
|
|
|
double **angmom = atom->angmom;
|
|
|
|
double *rmass = atom->rmass;
|
|
|
|
int *ellipsoid = atom->ellipsoid;
|
|
|
|
int *mask = atom->mask;
|
|
|
|
int *type = atom->type;
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
|
2013-04-24 05:57:35 +08:00
|
|
|
// rescale gamma1/gamma2 by ascale for aspherical particles
|
|
|
|
// does not affect rotational thermosatting
|
|
|
|
// gives correct rotational diffusivity behavior if (nearly) spherical
|
|
|
|
// any value will be incorrect for rotational diffusivity if aspherical
|
2013-01-26 06:38:26 +08:00
|
|
|
|
2011-07-01 04:10:18 +08:00
|
|
|
double inertia[3],omega[3],tran[3];
|
2011-04-29 23:52:26 +08:00
|
|
|
double *shape,*quat;
|
|
|
|
|
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
if (mask[i] & groupbit) {
|
|
|
|
shape = bonus[ellipsoid[i]].shape;
|
|
|
|
inertia[0] = EINERTIA*rmass[i] * (shape[1]*shape[1]+shape[2]*shape[2]);
|
|
|
|
inertia[1] = EINERTIA*rmass[i] * (shape[0]*shape[0]+shape[2]*shape[2]);
|
|
|
|
inertia[2] = EINERTIA*rmass[i] * (shape[0]*shape[0]+shape[1]*shape[1]);
|
|
|
|
quat = bonus[ellipsoid[i]].quat;
|
|
|
|
MathExtra::mq_to_omega(angmom[i],quat,inertia,omega);
|
2012-06-07 06:47:51 +08:00
|
|
|
|
2011-11-29 06:41:16 +08:00
|
|
|
if (tstyle == ATOM) tsqrt = sqrt(tforce[i]);
|
2013-04-24 05:57:35 +08:00
|
|
|
gamma1 = -ascale / t_period / ftm2v;
|
|
|
|
gamma2 = sqrt(ascale*24.0*boltz/t_period/dt/mvv2e) / ftm2v;
|
2011-04-29 23:52:26 +08:00
|
|
|
gamma1 *= 1.0/ratio[type[i]];
|
|
|
|
gamma2 *= 1.0/sqrt(ratio[type[i]]) * tsqrt;
|
|
|
|
tran[0] = sqrt(inertia[0])*gamma2*(random->uniform()-0.5);
|
|
|
|
tran[1] = sqrt(inertia[1])*gamma2*(random->uniform()-0.5);
|
|
|
|
tran[2] = sqrt(inertia[2])*gamma2*(random->uniform()-0.5);
|
|
|
|
torque[i][0] += inertia[0]*gamma1*omega[0] + tran[0];
|
|
|
|
torque[i][1] += inertia[1]*gamma1*omega[1] + tran[1];
|
|
|
|
torque[i][2] += inertia[2]*gamma1*omega[2] + tran[2];
|
|
|
|
}
|
|
|
|
}
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
2009-08-09 06:58:52 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
tally energy transfer to thermal reservoir
|
|
|
|
------------------------------------------------------------------------- */
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2009-08-09 06:58:52 +08:00
|
|
|
void FixLangevin::end_of_step()
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
2013-06-07 02:10:38 +08:00
|
|
|
if (!tallyflag) return;
|
2009-08-09 06:58:52 +08:00
|
|
|
|
|
|
|
double **v = atom->v;
|
|
|
|
int *mask = atom->mask;
|
2012-06-07 06:47:51 +08:00
|
|
|
int nlocal = atom->nlocal;
|
2009-08-09 06:58:52 +08:00
|
|
|
|
|
|
|
energy_onestep = 0.0;
|
2012-06-07 06:47:51 +08:00
|
|
|
|
2009-08-09 06:58:52 +08:00
|
|
|
for (int i = 0; i < nlocal; i++)
|
|
|
|
if (mask[i] & groupbit)
|
2012-06-07 06:47:51 +08:00
|
|
|
energy_onestep += flangevin[i][0]*v[i][0] + flangevin[i][1]*v[i][1] +
|
|
|
|
flangevin[i][2]*v[i][2];
|
2009-08-09 06:58:52 +08:00
|
|
|
|
|
|
|
energy += energy_onestep*update->dt;
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixLangevin::reset_target(double t_new)
|
|
|
|
{
|
2012-05-24 00:24:30 +08:00
|
|
|
t_target = t_start = t_stop = t_new;
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
2007-12-19 00:42:57 +08:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixLangevin::reset_dt()
|
|
|
|
{
|
2008-03-20 00:02:28 +08:00
|
|
|
if (atom->mass) {
|
|
|
|
for (int i = 1; i <= atom->ntypes; i++) {
|
2012-06-07 06:47:51 +08:00
|
|
|
gfactor2[i] = sqrt(atom->mass[i]) *
|
|
|
|
sqrt(24.0*force->boltz/t_period/update->dt/force->mvv2e) /
|
|
|
|
force->ftm2v;
|
2008-03-20 00:02:28 +08:00
|
|
|
gfactor2[i] *= 1.0/sqrt(ratio[i]);
|
|
|
|
}
|
2007-12-19 00:42:57 +08:00
|
|
|
}
|
|
|
|
}
|
2008-03-12 01:15:30 +08:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int FixLangevin::modify_param(int narg, char **arg)
|
|
|
|
{
|
|
|
|
if (strcmp(arg[0],"temp") == 0) {
|
2011-09-24 02:06:55 +08:00
|
|
|
if (narg < 2) error->all(FLERR,"Illegal fix_modify command");
|
2008-03-12 01:15:30 +08:00
|
|
|
delete [] id_temp;
|
|
|
|
int n = strlen(arg[1]) + 1;
|
|
|
|
id_temp = new char[n];
|
|
|
|
strcpy(id_temp,arg[1]);
|
|
|
|
|
|
|
|
int icompute = modify->find_compute(id_temp);
|
2012-06-07 06:47:51 +08:00
|
|
|
if (icompute < 0)
|
2011-11-29 06:41:16 +08:00
|
|
|
error->all(FLERR,"Could not find fix_modify temperature ID");
|
2008-03-12 01:15:30 +08:00
|
|
|
temperature = modify->compute[icompute];
|
|
|
|
|
|
|
|
if (temperature->tempflag == 0)
|
2011-11-29 06:41:16 +08:00
|
|
|
error->all(FLERR,
|
2012-06-07 06:47:51 +08:00
|
|
|
"Fix_modify temperature ID does not compute temperature");
|
2008-03-12 01:15:30 +08:00
|
|
|
if (temperature->igroup != igroup && comm->me == 0)
|
2011-09-24 02:06:55 +08:00
|
|
|
error->warning(FLERR,"Group for fix_modify temp != fix group");
|
2008-03-12 01:15:30 +08:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-09 06:58:52 +08:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
double FixLangevin::compute_scalar()
|
|
|
|
{
|
2013-06-07 02:10:38 +08:00
|
|
|
if (!tallyflag || flangevin == NULL) return 0.0;
|
2009-08-09 06:58:52 +08:00
|
|
|
|
|
|
|
// capture the very first energy transfer to thermal reservoir
|
|
|
|
|
|
|
|
double **v = atom->v;
|
|
|
|
int *mask = atom->mask;
|
2012-06-07 06:47:51 +08:00
|
|
|
int nlocal = atom->nlocal;
|
2009-08-09 06:58:52 +08:00
|
|
|
|
|
|
|
if (update->ntimestep == update->beginstep) {
|
|
|
|
energy_onestep = 0.0;
|
2012-06-07 06:47:51 +08:00
|
|
|
for (int i = 0; i < nlocal; i++)
|
|
|
|
if (mask[i] & groupbit)
|
|
|
|
energy_onestep += flangevin[i][0]*v[i][0] + flangevin[i][1]*v[i][1] +
|
|
|
|
flangevin[i][2]*v[i][2];
|
2009-08-09 06:58:52 +08:00
|
|
|
energy = 0.5*energy_onestep*update->dt;
|
|
|
|
}
|
|
|
|
|
2013-06-07 02:10:38 +08:00
|
|
|
// convert midstep energy back to previous fullstep energy
|
|
|
|
|
2009-08-09 06:58:52 +08:00
|
|
|
double energy_me = energy - 0.5*energy_onestep*update->dt;
|
|
|
|
|
2012-06-07 06:47:51 +08:00
|
|
|
double energy_all;
|
|
|
|
MPI_Allreduce(&energy_me,&energy_all,1,MPI_DOUBLE,MPI_SUM,world);
|
2009-08-09 06:58:52 +08:00
|
|
|
return -energy_all;
|
|
|
|
}
|
|
|
|
|
2012-05-24 00:24:30 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
extract thermostat properties
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void *FixLangevin::extract(const char *str, int &dim)
|
|
|
|
{
|
2012-08-23 22:07:14 +08:00
|
|
|
dim = 0;
|
2012-05-24 00:24:30 +08:00
|
|
|
if (strcmp(str,"t_target") == 0) {
|
|
|
|
return &t_target;
|
2012-06-07 06:47:51 +08:00
|
|
|
}
|
2012-05-24 00:24:30 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-08-09 06:58:52 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
memory usage of tally array
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
double FixLangevin::memory_usage()
|
|
|
|
{
|
2011-11-29 06:41:16 +08:00
|
|
|
double bytes = 0.0;
|
2013-06-07 02:10:38 +08:00
|
|
|
if (gjfflag) bytes += atom->nmax*3 * sizeof(double);
|
|
|
|
if (tallyflag) bytes += atom->nmax*3 * sizeof(double);
|
|
|
|
if (tforce) bytes += atom->nmax * sizeof(double);
|
2009-08-09 06:58:52 +08:00
|
|
|
return bytes;
|
|
|
|
}
|
2013-06-07 02:10:38 +08:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
allocate atom-based array for franprev
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixLangevin::grow_arrays(int nmax)
|
|
|
|
{
|
|
|
|
memory->grow(franprev,nmax,3,"fix_langevin:franprev");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
copy values within local atom-based array
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixLangevin::copy_arrays(int i, int j, int delflag)
|
|
|
|
{
|
|
|
|
for (int m = 0; m < nvalues; m++)
|
2013-06-07 04:18:08 +08:00
|
|
|
franprev[j][m] = franprev[i][m];
|
2013-06-07 02:10:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
pack values in local atom-based array for exchange with another proc
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int FixLangevin::pack_exchange(int i, double *buf)
|
|
|
|
{
|
2013-06-07 04:18:08 +08:00
|
|
|
for (int m = 0; m < nvalues; m++) buf[m] = franprev[i][m];
|
2013-06-07 02:10:38 +08:00
|
|
|
return nvalues;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
unpack values in local atom-based array from exchange with another proc
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int FixLangevin::unpack_exchange(int nlocal, double *buf)
|
|
|
|
{
|
2013-06-07 04:18:08 +08:00
|
|
|
for (int m = 0; m < nvalues; m++) franprev[nlocal][m] = buf[m];
|
2013-06-07 02:10:38 +08:00
|
|
|
return nvalues;
|
|
|
|
}
|