git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@3950 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp 2010-04-02 16:53:02 +00:00
parent aa618da536
commit 02ac8178c5
7 changed files with 167 additions and 687 deletions

View File

@ -8,6 +8,7 @@ if (test $1 = 1) then
cp atom_vec_ellipsoid.cpp ..
cp compute_erotate_asphere.cpp ..
cp compute_temp_asphere.cpp ..
cp fix_nph_asphere.cpp ..
cp fix_npt_asphere.cpp ..
cp fix_nve_asphere.cpp ..
cp fix_nvt_asphere.cpp ..
@ -17,6 +18,7 @@ if (test $1 = 1) then
cp atom_vec_ellipsoid.h ..
cp compute_erotate_asphere.h ..
cp compute_temp_asphere.h ..
cp fix_nph_asphere.h ..
cp fix_npt_asphere.h ..
cp fix_nve_asphere.h ..
cp fix_nvt_asphere.h ..
@ -28,6 +30,7 @@ elif (test $1 = 0) then
rm ../atom_vec_ellipsoid.cpp
rm ../compute_erotate_asphere.cpp
rm ../compute_temp_asphere.cpp
rm ../fix_nph_asphere.cpp
rm ../fix_npt_asphere.cpp
rm ../fix_nve_asphere.cpp
rm ../fix_nvt_asphere.cpp
@ -37,6 +40,7 @@ elif (test $1 = 0) then
rm ../atom_vec_ellipsoid.h
rm ../compute_erotate_asphere.h
rm ../compute_temp_asphere.h
rm ../fix_nph_asphere.h
rm ../fix_npt_asphere.h
rm ../fix_nve_asphere.h
rm ../fix_nvt_asphere.h

View File

@ -0,0 +1,67 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
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.
------------------------------------------------------------------------- */
#include "string.h"
#include "fix_nph_asphere.h"
#include "modify.h"
#include "error.h"
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
FixNPHAsphere::FixNPHAsphere(LAMMPS *lmp, int narg, char **arg) :
FixNHAsphere(lmp, narg, arg)
{
if (tstat_flag)
error->all("Temperature control can not be used with fix nph/asphere");
if (!pstat_flag)
error->all("Pressure control must be used with fix nph/asphere");
// create a new compute temp style
// id = fix-ID + temp
// compute group = all since pressure is always global (group all)
// and thus its KE/temperature contribution should use group all
int n = strlen(id) + 6;
id_temp = new char[n];
strcpy(id_temp,id);
strcat(id_temp,"_temp");
char **newarg = new char*[3];
newarg[0] = id_temp;
newarg[1] = (char *) "all";
newarg[2] = (char *) "temp/asphere";
modify->add_compute(3,newarg);
delete [] newarg;
tflag = 1;
// create a new compute pressure style
// id = fix-ID + press, compute group = all
// pass id_temp as 4th arg to pressure constructor
n = strlen(id) + 7;
id_press = new char[n];
strcpy(id_press,id);
strcat(id_press,"_press");
newarg = new char*[4];
newarg[0] = id_press;
newarg[1] = (char *) "all";
newarg[2] = (char *) "pressure";
newarg[3] = id_temp;
modify->add_compute(4,newarg);
delete [] newarg;
pflag = 1;
}

View File

@ -0,0 +1,36 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
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.
------------------------------------------------------------------------- */
#ifdef FIX_CLASS
FixStyle(nph/asphere,FixNPHAsphere)
#else
#ifndef LMP_FIX_NPH_ASPHERE_H
#define LMP_FIX_NPH_ASPHERE_H
#include "fix_nh_asphere.h"
namespace LAMMPS_NS {
class FixNPHAsphere : public FixNHAsphere {
public:
FixNPHAsphere(class LAMMPS *, int, char **);
~FixNPHAsphere() {}
};
}
#endif
#endif

View File

@ -11,375 +11,57 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Mike Brown (SNL)
------------------------------------------------------------------------- */
#include "string.h"
#include "stdlib.h"
#include "math.h"
#include "fix_npt_asphere.h"
#include "math_extra.h"
#include "atom.h"
#include "atom_vec.h"
#include "force.h"
#include "compute.h"
#include "kspace.h"
#include "update.h"
#include "domain.h"
#include "memory.h"
#include "modify.h"
#include "error.h"
using namespace LAMMPS_NS;
enum{NOBIAS,BIAS};
/* ---------------------------------------------------------------------- */
FixNPTAsphere::FixNPTAsphere(LAMMPS *lmp, int narg, char **arg) :
FixNPT(lmp, narg, arg)
FixNHAsphere(lmp, narg, arg)
{
inertia =
memory->create_2d_double_array(atom->ntypes+1,3,"fix_npt_asphere:inertia");
if (!tstat_flag)
error->all("Temperature control must be used with fix npt/asphere");
if (!pstat_flag)
error->all("Pressure control must be used with fix npt/asphere");
// error checks
// create a new compute temp style
// id = fix-ID + temp
// compute group = all since pressure is always global (group all)
// and thus its KE/temperature contribution should use group all
if (!atom->quat_flag || !atom->angmom_flag || !atom->torque_flag ||
!atom->avec->shape_type)
error->all("Fix npt/asphere requires atom attributes "
"quat, angmom, torque, shape");
if (atom->radius_flag || atom->rmass_flag)
error->all("Fix npt/asphere cannot be used with atom attributes "
"diameter or rmass");
}
/* ---------------------------------------------------------------------- */
FixNPTAsphere::~FixNPTAsphere()
{
memory->destroy_2d_double_array(inertia);
}
/* ---------------------------------------------------------------------- */
void FixNPTAsphere::init()
{
// check that all particles are finite-size
// no point particles allowed, spherical is OK
double **shape = atom->shape;
int *type = atom->type;
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)
if (shape[type[i]][0] == 0.0)
error->one("Fix nvt/asphere requires extended particles");
FixNPT::init();
calculate_inertia();
}
/* ---------------------------------------------------------------------- */
void FixNPTAsphere::initial_integrate(int vflag)
{
int i;
double dtfm;
double delta = update->ntimestep - update->beginstep;
delta /= update->endstep - update->beginstep;
// update eta_dot
t_target = t_start + delta * (t_stop-t_start);
f_eta = t_freq*t_freq * (t_current/t_target - 1.0);
eta_dot += f_eta*dthalf;
eta_dot *= drag_factor;
eta += dtv*eta_dot;
// update omega_dot
// for non-varying dims, p_freq is 0.0, so omega_dot doesn't change
double f_omega,volume;
if (dimension == 3) volume = domain->xprd*domain->yprd*domain->zprd;
else volume = domain->xprd*domain->yprd;
double denskt = atom->natoms*boltz*t_target / volume * nktv2p;
for (i = 0; i < 3; i++) {
p_target[i] = p_start[i] + delta * (p_stop[i]-p_start[i]);
f_omega = p_freq[i]*p_freq[i] * (p_current[i]-p_target[i])/denskt;
omega_dot[i] += f_omega*dthalf;
omega_dot[i] *= drag_factor;
omega[i] += dtv*omega_dot[i];
factor[i] = exp(-dthalf*(eta_dot+omega_dot[i]));
dilation[i] = exp(dthalf*omega_dot[i]);
}
factor_rotate = exp(-dthalf*eta_dot);
// update v of atoms in group
// for BIAS:
// calculate temperature since some computes require temp
// computed on current nlocal atoms to remove bias
// OK to not test returned v = 0, since factor is multiplied by v
double **x = atom->x;
double **v = atom->v;
double **f = atom->f;
double **quat = atom->quat;
double **angmom = atom->angmom;
double **torque = atom->torque;
double *mass = atom->mass;
int *type = atom->type;
int *mask = atom->mask;
int nlocal = atom->nlocal;
if (igroup == atom->firstgroup) nlocal = atom->nfirst;
if (which == NOBIAS) {
for (i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
dtfm = dtf / mass[type[i]];
v[i][0] = v[i][0]*factor[0] + dtfm*f[i][0];
v[i][1] = v[i][1]*factor[1] + dtfm*f[i][1];
v[i][2] = v[i][2]*factor[2] + dtfm*f[i][2];
}
}
} else {
double tmp = temperature->compute_scalar();
for (i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
temperature->remove_bias(i,v[i]);
dtfm = dtf / mass[type[i]];
v[i][0] = v[i][0]*factor[0] + dtfm*f[i][0];
v[i][1] = v[i][1]*factor[1] + dtfm*f[i][1];
v[i][2] = v[i][2]*factor[2] + dtfm*f[i][2];
temperature->restore_bias(i,v[i]);
}
}
}
// remap simulation box by 1/2 step
remap();
// update x by full step for atoms in group
for (i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
x[i][0] += dtv * v[i][0];
x[i][1] += dtv * v[i][1];
x[i][2] += dtv * v[i][2];
}
}
// set timestep here since dt may have changed or come via rRESPA
dtq = 0.5 * dtv;
// update angular momentum by 1/2 step for atoms in group
// update quaternion a full step via Richardson iteration
// returns new normalized quaternion
for (i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
angmom[i][0] = angmom[i][0]*factor_rotate + dtf*torque[i][0];
angmom[i][1] = angmom[i][1]*factor_rotate + dtf*torque[i][1];
angmom[i][2] = angmom[i][2]*factor_rotate + dtf*torque[i][2];
richardson(quat[i],angmom[i],inertia[type[i]]);
}
}
// remap simulation box by 1/2 step
// redo KSpace coeffs since volume has changed
remap();
if (kspace_flag) force->kspace->setup();
}
/* ---------------------------------------------------------------------- */
void FixNPTAsphere::final_integrate()
{
int i;
double dtfm;
// update v,angmom of atoms in group
// for BIAS:
// calculate temperature since some computes require temp
// computed on current nlocal atoms to remove bias
// OK to not test returned v = 0, since factor is multiplied by v
double **v = atom->v;
double **f = atom->f;
double **angmom = atom->angmom;
double **torque = atom->torque;
double *mass = atom->mass;
int *type = atom->type;
int *mask = atom->mask;
int nlocal = atom->nlocal;
if (igroup == atom->firstgroup) nlocal = atom->nfirst;
if (which == NOBIAS) {
for (i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
dtfm = dtf / mass[type[i]];
v[i][0] = (v[i][0] + dtfm*f[i][0]) * factor[0];
v[i][1] = (v[i][1] + dtfm*f[i][1]) * factor[1];
v[i][2] = (v[i][2] + dtfm*f[i][2]) * factor[2];
angmom[i][0] = (angmom[i][0] + dtf * torque[i][0]) * factor_rotate;
angmom[i][1] = (angmom[i][1] + dtf * torque[i][1]) * factor_rotate;
angmom[i][2] = (angmom[i][2] + dtf * torque[i][2]) * factor_rotate;
}
}
} else {
double tmp = temperature->compute_scalar();
for (i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
temperature->remove_bias(i,v[i]);
dtfm = dtf / mass[type[i]];
v[i][0] = (v[i][0] + dtfm*f[i][0]) * factor[0];
v[i][1] = (v[i][1] + dtfm*f[i][1]) * factor[1];
v[i][2] = (v[i][2] + dtfm*f[i][2]) * factor[2];
temperature->restore_bias(i,v[i]);
angmom[i][0] = (angmom[i][0] + dtf * torque[i][0]) * factor_rotate;
angmom[i][1] = (angmom[i][1] + dtf * torque[i][1]) * factor_rotate;
angmom[i][2] = (angmom[i][2] + dtf * torque[i][2]) * factor_rotate;
}
}
}
// compute new T,P
t_current = temperature->compute_scalar();
if (press_couple == 0) {
double tmp = pressure->compute_scalar();
} else {
temperature->compute_vector();
pressure->compute_vector();
}
couple();
// trigger virial computation on next timestep
pressure->addstep(update->ntimestep+1);
// update eta_dot
f_eta = t_freq*t_freq * (t_current/t_target - 1.0);
eta_dot += f_eta*dthalf;
eta_dot *= drag_factor;
// update omega_dot
// for non-varying dims, p_freq is 0.0, so omega_dot doesn't change
double f_omega,volume;
if (dimension == 3) volume = domain->xprd*domain->yprd*domain->zprd;
else volume = domain->xprd*domain->yprd;
double denskt = atom->natoms*boltz*t_target / volume * nktv2p;
for (i = 0; i < 3; i++) {
f_omega = p_freq[i]*p_freq[i] * (p_current[i]-p_target[i])/denskt;
omega_dot[i] += f_omega*dthalf;
omega_dot[i] *= drag_factor;
}
}
/* ----------------------------------------------------------------------
Richardson iteration to update quaternion accurately
------------------------------------------------------------------------- */
void FixNPTAsphere::richardson(double *q, double *m, double *moments)
{
// compute omega at 1/2 step from m at 1/2 step and q at 0
double w[3];
omega_from_mq(q,m,moments,w);
// full update from dq/dt = 1/2 w q
double wq[4];
MathExtra::multiply_vec_quat(w,q,wq);
double qfull[4];
qfull[0] = q[0] + dtq * wq[0];
qfull[1] = q[1] + dtq * wq[1];
qfull[2] = q[2] + dtq * wq[2];
qfull[3] = q[3] + dtq * wq[3];
MathExtra::normalize4(qfull);
// 1st half of update from dq/dt = 1/2 w q
double qhalf[4];
qhalf[0] = q[0] + 0.5*dtq * wq[0];
qhalf[1] = q[1] + 0.5*dtq * wq[1];
qhalf[2] = q[2] + 0.5*dtq * wq[2];
qhalf[3] = q[3] + 0.5*dtq * wq[3];
MathExtra::normalize4(qhalf);
// re-compute omega at 1/2 step from m at 1/2 step and q at 1/2 step
// recompute wq
omega_from_mq(qhalf,m,moments,w);
MathExtra::multiply_vec_quat(w,qhalf,wq);
// 2nd half of update from dq/dt = 1/2 w q
qhalf[0] += 0.5*dtq * wq[0];
qhalf[1] += 0.5*dtq * wq[1];
qhalf[2] += 0.5*dtq * wq[2];
qhalf[3] += 0.5*dtq * wq[3];
MathExtra::normalize4(qhalf);
// corrected Richardson update
q[0] = 2.0*qhalf[0] - qfull[0];
q[1] = 2.0*qhalf[1] - qfull[1];
q[2] = 2.0*qhalf[2] - qfull[2];
q[3] = 2.0*qhalf[3] - qfull[3];
MathExtra::normalize4(q);
}
/* ----------------------------------------------------------------------
compute omega from angular momentum
w = omega = angular velocity in space frame
wbody = angular velocity in body frame
project space-frame angular momentum onto body axes
and divide by principal moments
------------------------------------------------------------------------- */
void FixNPTAsphere::omega_from_mq(double *q, double *m, double *inertia,
double *w)
{
double rot[3][3];
MathExtra::quat_to_mat(q,rot);
int n = strlen(id) + 6;
id_temp = new char[n];
strcpy(id_temp,id);
strcat(id_temp,"_temp");
double wbody[3];
MathExtra::transpose_times_column3(rot,m,wbody);
wbody[0] /= inertia[0];
wbody[1] /= inertia[1];
wbody[2] /= inertia[2];
MathExtra::times_column3(rot,wbody,w);
}
char **newarg = new char*[3];
newarg[0] = id_temp;
newarg[1] = (char *) "all";
newarg[2] = (char *) "temp/asphere";
modify->add_compute(3,newarg);
delete [] newarg;
tflag = 1;
/* ----------------------------------------------------------------------
principal moments of inertia for ellipsoids
------------------------------------------------------------------------- */
// create a new compute pressure style
// id = fix-ID + press, compute group = all
// pass id_temp as 4th arg to pressure constructor
void FixNPTAsphere::calculate_inertia()
{
double *mass = atom->mass;
double **shape = atom->shape;
n = strlen(id) + 7;
id_press = new char[n];
strcpy(id_press,id);
strcat(id_press,"_press");
for (int i = 1; i <= atom->ntypes; i++) {
inertia[i][0] = 0.2*mass[i] *
(shape[i][1]*shape[i][1]+shape[i][2]*shape[i][2]);
inertia[i][1] = 0.2*mass[i] *
(shape[i][0]*shape[i][0]+shape[i][2]*shape[i][2]);
inertia[i][2] = 0.2*mass[i] *
(shape[i][0]*shape[i][0]+shape[i][1]*shape[i][1]);
}
newarg = new char*[4];
newarg[0] = id_press;
newarg[1] = (char *) "all";
newarg[2] = (char *) "pressure";
newarg[3] = id_temp;
modify->add_compute(4,newarg);
delete [] newarg;
pflag = 1;
}

View File

@ -20,26 +20,14 @@ FixStyle(npt/asphere,FixNPTAsphere)
#ifndef LMP_FIX_NPT_ASPHERE_H
#define LMP_FIX_NPT_ASPHERE_H
#include "fix_npt.h"
#include "fix_nh_asphere.h"
namespace LAMMPS_NS {
class FixNPTAsphere : public FixNPT {
class FixNPTAsphere : public FixNHAsphere {
public:
FixNPTAsphere(class LAMMPS *, int, char **);
~FixNPTAsphere();
void init();
void initial_integrate(int);
void final_integrate();
private:
double dtq;
double factor_rotate;
double **inertia;
void richardson(double *, double *, double *);
void omega_from_mq(double *, double *, double *, double *);
void calculate_inertia();
~FixNPTAsphere() {}
};
}

View File

@ -11,324 +11,38 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Mike Brown (SNL)
------------------------------------------------------------------------- */
#include "string.h"
#include "stdlib.h"
#include "math.h"
#include "fix_nvt_asphere.h"
#include "math_extra.h"
#include "atom.h"
#include "atom_vec.h"
#include "force.h"
#include "comm.h"
#include "group.h"
#include "update.h"
#include "modify.h"
#include "compute.h"
#include "memory.h"
#include "error.h"
using namespace LAMMPS_NS;
enum{NOBIAS,BIAS};
/* ---------------------------------------------------------------------- */
FixNVTAsphere::FixNVTAsphere(LAMMPS *lmp, int narg, char **arg) :
FixNVT(lmp, narg, arg)
FixNHAsphere(lmp, narg, arg)
{
inertia =
memory->create_2d_double_array(atom->ntypes+1,3,"fix_nvt_asphere:inertia");
if (!tstat_flag)
error->all("Temperature control must be used with fix nvt/asphere");
if (pstat_flag)
error->all("Pressure control can not be used with fix nvt/asphere");
// error checks
// create a new compute temp style
// id = fix-ID + temp
if (!atom->quat_flag || !atom->angmom_flag || !atom->torque_flag ||
!atom->avec->shape_type)
error->all("Fix nvt/asphere requires atom attributes "
"quat, angmom, torque, shape");
if (atom->radius_flag || atom->rmass_flag)
error->all("Fix nvt/asphere cannot be used with atom attributes "
"diameter or rmass");
}
/* ---------------------------------------------------------------------- */
FixNVTAsphere::~FixNVTAsphere()
{
memory->destroy_2d_double_array(inertia);
}
/* ---------------------------------------------------------------------- */
void FixNVTAsphere::init()
{
// check that all particles are finite-size
// no point particles allowed, spherical is OK
double **shape = atom->shape;
int *type = atom->type;
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)
if (shape[type[i]][0] == 0.0)
error->one("Fix nvt/asphere requires extended particles");
FixNVT::init();
calculate_inertia();
}
/* ---------------------------------------------------------------------- */
void FixNVTAsphere::initial_integrate(int vflag)
{
double dtfm;
double delta = update->ntimestep - update->beginstep;
delta /= update->endstep - update->beginstep;
t_target = t_start + delta * (t_stop-t_start);
// update eta_dot
f_eta = t_freq*t_freq * (t_current/t_target - 1.0);
eta_dot += f_eta*dthalf;
eta_dot *= drag_factor;
eta += dtv*eta_dot;
factor = exp(-dthalf*eta_dot);
// update v,x,angmom of atoms in group
// for BIAS:
// calculate temperature since some computes require temp
// computed on current nlocal atoms to remove bias
// OK to not test returned v = 0, since factor is multiplied by v
double **x = atom->x;
double **v = atom->v;
double **f = atom->f;
double **quat = atom->quat;
double **angmom = atom->angmom;
double **torque = atom->torque;
double *mass = atom->mass;
int *type = atom->type;
int *mask = atom->mask;
int nlocal = atom->nlocal;
if (igroup == atom->firstgroup) nlocal = atom->nfirst;
// set timestep here since dt may have changed or come via rRESPA
dtq = 0.5 * dtv;
if (which == NOBIAS) {
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
dtfm = dtf / mass[type[i]];
v[i][0] = v[i][0]*factor + dtfm*f[i][0];
v[i][1] = v[i][1]*factor + dtfm*f[i][1];
v[i][2] = v[i][2]*factor + 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];
// update angular momentum by 1/2 step
// update quaternion a full step via Richardson iteration
// returns new normalized quaternion
angmom[i][0] = angmom[i][0]*factor + dtf*torque[i][0];
angmom[i][1] = angmom[i][1]*factor + dtf*torque[i][1];
angmom[i][2] = angmom[i][2]*factor + dtf*torque[i][2];
richardson(quat[i],angmom[i],inertia[type[i]]);
}
}
} else {
double tmp = temperature->compute_scalar();
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
temperature->remove_bias(i,v[i]);
dtfm = dtf / mass[type[i]];
v[i][0] = v[i][0]*factor + dtfm*f[i][0];
v[i][1] = v[i][1]*factor + dtfm*f[i][1];
v[i][2] = v[i][2]*factor + dtfm*f[i][2];
temperature->restore_bias(i,v[i]);
x[i][0] += dtv * v[i][0];
x[i][1] += dtv * v[i][1];
x[i][2] += dtv * v[i][2];
// update angular momentum by 1/2 step
// update quaternion a full step via Richardson iteration
// returns new normalized quaternion
angmom[i][0] = angmom[i][0]*factor + dtf*torque[i][0];
angmom[i][1] = angmom[i][1]*factor + dtf*torque[i][1];
angmom[i][2] = angmom[i][2]*factor + dtf*torque[i][2];
richardson(quat[i],angmom[i],inertia[type[i]]);
}
}
}
}
/* ---------------------------------------------------------------------- */
void FixNVTAsphere::final_integrate()
{
double dtfm;
// update v,angmom of atoms in group
// for BIAS:
// calculate temperature since some computes require temp
// computed on current nlocal atoms to remove bias
// OK to not test returned v = 0, since factor is multiplied by v
double **v = atom->v;
double **f = atom->f;
double **angmom = atom->angmom;
double **torque = atom->torque;
double *mass = atom->mass;
int *type = atom->type;
int *mask = atom->mask;
int nlocal = atom->nlocal;
if (igroup == atom->firstgroup) nlocal = atom->nfirst;
if (which == NOBIAS) {
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
dtfm = dtf / mass[type[i]] * factor;
v[i][0] = v[i][0]*factor + dtfm*f[i][0];
v[i][1] = v[i][1]*factor + dtfm*f[i][1];
v[i][2] = v[i][2]*factor + dtfm*f[i][2];
angmom[i][0] = (angmom[i][0] + dtf*torque[i][0]) * factor;
angmom[i][1] = (angmom[i][1] + dtf*torque[i][1]) * factor;
angmom[i][2] = (angmom[i][2] + dtf*torque[i][2]) * factor;
}
}
} else {
double tmp = temperature->compute_scalar();
for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
temperature->remove_bias(i,v[i]);
dtfm = dtf / mass[type[i]] * factor;
v[i][0] = v[i][0]*factor + dtfm*f[i][0];
v[i][1] = v[i][1]*factor + dtfm*f[i][1];
v[i][2] = v[i][2]*factor + dtfm*f[i][2];
temperature->restore_bias(i,v[i]);
angmom[i][0] = (angmom[i][0] + dtf*torque[i][0]) * factor;
angmom[i][1] = (angmom[i][1] + dtf*torque[i][1]) * factor;
angmom[i][2] = (angmom[i][2] + dtf*torque[i][2]) * factor;
}
}
}
// compute current T
t_current = temperature->compute_scalar();
// update eta_dot
f_eta = t_freq*t_freq * (t_current/t_target - 1.0);
eta_dot += f_eta*dthalf;
eta_dot *= drag_factor;
}
/* ----------------------------------------------------------------------
Richardson iteration to update quaternion accurately
------------------------------------------------------------------------- */
void FixNVTAsphere::richardson(double *q, double *m, double *moments)
{
// compute omega at 1/2 step from m at 1/2 step and q at 0
double w[3];
omega_from_mq(q,m,moments,w);
// full update from dq/dt = 1/2 w q
double wq[4];
MathExtra::multiply_vec_quat(w,q,wq);
double qfull[4];
qfull[0] = q[0] + dtq * wq[0];
qfull[1] = q[1] + dtq * wq[1];
qfull[2] = q[2] + dtq * wq[2];
qfull[3] = q[3] + dtq * wq[3];
MathExtra::normalize4(qfull);
// 1st half of update from dq/dt = 1/2 w q
double qhalf[4];
qhalf[0] = q[0] + 0.5*dtq * wq[0];
qhalf[1] = q[1] + 0.5*dtq * wq[1];
qhalf[2] = q[2] + 0.5*dtq * wq[2];
qhalf[3] = q[3] + 0.5*dtq * wq[3];
MathExtra::normalize4(qhalf);
// re-compute omega at 1/2 step from m at 1/2 step and q at 1/2 step
// recompute wq
omega_from_mq(qhalf,m,moments,w);
MathExtra::multiply_vec_quat(w,qhalf,wq);
// 2nd half of update from dq/dt = 1/2 w q
qhalf[0] += 0.5*dtq * wq[0];
qhalf[1] += 0.5*dtq * wq[1];
qhalf[2] += 0.5*dtq * wq[2];
qhalf[3] += 0.5*dtq * wq[3];
MathExtra::normalize4(qhalf);
// corrected Richardson update
q[0] = 2.0*qhalf[0] - qfull[0];
q[1] = 2.0*qhalf[1] - qfull[1];
q[2] = 2.0*qhalf[2] - qfull[2];
q[3] = 2.0*qhalf[3] - qfull[3];
MathExtra::normalize4(q);
}
/* ----------------------------------------------------------------------
compute omega from angular momentum
w = omega = angular velocity in space frame
wbody = angular velocity in body frame
project space-frame angular momentum onto body axes
and divide by principal moments
------------------------------------------------------------------------- */
void FixNVTAsphere::omega_from_mq(double *q, double *m, double *inertia,
double *w)
{
double rot[3][3];
MathExtra::quat_to_mat(q,rot);
int n = strlen(id) + 6;
id_temp = new char[n];
strcpy(id_temp,id);
strcat(id_temp,"_temp");
double wbody[3];
MathExtra::transpose_times_column3(rot,m,wbody);
wbody[0] /= inertia[0];
wbody[1] /= inertia[1];
wbody[2] /= inertia[2];
MathExtra::times_column3(rot,wbody,w);
}
char **newarg = new char*[3];
newarg[0] = id_temp;
newarg[1] = group->names[igroup];
newarg[2] = (char *) "temp/asphere";
/* ----------------------------------------------------------------------
principal moments of inertia for ellipsoids
------------------------------------------------------------------------- */
void FixNVTAsphere::calculate_inertia()
{
double *mass = atom->mass;
double **shape = atom->shape;
for (int i = 1; i <= atom->ntypes; i++) {
inertia[i][0] = 0.2*mass[i] *
(shape[i][1]*shape[i][1]+shape[i][2]*shape[i][2]);
inertia[i][1] = 0.2*mass[i] *
(shape[i][0]*shape[i][0]+shape[i][2]*shape[i][2]);
inertia[i][2] = 0.2*mass[i] *
(shape[i][0]*shape[i][0]+shape[i][1]*shape[i][1]);
}
modify->add_compute(3,newarg);
delete [] newarg;
tflag = 1;
}

View File

@ -20,25 +20,14 @@ FixStyle(nvt/asphere,FixNVTAsphere)
#ifndef LMP_FIX_NVT_ASPHERE_H
#define LMP_FIX_NVT_ASPHERE_H
#include "fix_nvt.h"
#include "fix_nh_asphere.h"
namespace LAMMPS_NS {
class FixNVTAsphere : public FixNVT {
class FixNVTAsphere : public FixNHAsphere {
public:
FixNVTAsphere(class LAMMPS *, int, char **);
~FixNVTAsphere();
void init();
void initial_integrate(int);
void final_integrate();
private:
double dtq;
double **inertia;
void richardson(double *, double *, double *);
void omega_from_mq(double *, double *, double *, double *);
void calculate_inertia();
~FixNVTAsphere() {}
};
}