Commit d8ac4b82 authored by sjplimp's avatar sjplimp
Browse files

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@1646 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent 23196923
Loading
Loading
Loading
Loading
+72 −23
Original line number Diff line number Diff line
@@ -27,9 +27,12 @@
#include "kspace.h"
#include "update.h"
#include "domain.h"
#include "error.h"

using namespace LAMMPS_NS;

enum{NOBIAS,BIAS};

/* ---------------------------------------------------------------------- */

FixNPTASphere::FixNPTASphere(LAMMPS *lmp, int narg, char **arg) :
@@ -41,6 +44,14 @@ FixNPTASphere::FixNPTASphere(LAMMPS *lmp, int narg, char **arg) :
	       "quat, angmom, torque, shape");
}

/* ---------------------------------------------------------------------- */

void FixNPTASphere::init()
{
  FixNPT::init();
  dtq = 0.5 * update->dt;
}

/* ----------------------------------------------------------------------
   1st half of Verlet update 
------------------------------------------------------------------------- */
@@ -48,6 +59,7 @@ FixNPTASphere::FixNPTASphere(LAMMPS *lmp, int narg, char **arg) :
void FixNPTASphere::initial_integrate(int vflag)
{
  int i;
  double dtfm;

  double delta = update->ntimestep - update->beginstep;
  delta /= update->endstep - update->beginstep;
@@ -77,9 +89,9 @@ void FixNPTASphere::initial_integrate(int vflag)
    factor[i] = exp(-dthalf*(eta_dot+omega_dot[i]));
    dilation[i] = exp(dthalf*omega_dot[i]);
  }
  ang_factor = exp(-dthalf*eta_dot);
  factor_rotate = exp(-dthalf*eta_dot);

  // v update only for atoms in group
  // update v of only atoms in group

  double **x = atom->x;
  double **v = atom->v;
@@ -93,7 +105,7 @@ void FixNPTASphere::initial_integrate(int vflag)
  int nlocal = atom->nlocal;
  if (igroup == atom->firstgroup) nlocal = atom->nfirst;

  double dtfm;
  if (which == NOBIAS) {
    for (i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) {
	dtfm = dtf / mass[type[i]];
@@ -102,6 +114,18 @@ void FixNPTASphere::initial_integrate(int vflag)
	v[i][2] = v[i][2]*factor[2] + dtfm*f[i][2];
      }
    }
  } else if (which == BIAS) {
    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(v[i]);
      }
    }
  }

  // remap simulation box and all owned atoms by 1/2 step

@@ -120,11 +144,12 @@ void FixNPTASphere::initial_integrate(int vflag)
  // update angular momentum by 1/2 step
  // 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] * ang_factor + dtf * torque[i][0];
      angmom[i][1] = angmom[i][1] * ang_factor + dtf * torque[i][1];
      angmom[i][2] = angmom[i][2] * ang_factor + dtf * torque[i][2];
      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];
		
      double inertia[3];
      calculate_inertia(atom->mass[type[i]],atom->shape[type[i]],inertia);
@@ -146,8 +171,9 @@ void FixNPTASphere::initial_integrate(int vflag)
void FixNPTASphere::final_integrate()
{
  int i;
  double dtfm;

  // v update only for atoms in group
  // update v of only atoms in group

  double **v = atom->v;
  double **f = atom->f;
@@ -159,16 +185,31 @@ void FixNPTASphere::final_integrate()
  int nlocal = atom->nlocal;
  if (igroup == atom->firstgroup) nlocal = atom->nfirst;

  double dtfm;
  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]) * ang_factor;
      angmom[i][1] = (angmom[i][1] + dtf * torque[i][1]) * ang_factor;
      angmom[i][2] = (angmom[i][2] + dtf * torque[i][2]) * ang_factor;
	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 if (which == BIAS) {
    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(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;
      }
    }
  }

@@ -208,6 +249,14 @@ void FixNPTASphere::final_integrate()
  }
}

/* ---------------------------------------------------------------------- */

void FixNPTASphere::reset_dt()
{
  FixNPT::reset_dt();
  dtq = 0.5 * update->dt;
}

/* ----------------------------------------------------------------------
   Richardson iteration to update quaternion accurately
------------------------------------------------------------------------- */
+4 −2
Original line number Diff line number Diff line
@@ -21,12 +21,14 @@ namespace LAMMPS_NS {
class FixNPTASphere : public FixNPT {
 public:
  FixNPTASphere(class LAMMPS *, int, char **);
  ~FixNPTASphere() {}
  void init();
  void initial_integrate(int);
  void final_integrate();
  void reset_dt();

 private:
  double ang_factor;
  double dtq;
  double factor_rotate;

  void richardson(double *, double *, double *);
  void omega_from_mq(double *, double *, double *, double *);
+93 −30
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@

using namespace LAMMPS_NS;

enum{NOBIAS,BIAS};

/* ---------------------------------------------------------------------- */

FixNVTASphere::FixNVTASphere(LAMMPS *lmp, int narg, char **arg) :
@@ -45,6 +47,14 @@ FixNVTASphere::FixNVTASphere(LAMMPS *lmp, int narg, char **arg) :

/* ---------------------------------------------------------------------- */

void FixNVTASphere::init()
{
  FixNVT::init();
  dtq = 0.5 * update->dt;
}

/* ---------------------------------------------------------------------- */

void FixNVTASphere::initial_integrate(int vflag)
{
  double dtfm;
@@ -75,12 +85,40 @@ void FixNVTASphere::initial_integrate(int vflag)
  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]];
	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];
	
	double inertia[3];
	calculate_inertia(atom->mass[type[i]],atom->shape[type[i]],inertia);
	richardson(quat[i],angmom[i],inertia);
      }
    }

  } else if (which == BIAS) {
    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(v[i]);
	x[i][0] += dtv * v[i][0];
	x[i][1] += dtv * v[i][1];
	x[i][2] += dtv * v[i][2];
@@ -99,6 +137,7 @@ void FixNVTASphere::initial_integrate(int vflag)
      }
    }
  }
}

/* ---------------------------------------------------------------------- */

@@ -118,16 +157,32 @@ void FixNVTASphere::final_integrate()
  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;
      }
    }

      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];
  } else if (which == BIAS) {
    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(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;
      }
    }
  }

@@ -142,6 +197,14 @@ void FixNVTASphere::final_integrate()
  eta_dot *= drag_factor;
}

/* ---------------------------------------------------------------------- */

void FixNVTASphere::reset_dt()
{
  FixNVT::reset_dt();
  dtq = 0.5 * update->dt;
}

/* ----------------------------------------------------------------------
   Richardson iteration to update quaternion accurately
------------------------------------------------------------------------- */
+4 −1
Original line number Diff line number Diff line
@@ -21,11 +21,14 @@ namespace LAMMPS_NS {
class FixNVTASphere : public FixNVT {
 public:
  FixNVTASphere(class LAMMPS *, int, char **);
  ~FixNVTASphere() {}
  void init();
  void initial_integrate(int);
  void final_integrate();
  void reset_dt();

 private:
  double dtq;

  void richardson(double *, double *, double *);
  void omega_from_mq(double *, double *, double *, double *);
  void calculate_inertia(double mass, double *shape, double *inertia);
+0 −1
Original line number Diff line number Diff line
@@ -175,4 +175,3 @@ void Compute::restore_bias(double *v)
  v[1] += vbias[1];
  v[2] += vbias[2];
}
Loading