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
|
|
|
|
certain rights in this software. This software is distributed under
|
|
|
|
the GNU General Public License.
|
|
|
|
|
|
|
|
See the README file in the top-level LAMMPS directory.
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2009-08-09 06:58:52 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
Contributing author: Carolyn Phillips (U Mich), reservoir energy tally
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
#include "mpi.h"
|
|
|
|
#include "math.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
#include "fix_langevin.h"
|
|
|
|
#include "atom.h"
|
|
|
|
#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"
|
|
|
|
#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"
|
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
using namespace LAMMPS_NS;
|
|
|
|
|
2008-03-12 01:15:30 +08:00
|
|
|
enum{NOBIAS,BIAS};
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (narg < 7) error->all("Illegal fix langevin command");
|
|
|
|
|
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
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
t_start = atof(arg[3]);
|
|
|
|
t_stop = atof(arg[4]);
|
|
|
|
t_period = atof(arg[5]);
|
|
|
|
int seed = atoi(arg[6]);
|
|
|
|
|
|
|
|
if (t_period <= 0.0) error->all("Fix langevin period must be > 0.0");
|
2007-10-10 07:40:36 +08:00
|
|
|
if (seed <= 0) error->all("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];
|
|
|
|
|
|
|
|
// optional args
|
|
|
|
|
|
|
|
for (int i = 1; i <= atom->ntypes; i++) ratio[i] = 1.0;
|
2009-08-09 06:58:52 +08:00
|
|
|
tally = 0;
|
2006-09-28 03:51:33 +08:00
|
|
|
|
|
|
|
int iarg = 7;
|
|
|
|
while (iarg < narg) {
|
2008-03-12 01:15:30 +08:00
|
|
|
if (strcmp(arg[iarg],"scale") == 0) {
|
2006-09-28 03:51:33 +08:00
|
|
|
if (iarg+3 > narg) error->all("Illegal fix langevin command");
|
|
|
|
int itype = atoi(arg[iarg+1]);
|
|
|
|
double scale = atof(arg[iarg+2]);
|
|
|
|
if (itype <= 0 || itype > atom->ntypes)
|
|
|
|
error->all("Illegal fix langevin command");
|
|
|
|
ratio[itype] = scale;
|
|
|
|
iarg += 3;
|
2009-08-09 06:58:52 +08:00
|
|
|
} else if (strcmp(arg[iarg],"tally") == 0) {
|
|
|
|
if (iarg+2 > narg) error->all("Illegal fix langevin command");
|
|
|
|
if (strcmp(arg[iarg+1],"no") == 0) tally = 0;
|
|
|
|
else if (strcmp(arg[iarg+1],"yes") == 0) tally = 1;
|
2010-05-07 01:26:38 +08:00
|
|
|
else error->all("Illegal fix langevin command");
|
2009-08-09 06:58:52 +08:00
|
|
|
iarg += 2;
|
2006-09-28 03:51:33 +08:00
|
|
|
} else error->all("Illegal fix langevin command");
|
|
|
|
}
|
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
|
|
|
flangevin = NULL;
|
|
|
|
nmax = 0;
|
|
|
|
energy = 0.0;
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
FixLangevin::~FixLangevin()
|
|
|
|
{
|
|
|
|
delete random;
|
|
|
|
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);
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int FixLangevin::setmask()
|
|
|
|
{
|
|
|
|
int mask = 0;
|
|
|
|
mask |= POST_FORCE;
|
|
|
|
mask |= POST_FORCE_RESPA;
|
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()
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
gfactor2[i] = sqrt(atom->mass[i]) *
|
|
|
|
sqrt(24.0*force->boltz/t_period/update->dt/force->mvv2e) /
|
|
|
|
force->ftm2v;
|
|
|
|
gfactor1[i] *= 1.0/ratio[i];
|
|
|
|
gfactor2[i] *= 1.0/sqrt(ratio[i]);
|
|
|
|
}
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
2008-03-12 01:15:30 +08:00
|
|
|
if (temperature && temperature->tempbias) which = BIAS;
|
|
|
|
else which = NOBIAS;
|
|
|
|
|
2006-09-28 03:51:33 +08:00
|
|
|
if (strcmp(update->integrate_style,"respa") == 0)
|
|
|
|
nlevels_respa = ((Respa *) update->integrate)->nlevels;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2008-01-10 05:56:57 +08:00
|
|
|
void FixLangevin::setup(int vflag)
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
|
|
|
if (strcmp(update->integrate_style,"verlet") == 0)
|
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
|
|
|
{
|
|
|
|
if (tally) post_force_tally();
|
|
|
|
else post_force_no_tally();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixLangevin::post_force_respa(int vflag, int ilevel, int iloop)
|
|
|
|
{
|
|
|
|
if (ilevel == nlevels_respa-1) post_force(vflag);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixLangevin::post_force_no_tally()
|
2006-09-28 03:51:33 +08:00
|
|
|
{
|
2008-03-12 01:15:30 +08:00
|
|
|
double gamma1,gamma2;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
double delta = update->ntimestep - update->beginstep;
|
|
|
|
delta /= update->endstep - update->beginstep;
|
|
|
|
double t_target = t_start + delta * (t_stop-t_start);
|
|
|
|
double tsqrt = sqrt(t_target);
|
|
|
|
|
2009-11-18 05:18:23 +08:00
|
|
|
// apply damping and thermostat to atoms in group
|
|
|
|
// for BIAS:
|
|
|
|
// 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
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2009-08-09 06:58:52 +08:00
|
|
|
if (rmass) {
|
|
|
|
double boltz = force->boltz;
|
|
|
|
double dt = update->dt;
|
|
|
|
double mvv2e = force->mvv2e;
|
|
|
|
double ftm2v = force->ftm2v;
|
|
|
|
|
|
|
|
if (which == NOBIAS) {
|
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
if (mask[i] & groupbit) {
|
|
|
|
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;
|
|
|
|
f[i][0] += gamma1*v[i][0] + gamma2*(random->uniform()-0.5);
|
|
|
|
f[i][1] += gamma1*v[i][1] + gamma2*(random->uniform()-0.5);
|
|
|
|
f[i][2] += gamma1*v[i][2] + gamma2*(random->uniform()-0.5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (which == BIAS) {
|
|
|
|
double tmp = temperature->compute_scalar();
|
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
if (mask[i] & groupbit) {
|
|
|
|
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;
|
|
|
|
temperature->remove_bias(i,v[i]);
|
|
|
|
if (v[i][0] != 0.0)
|
|
|
|
f[i][0] += gamma1*v[i][0] + gamma2*(random->uniform()-0.5);
|
|
|
|
if (v[i][1] != 0.0)
|
|
|
|
f[i][1] += gamma1*v[i][1] + gamma2*(random->uniform()-0.5);
|
|
|
|
if (v[i][2] != 0.0)
|
|
|
|
f[i][2] += gamma1*v[i][2] + gamma2*(random->uniform()-0.5);
|
|
|
|
temperature->restore_bias(i,v[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2008-03-20 00:02:28 +08:00
|
|
|
if (which == NOBIAS) {
|
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
if (mask[i] & groupbit) {
|
|
|
|
gamma1 = gfactor1[type[i]];
|
|
|
|
gamma2 = gfactor2[type[i]] * tsqrt;
|
|
|
|
f[i][0] += gamma1*v[i][0] + gamma2*(random->uniform()-0.5);
|
|
|
|
f[i][1] += gamma1*v[i][1] + gamma2*(random->uniform()-0.5);
|
|
|
|
f[i][2] += gamma1*v[i][2] + gamma2*(random->uniform()-0.5);
|
|
|
|
}
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
2008-03-20 00:02:28 +08:00
|
|
|
} else if (which == BIAS) {
|
|
|
|
double tmp = temperature->compute_scalar();
|
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
if (mask[i] & groupbit) {
|
|
|
|
gamma1 = gfactor1[type[i]];
|
|
|
|
gamma2 = gfactor2[type[i]] * tsqrt;
|
|
|
|
temperature->remove_bias(i,v[i]);
|
|
|
|
if (v[i][0] != 0.0)
|
|
|
|
f[i][0] += gamma1*v[i][0] + gamma2*(random->uniform()-0.5);
|
|
|
|
if (v[i][1] != 0.0)
|
|
|
|
f[i][1] += gamma1*v[i][1] + gamma2*(random->uniform()-0.5);
|
|
|
|
if (v[i][2] != 0.0)
|
|
|
|
f[i][2] += gamma1*v[i][2] + gamma2*(random->uniform()-0.5);
|
2008-03-20 23:32:33 +08:00
|
|
|
temperature->restore_bias(i,v[i]);
|
2008-03-20 00:02:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-09 06:58:52 +08:00
|
|
|
}
|
|
|
|
}
|
2006-09-28 03:51:33 +08:00
|
|
|
|
2009-08-09 06:58:52 +08:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixLangevin::post_force_tally()
|
|
|
|
{
|
|
|
|
double gamma1,gamma2;
|
|
|
|
|
|
|
|
// reallocate flangevin if necessary
|
|
|
|
|
|
|
|
if (atom->nmax > nmax) {
|
2011-03-26 05:13:51 +08:00
|
|
|
memory->destroy(flangevin);
|
2009-08-09 06:58:52 +08:00
|
|
|
nmax = atom->nmax;
|
2011-03-26 05:13:51 +08:00
|
|
|
memory->create(flangevin,nmax,3,"langevin:flangevin");
|
2009-08-09 06:58:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
double **v = atom->v;
|
|
|
|
double **f = atom->f;
|
|
|
|
double *rmass = atom->rmass;
|
|
|
|
int *type = atom->type;
|
|
|
|
int *mask = atom->mask;
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
|
|
|
|
double delta = update->ntimestep - update->beginstep;
|
|
|
|
delta /= update->endstep - update->beginstep;
|
|
|
|
double t_target = t_start + delta * (t_stop-t_start);
|
|
|
|
double tsqrt = sqrt(t_target);
|
|
|
|
|
|
|
|
// apply damping and thermostat to appropriate atoms
|
2009-11-18 05:18:23 +08:00
|
|
|
// for BIAS:
|
|
|
|
// 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
|
2009-08-09 06:58:52 +08:00
|
|
|
|
|
|
|
if (rmass) {
|
2008-03-20 00:02:28 +08:00
|
|
|
double boltz = force->boltz;
|
|
|
|
double dt = update->dt;
|
|
|
|
double mvv2e = force->mvv2e;
|
|
|
|
double ftm2v = force->ftm2v;
|
|
|
|
|
|
|
|
if (which == NOBIAS) {
|
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
if (mask[i] & groupbit) {
|
|
|
|
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;
|
2009-08-09 06:58:52 +08:00
|
|
|
flangevin[i][0] = gamma1*v[i][0] + gamma2*(random->uniform()-0.5);
|
|
|
|
flangevin[i][1] = gamma1*v[i][1] + gamma2*(random->uniform()-0.5);
|
|
|
|
flangevin[i][2] = gamma1*v[i][2] + gamma2*(random->uniform()-0.5);
|
|
|
|
f[i][0] += flangevin[i][0];
|
|
|
|
f[i][1] += flangevin[i][1];
|
|
|
|
f[i][2] += flangevin[i][2];
|
2008-03-20 00:02:28 +08:00
|
|
|
}
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
2008-03-12 01:15:30 +08:00
|
|
|
|
2008-03-20 00:02:28 +08:00
|
|
|
} else if (which == BIAS) {
|
|
|
|
double tmp = temperature->compute_scalar();
|
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
if (mask[i] & groupbit) {
|
|
|
|
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;
|
|
|
|
temperature->remove_bias(i,v[i]);
|
2009-08-09 06:58:52 +08:00
|
|
|
flangevin[i][0] = gamma1*v[i][0] + gamma2*(random->uniform()-0.5);
|
|
|
|
flangevin[i][1] = gamma1*v[i][1] + gamma2*(random->uniform()-0.5);
|
|
|
|
flangevin[i][2] = gamma1*v[i][2] + gamma2*(random->uniform()-0.5);
|
|
|
|
if (v[i][0] != 0.0) f[i][0] += flangevin[i][0];
|
|
|
|
else flangevin[i][0] = 0;
|
|
|
|
if (v[i][1] != 0.0) f[i][1] += flangevin[i][1];
|
|
|
|
else flangevin[i][1] = 0;
|
|
|
|
if (v[i][2] != 0.0) f[i][2] += flangevin[i][2];
|
|
|
|
else flangevin[i][2] = 0;
|
|
|
|
temperature->restore_bias(i,v[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (which == NOBIAS) {
|
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
if (mask[i] & groupbit) {
|
|
|
|
gamma1 = gfactor1[type[i]];
|
|
|
|
gamma2 = gfactor2[type[i]] * tsqrt;
|
|
|
|
flangevin[i][0] = gamma1*v[i][0] + gamma2*(random->uniform()-0.5);
|
|
|
|
flangevin[i][1] = gamma1*v[i][1] + gamma2*(random->uniform()-0.5);
|
|
|
|
flangevin[i][2] = gamma1*v[i][2] + gamma2*(random->uniform()-0.5);
|
|
|
|
f[i][0] += flangevin[i][0];
|
|
|
|
f[i][1] += flangevin[i][1];
|
|
|
|
f[i][2] += flangevin[i][2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (which == BIAS) {
|
|
|
|
double tmp = temperature->compute_scalar();
|
|
|
|
for (int i = 0; i < nlocal; i++) {
|
|
|
|
if (mask[i] & groupbit) {
|
|
|
|
gamma1 = gfactor1[type[i]];
|
|
|
|
gamma2 = gfactor2[type[i]] * tsqrt;
|
|
|
|
temperature->remove_bias(i,v[i]);
|
|
|
|
flangevin[i][0] = gamma1*v[i][0] + gamma2*(random->uniform()-0.5);
|
|
|
|
flangevin[i][1] = gamma1*v[i][1] + gamma2*(random->uniform()-0.5);
|
|
|
|
flangevin[i][2] = gamma1*v[i][2] + gamma2*(random->uniform()-0.5);
|
|
|
|
if (v[i][0] != 0.0) f[i][0] += flangevin[i][0];
|
|
|
|
else flangevin[i][0] = 0.0;
|
|
|
|
if (v[i][1] != 0.0) f[i][1] += flangevin[i][1];
|
|
|
|
else flangevin[i][1] = 0.0;
|
|
|
|
if (v[i][2] != 0.0) f[i][2] += flangevin[i][2];
|
|
|
|
else flangevin[i][2] = 0.0;
|
2008-03-20 23:32:33 +08:00
|
|
|
temperature->restore_bias(i,v[i]);
|
2008-03-20 00:02:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2009-08-09 06:58:52 +08:00
|
|
|
if (!tally) return;
|
|
|
|
|
|
|
|
double **v = atom->v;
|
|
|
|
int *mask = atom->mask;
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
|
|
|
|
energy_onestep = 0.0;
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
energy += energy_onestep*update->dt;
|
2006-09-28 03:51:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixLangevin::reset_target(double t_new)
|
|
|
|
{
|
|
|
|
t_start = t_stop = t_new;
|
|
|
|
}
|
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++) {
|
|
|
|
gfactor2[i] = sqrt(atom->mass[i]) *
|
|
|
|
sqrt(24.0*force->boltz/t_period/update->dt/force->mvv2e) /
|
|
|
|
force->ftm2v;
|
|
|
|
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) {
|
|
|
|
if (narg < 2) error->all("Illegal fix_modify command");
|
|
|
|
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);
|
2009-11-07 07:34:26 +08:00
|
|
|
if (icompute < 0) error->all("Could not find fix_modify temperature ID");
|
2008-03-12 01:15:30 +08:00
|
|
|
temperature = modify->compute[icompute];
|
|
|
|
|
|
|
|
if (temperature->tempflag == 0)
|
2009-11-07 07:34:26 +08:00
|
|
|
error->all("Fix_modify temperature ID does not compute temperature");
|
2008-03-12 01:15:30 +08:00
|
|
|
if (temperature->igroup != igroup && comm->me == 0)
|
|
|
|
error->warning("Group for fix_modify temp != fix group");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-09 06:58:52 +08:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
double FixLangevin::compute_scalar()
|
|
|
|
{
|
2010-09-28 00:48:24 +08:00
|
|
|
if (!tally || 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;
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
|
|
|
|
if (update->ntimestep == update->beginstep) {
|
|
|
|
energy_onestep = 0.0;
|
|
|
|
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];
|
|
|
|
energy = 0.5*energy_onestep*update->dt;
|
|
|
|
}
|
|
|
|
|
|
|
|
double energy_me = energy - 0.5*energy_onestep*update->dt;
|
|
|
|
|
|
|
|
double energy_all;
|
|
|
|
MPI_Allreduce(&energy_me,&energy_all,1,MPI_DOUBLE,MPI_SUM,world);
|
|
|
|
return -energy_all;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
memory usage of tally array
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
double FixLangevin::memory_usage()
|
|
|
|
{
|
|
|
|
if (!tally) return 0.0;
|
|
|
|
double bytes = atom->nmax*3 * sizeof(double);
|
|
|
|
return bytes;
|
|
|
|
}
|