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

This commit is contained in:
sjplimp
2007-06-20 13:17:59 +00:00
parent bde732bced
commit aaed6ebc33
131 changed files with 4277 additions and 2222 deletions

236
src/ASPHERE/fix_nve_asphere.cpp Executable file
View File

@ -0,0 +1,236 @@
/* ----------------------------------------------------------------------
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.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Mike Brown (SNL)
------------------------------------------------------------------------- */
#include "math.h"
#include "stdio.h"
#include "string.h"
#include "fix_nve_asphere.h"
#include "math_extra.h"
#include "atom.h"
#include "force.h"
#include "update.h"
#include "memory.h"
#include "error.h"
#define TOLERANCE 1.0e-6
#define EPSILON 1.0e-7
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
FixNVEASphere::FixNVEASphere(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg)
{
if (narg < 3) error->all("Illegal fix nve/asphere command");
if (atom->quat == NULL || atom->angmom == NULL || atom->torque == NULL)
error->all("Fix nve/asphere requires atom attributes "
"quat, angmom, torque");
inertia =
memory->create_2d_double_array(atom->ntypes+1,3,"fix_temp_sphere:inertia");
}
/* ---------------------------------------------------------------------- */
FixNVEASphere::~FixNVEASphere()
{
memory->destroy_2d_double_array(inertia);
}
/* ---------------------------------------------------------------------- */
int FixNVEASphere::setmask()
{
int mask = 0;
mask |= INITIAL_INTEGRATE;
mask |= FINAL_INTEGRATE;
return mask;
}
/* ---------------------------------------------------------------------- */
void FixNVEASphere::init()
{
dtv = update->dt;
dtf = 0.5 * update->dt * force->ftm2v;
dtq = 0.5 * update->dt;
calculate_inertia();
}
/* ---------------------------------------------------------------------- */
void FixNVEASphere::initial_integrate()
{
double dtfm;
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;
for (int i = 0; i < atom->nlocal; i++)
if (mask[i] & groupbit) {
dtfm = dtf / mass[type[i]];
v[i][0] += dtfm * f[i][0];
v[i][1] += dtfm * f[i][1];
v[i][2] += dtfm * f[i][2];
x[i][0] += dtv * v[i][0];
x[i][1] += dtv * v[i][1];
x[i][2] += dtv * v[i][2];
// update angular momentum by 1/2 step
// update quaternion a full step via Richardson iteration
// returns new normalized quaternion
angmom[i][0] += dtf * torque[i][0];
angmom[i][1] += dtf * torque[i][1];
angmom[i][2] += dtf * torque[i][2];
richardson(quat[i],angmom[i],inertia[type[i]]);
}
}
/* ---------------------------------------------------------------------- */
void FixNVEASphere::final_integrate()
{
double dtfm;
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;
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
dtfm = dtf / mass[atom->type[i]];
v[i][0] += dtfm * f[i][0];
v[i][1] += dtfm * f[i][1];
v[i][2] += dtfm * f[i][2];
angmom[i][0] += dtf * torque[i][0];
angmom[i][1] += dtf * torque[i][1];
angmom[i][2] += dtf * torque[i][2];
}
}
/* ----------------------------------------------------------------------
Richardson iteration to update quaternion accurately
------------------------------------------------------------------------- */
void FixNVEASphere::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 FixNVEASphere::omega_from_mq(double *q, double *m, double *moments,
double *w)
{
double rot[3][3];
MathExtra::quat_to_mat(q,rot);
double wbody[3];
MathExtra::transpose_times_column3(rot,m,wbody);
wbody[0] /= moments[0];
wbody[1] /= moments[1];
wbody[2] /= moments[2];
MathExtra::times_column3(rot,wbody,w);
}
/* ----------------------------------------------------------------------
principal moments of inertia for ellipsoids
------------------------------------------------------------------------- */
void FixNVEASphere::calculate_inertia()
{
double *mass = atom->mass;
double **shape = atom->shape;
for (int i = 1; i <= atom->ntypes; i++) {
inertia[i][0] = mass[i] *
(shape[i][1]*shape[i][1]+shape[i][2]*shape[i][2]) / 5.0;
inertia[i][1] = mass[i] *
(shape[i][0]*shape[i][0]+shape[i][2]*shape[i][2]) / 5.0;
inertia[i][2] = mass[i] *
(shape[i][0]*shape[i][0]+shape[i][1]*shape[i][1]) / 5.0;
}
}