git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@6630 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
19
src/USER-MISC/Install.sh
Normal file
19
src/USER-MISC/Install.sh
Normal file
@ -0,0 +1,19 @@
|
||||
# Install/unInstall package files in LAMMPS
|
||||
|
||||
if (test $1 = 1) then
|
||||
|
||||
cp compute_temp_rotate.cpp ..
|
||||
cp fix_addtorque.cpp ..
|
||||
|
||||
cp compute_temp_rotate.h ..
|
||||
cp fix_addtorque.h ..
|
||||
|
||||
elif (test $1 = 0) then
|
||||
|
||||
rm -f ../compute_temp_rotate.cpp
|
||||
rm -f ../fix_addtorque.cpp
|
||||
|
||||
rm -f ../compute_temp_rotate.h
|
||||
rm -f ../fix_addtorque.h
|
||||
|
||||
fi
|
||||
20
src/USER-MISC/README
Normal file
20
src/USER-MISC/README
Normal file
@ -0,0 +1,20 @@
|
||||
The files in this directory are a potpourri of (mostly) unrelated
|
||||
features contributed to LAMMPS by users. Each feature is a single
|
||||
file (actually a *.cpp and *.h file).
|
||||
|
||||
More information about each feature can be found by reading its doc
|
||||
page in the LAMMPS doc directory. This link points to the doc
|
||||
page for all LAMMPS commands:
|
||||
|
||||
http://lammps.sandia.gov/doc/Section_commands.html#3_5\
|
||||
|
||||
User-contributed features are listed at the bottom of the fix,
|
||||
compute, pair, etc sections.
|
||||
|
||||
You should contact the author if you have specific questions about the
|
||||
feature or its code.
|
||||
|
||||
------------------------------------------------------------
|
||||
|
||||
compute temp/rotate, Laurent Joly (U Lyon, France), ljoly.ulyon at gmail.com, 8Aug11
|
||||
fix addtorque, Laurent Joly (U Lyon, France), ljoly.ulyon at gmail.com, 8Aug11
|
||||
294
src/USER-MISC/compute_temp_rotate.cpp
Normal file
294
src/USER-MISC/compute_temp_rotate.cpp
Normal file
@ -0,0 +1,294 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
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: Laurent Joly (U Lyon, France)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "mpi.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "compute_temp_rotate.h"
|
||||
#include "atom.h"
|
||||
#include "update.h"
|
||||
#include "force.h"
|
||||
#include "group.h"
|
||||
#include "modify.h"
|
||||
#include "fix.h"
|
||||
#include "domain.h"
|
||||
#include "lattice.h"
|
||||
#include "error.h"
|
||||
#include "memory.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
#define MIN(A,B) ((A) < (B)) ? (A) : (B)
|
||||
#define MAX(A,B) ((A) > (B)) ? (A) : (B)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
ComputeTempRotate::ComputeTempRotate(LAMMPS *lmp, int narg, char **arg) :
|
||||
Compute(lmp, narg, arg)
|
||||
{
|
||||
if (narg != 3) error->all("Illegal compute temp/rotate command");
|
||||
|
||||
scalar_flag = vector_flag = 1;
|
||||
size_vector = 6;
|
||||
extscalar = 0;
|
||||
extvector = 1;
|
||||
tempflag = 1;
|
||||
tempbias = 1;
|
||||
|
||||
maxbias = 0;
|
||||
vbiasall = NULL;
|
||||
vector = new double[6];
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
ComputeTempRotate::~ComputeTempRotate()
|
||||
{
|
||||
memory->destroy(vbiasall);
|
||||
delete [] vector;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void ComputeTempRotate::init()
|
||||
{
|
||||
fix_dof = 0;
|
||||
for (int i = 0; i < modify->nfix; i++)
|
||||
fix_dof += modify->fix[i]->dof(igroup);
|
||||
dof_compute();
|
||||
|
||||
masstotal = group->mass(igroup);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void ComputeTempRotate::dof_compute()
|
||||
{
|
||||
double natoms = group->count(igroup);
|
||||
int nper = domain->dimension;
|
||||
dof = nper * natoms;
|
||||
dof -= extra_dof + fix_dof;
|
||||
if (dof > 0) tfactor = force->mvv2e / (dof * force->boltz);
|
||||
else tfactor = 0.0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
double ComputeTempRotate::compute_scalar()
|
||||
{
|
||||
double vthermal[3];
|
||||
double vcm[3],xcm[3],inertia[3][3],angmom[3],omega[3];
|
||||
int xbox,ybox,zbox;
|
||||
double dx,dy,dz;
|
||||
double xprd = domain->xprd;
|
||||
double yprd = domain->yprd;
|
||||
double zprd = domain->zprd;
|
||||
|
||||
invoked_scalar = update->ntimestep;
|
||||
|
||||
if (dynamic) masstotal = group->mass(igroup);
|
||||
group->vcm(igroup,masstotal,vcm);
|
||||
group->xcm(igroup,masstotal,xcm);
|
||||
group->inertia(igroup,xcm,inertia);
|
||||
group->angmom(igroup,xcm,angmom);
|
||||
group->omega(angmom,inertia,omega);
|
||||
|
||||
double **x = atom->x;
|
||||
double **v = atom->v;
|
||||
double *mass = atom->mass;
|
||||
double *rmass = atom->rmass;
|
||||
int *type = atom->type;
|
||||
int *image = atom->image;
|
||||
int *mask = atom->mask;
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
if (nlocal > maxbias) {
|
||||
memory->destroy(vbiasall);
|
||||
maxbias = atom->nmax;
|
||||
memory->create(vbiasall,maxbias,3,"temp/rotate:vbiasall");
|
||||
}
|
||||
|
||||
double t = 0.0;
|
||||
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) {
|
||||
|
||||
xbox = (image[i] & 1023) - 512;
|
||||
ybox = (image[i] >> 10 & 1023) - 512;
|
||||
zbox = (image[i] >> 20) - 512;
|
||||
dx = (x[i][0] + xbox*xprd) - xcm[0];
|
||||
dy = (x[i][1] + ybox*yprd) - xcm[1];
|
||||
dz = (x[i][2] + zbox*zprd) - xcm[2];
|
||||
vbiasall[i][0] = vcm[0] + dz*omega[1]-dy*omega[2];
|
||||
vbiasall[i][1] = vcm[1] + dx*omega[2]-dz*omega[0];
|
||||
vbiasall[i][2] = vcm[2] + dy*omega[0]-dx*omega[1];
|
||||
|
||||
vthermal[0] = v[i][0] - vbiasall[i][0];
|
||||
vthermal[1] = v[i][1] - vbiasall[i][1];
|
||||
vthermal[2] = v[i][2] - vbiasall[i][2];
|
||||
if (rmass)
|
||||
t += (vthermal[0]*vthermal[0] + vthermal[1]*vthermal[1] +
|
||||
vthermal[2]*vthermal[2]) * rmass[i];
|
||||
else
|
||||
t += (vthermal[0]*vthermal[0] + vthermal[1]*vthermal[1] +
|
||||
vthermal[2]*vthermal[2]) * mass[type[i]];
|
||||
}
|
||||
|
||||
MPI_Allreduce(&t,&scalar,1,MPI_DOUBLE,MPI_SUM,world);
|
||||
if (dynamic) dof_compute();
|
||||
scalar *= tfactor;
|
||||
return scalar;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void ComputeTempRotate::compute_vector()
|
||||
{
|
||||
int i;
|
||||
double vthermal[3];
|
||||
double vcm[3],xcm[3],inertia[3][3],angmom[3],omega[3];
|
||||
int xbox,ybox,zbox;
|
||||
double dx,dy,dz;
|
||||
double xprd = domain->xprd;
|
||||
double yprd = domain->yprd;
|
||||
double zprd = domain->zprd;
|
||||
|
||||
invoked_vector = update->ntimestep;
|
||||
|
||||
if (dynamic) masstotal = group->mass(igroup);
|
||||
group->vcm(igroup,masstotal,vcm);
|
||||
group->xcm(igroup,masstotal,xcm);
|
||||
group->inertia(igroup,xcm,inertia);
|
||||
group->angmom(igroup,xcm,angmom);
|
||||
group->omega(angmom,inertia,omega);
|
||||
|
||||
double **x = atom->x;
|
||||
double **v = atom->v;
|
||||
double *mass = atom->mass;
|
||||
double *rmass = atom->rmass;
|
||||
int *type = atom->type;
|
||||
int *image = atom->image;
|
||||
int *mask = atom->mask;
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
if (nlocal > maxbias) {
|
||||
memory->destroy(vbiasall);
|
||||
maxbias = atom->nmax;
|
||||
memory->create(vbiasall,maxbias,3,"temp/rotate:vbiasall");
|
||||
}
|
||||
|
||||
double massone,t[6];
|
||||
for (i = 0; i < 6; i++) t[i] = 0.0;
|
||||
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) {
|
||||
|
||||
xbox = (image[i] & 1023) - 512;
|
||||
ybox = (image[i] >> 10 & 1023) - 512;
|
||||
zbox = (image[i] >> 20) - 512;
|
||||
dx = (x[i][0] + xbox*xprd) - xcm[0];
|
||||
dy = (x[i][1] + ybox*yprd) - xcm[1];
|
||||
dz = (x[i][2] + zbox*zprd) - xcm[2];
|
||||
vbiasall[i][0] = vcm[0] + dz*omega[1]-dy*omega[2];
|
||||
vbiasall[i][1] = vcm[1] + dx*omega[2]-dz*omega[0];
|
||||
vbiasall[i][2] = vcm[2] + dy*omega[0]-dx*omega[1];
|
||||
|
||||
vthermal[0] = v[i][0] - vbiasall[i][0];
|
||||
vthermal[1] = v[i][1] - vbiasall[i][1];
|
||||
vthermal[2] = v[i][2] - vbiasall[i][2];
|
||||
|
||||
if (rmass) massone = rmass[i];
|
||||
else massone = mass[type[i]];
|
||||
t[0] += massone * vthermal[0]*vthermal[0];
|
||||
t[1] += massone * vthermal[1]*vthermal[1];
|
||||
t[2] += massone * vthermal[2]*vthermal[2];
|
||||
t[3] += massone * vthermal[0]*vthermal[1];
|
||||
t[4] += massone * vthermal[0]*vthermal[2];
|
||||
t[5] += massone * vthermal[1]*vthermal[2];
|
||||
}
|
||||
|
||||
MPI_Allreduce(t,vector,6,MPI_DOUBLE,MPI_SUM,world);
|
||||
for (i = 0; i < 6; i++) vector[i] *= force->mvv2e;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
remove velocity bias from atom I to leave thermal velocity
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void ComputeTempRotate::remove_bias(int i, double *v)
|
||||
{
|
||||
v[0] -= vbiasall[i][0];
|
||||
v[1] -= vbiasall[i][1];
|
||||
v[2] -= vbiasall[i][2];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
remove velocity bias from all atoms to leave thermal velocity
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void ComputeTempRotate::remove_bias_all()
|
||||
{
|
||||
double **v = atom->v;
|
||||
int *mask = atom->mask;
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) {
|
||||
v[i][0] -= vbiasall[i][0];
|
||||
v[i][1] -= vbiasall[i][1];
|
||||
v[i][2] -= vbiasall[i][2];
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
add back in velocity bias to atom I removed by remove_bias()
|
||||
assume remove_bias() was previously called
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void ComputeTempRotate::restore_bias(int i, double *v)
|
||||
{
|
||||
v[0] += vbiasall[i][0];
|
||||
v[1] += vbiasall[i][1];
|
||||
v[2] += vbiasall[i][2];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
add back in velocity bias to all atoms removed by remove_bias_all()
|
||||
assume remove_bias_all() was previously called
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void ComputeTempRotate::restore_bias_all()
|
||||
{
|
||||
double **v = atom->v;
|
||||
int *mask = atom->mask;
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) {
|
||||
v[i][0] += vbiasall[i][0];
|
||||
v[i][1] += vbiasall[i][1];
|
||||
v[i][2] += vbiasall[i][2];
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
double ComputeTempRotate::memory_usage()
|
||||
{
|
||||
double bytes = maxbias * sizeof(double);
|
||||
return bytes;
|
||||
}
|
||||
54
src/USER-MISC/compute_temp_rotate.h
Normal file
54
src/USER-MISC/compute_temp_rotate.h
Normal file
@ -0,0 +1,54 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
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 COMPUTE_CLASS
|
||||
|
||||
ComputeStyle(temp/rotate,ComputeTempRotate)
|
||||
|
||||
#else
|
||||
|
||||
#ifndef LMP_COMPUTE_TEMP_ROTATE_H
|
||||
#define LMP_COMPUTE_TEMP_ROTATE_H
|
||||
|
||||
#include "compute.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
class ComputeTempRotate : public Compute {
|
||||
public:
|
||||
ComputeTempRotate(class LAMMPS *, int, char **);
|
||||
~ComputeTempRotate();
|
||||
void init();
|
||||
double compute_scalar();
|
||||
void compute_vector();
|
||||
|
||||
void remove_bias(int, double *);
|
||||
void remove_bias_all();
|
||||
void restore_bias(int, double *);
|
||||
void restore_bias_all();
|
||||
double memory_usage();
|
||||
|
||||
private:
|
||||
int fix_dof;
|
||||
double tfactor,masstotal;
|
||||
double **vbiasall; // stored velocity bias for all atoms
|
||||
int maxbias; // size of vbiasall array
|
||||
|
||||
void dof_compute(); //without virtual
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
292
src/USER-MISC/fix_addtorque.cpp
Normal file
292
src/USER-MISC/fix_addtorque.cpp
Normal file
@ -0,0 +1,292 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
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: Laurent Joly (U Lyon, France)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "fix_addtorque.h"
|
||||
#include "atom.h"
|
||||
#include "update.h"
|
||||
#include "modify.h"
|
||||
#include "domain.h"
|
||||
#include "respa.h"
|
||||
#include "input.h"
|
||||
#include "variable.h"
|
||||
#include "memory.h"
|
||||
#include "error.h"
|
||||
#include "group.h"
|
||||
#include "force.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
enum{NONE,CONSTANT,EQUAL,ATOM};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixAddTorque::FixAddTorque(LAMMPS *lmp, int narg, char **arg) :
|
||||
Fix(lmp, narg, arg)
|
||||
{
|
||||
if (narg != 6) error->all("Illegal fix addtorque command");
|
||||
|
||||
scalar_flag = 1;
|
||||
vector_flag = 1;
|
||||
size_vector = 3;
|
||||
global_freq = 1;
|
||||
extscalar = 1;
|
||||
extvector = 1;
|
||||
|
||||
xstr = ystr = zstr = NULL;
|
||||
|
||||
if (strstr(arg[3],"v_") == arg[3]) {
|
||||
int n = strlen(&arg[3][2]) + 1;
|
||||
xstr = new char[n];
|
||||
strcpy(xstr,&arg[3][2]);
|
||||
} else {
|
||||
xvalue = atof(arg[3]);
|
||||
xstyle = CONSTANT;
|
||||
}
|
||||
if (strstr(arg[4],"v_") == arg[4]) {
|
||||
int n = strlen(&arg[4][2]) + 1;
|
||||
ystr = new char[n];
|
||||
strcpy(ystr,&arg[4][2]);
|
||||
} else {
|
||||
yvalue = atof(arg[4]);
|
||||
ystyle = CONSTANT;
|
||||
}
|
||||
if (strstr(arg[5],"v_") == arg[5]) {
|
||||
int n = strlen(&arg[5][2]) + 1;
|
||||
zstr = new char[n];
|
||||
strcpy(zstr,&arg[5][2]);
|
||||
} else {
|
||||
zvalue = atof(arg[5]);
|
||||
zstyle = CONSTANT;
|
||||
}
|
||||
|
||||
force_flag = 0;
|
||||
foriginal[0] = foriginal[1] = foriginal[2] = foriginal[3] = 0.0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixAddTorque::~FixAddTorque()
|
||||
{
|
||||
delete [] xstr;
|
||||
delete [] ystr;
|
||||
delete [] zstr;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
int FixAddTorque::setmask()
|
||||
{
|
||||
int mask = 0;
|
||||
mask |= POST_FORCE;
|
||||
mask |= THERMO_ENERGY;
|
||||
mask |= POST_FORCE_RESPA;
|
||||
mask |= MIN_POST_FORCE;
|
||||
return mask;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixAddTorque::init()
|
||||
{
|
||||
// check variables
|
||||
|
||||
if (xstr) {
|
||||
xvar = input->variable->find(xstr);
|
||||
if (xvar < 0) error->all("Variable name for fix addtorque does not exist");
|
||||
if (input->variable->equalstyle(xvar)) xstyle = EQUAL;
|
||||
else error->all("Variable for fix addtorque is invalid style");
|
||||
}
|
||||
if (ystr) {
|
||||
yvar = input->variable->find(ystr);
|
||||
if (yvar < 0) error->all("Variable name for fix addtorque does not exist");
|
||||
if (input->variable->equalstyle(yvar)) ystyle = EQUAL;
|
||||
else error->all("Variable for fix addtorque is invalid style");
|
||||
}
|
||||
if (zstr) {
|
||||
zvar = input->variable->find(zstr);
|
||||
if (zvar < 0) error->all("Variable name for fix addtorque does not exist");
|
||||
if (input->variable->equalstyle(zvar)) zstyle = EQUAL;
|
||||
else error->all("Variable for fix addtorque is invalid style");
|
||||
}
|
||||
|
||||
if (xstyle == EQUAL || ystyle == EQUAL || zstyle == EQUAL)
|
||||
varflag = EQUAL;
|
||||
else varflag = CONSTANT;
|
||||
|
||||
if (strcmp(update->integrate_style,"respa") == 0)
|
||||
nlevels_respa = ((Respa *) update->integrate)->nlevels;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixAddTorque::setup(int vflag)
|
||||
{
|
||||
if (strcmp(update->integrate_style,"verlet") == 0)
|
||||
post_force(vflag);
|
||||
else {
|
||||
((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1);
|
||||
post_force_respa(vflag,nlevels_respa-1,0);
|
||||
((Respa *) update->integrate)->copy_f_flevel(nlevels_respa-1);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixAddTorque::min_setup(int vflag)
|
||||
{
|
||||
post_force(vflag);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixAddTorque::post_force(int vflag)
|
||||
{
|
||||
double **x = atom->x;
|
||||
double **f = atom->f;
|
||||
int *mask = atom->mask;
|
||||
int *type = atom->type;
|
||||
int *image = atom->image;
|
||||
double *mass = atom->mass;
|
||||
double *rmass = atom->rmass;
|
||||
int nlocal = atom->nlocal;
|
||||
double mvv2e = force->mvv2e;
|
||||
|
||||
int xbox,ybox,zbox;
|
||||
double dx,dy,dz,vx,vy,vz,fx,fy,fz,massone,omegadotr;
|
||||
double xprd = domain->xprd;
|
||||
double yprd = domain->yprd;
|
||||
double zprd = domain->zprd;
|
||||
|
||||
double tcm[3],xcm[3],angmom[3],omega[3],itorque[3],domegadt[3],tlocal[3];
|
||||
double inertia[3][3];
|
||||
// foriginal[0] = "potential energy" for added force
|
||||
// foriginal[123] = torque on atoms before extra force added
|
||||
foriginal[0] = foriginal[1] = foriginal[2] = foriginal[3] = 0.0;
|
||||
force_flag = 0;
|
||||
|
||||
if (varflag == EQUAL) {
|
||||
// variable torque, wrap with clear/add
|
||||
modify->clearstep_compute();
|
||||
if (xstyle == EQUAL) xvalue = input->variable->compute_equal(xvar);
|
||||
if (ystyle == EQUAL) yvalue = input->variable->compute_equal(yvar);
|
||||
if (zstyle == EQUAL) zvalue = input->variable->compute_equal(zvar);
|
||||
modify->addstep_compute(update->ntimestep + 1);
|
||||
}
|
||||
|
||||
atom->check_mass();
|
||||
double masstotal = group->mass(igroup);
|
||||
group->xcm(igroup,masstotal,xcm);
|
||||
group->inertia(igroup,xcm,inertia);
|
||||
group->angmom(igroup,xcm,angmom);
|
||||
group->omega(angmom,inertia,omega);
|
||||
|
||||
tlocal[0] = tlocal[1] = tlocal[2] = 0.0;
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) {
|
||||
xbox = (image[i] & 1023) - 512;
|
||||
ybox = (image[i] >> 10 & 1023) - 512;
|
||||
zbox = (image[i] >> 20) - 512;
|
||||
dx = (x[i][0] + xbox*xprd) - xcm[0];
|
||||
dy = (x[i][1] + ybox*yprd) - xcm[1];
|
||||
dz = (x[i][2] + zbox*zprd) - xcm[2];
|
||||
if (rmass) massone = rmass[i];
|
||||
else massone = mass[type[i]];
|
||||
omegadotr = omega[0]*dx+omega[1]*dy+omega[2]*dz;
|
||||
tlocal[0] += massone * omegadotr * (dy*omega[2] - dz*omega[1]);
|
||||
tlocal[1] += massone * omegadotr * (dz*omega[0] - dx*omega[2]);
|
||||
tlocal[2] += massone * omegadotr * (dx*omega[1] - dy*omega[0]);
|
||||
}
|
||||
MPI_Allreduce(tlocal,itorque,3,MPI_DOUBLE,MPI_SUM,world);
|
||||
|
||||
tcm[0] = xvalue - mvv2e*itorque[0];
|
||||
tcm[1] = yvalue - mvv2e*itorque[1];
|
||||
tcm[2] = zvalue - mvv2e*itorque[2];
|
||||
group->omega(tcm,inertia,domegadt);
|
||||
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) {
|
||||
xbox = (image[i] & 1023) - 512;
|
||||
ybox = (image[i] >> 10 & 1023) - 512;
|
||||
zbox = (image[i] >> 20) - 512;
|
||||
dx = (x[i][0] + xbox*xprd) - xcm[0];
|
||||
dy = (x[i][1] + ybox*yprd) - xcm[1];
|
||||
dz = (x[i][2] + zbox*zprd) - xcm[2];
|
||||
vx = mvv2e*(dz*omega[1]-dy*omega[2]);
|
||||
vy = mvv2e*(dx*omega[2]-dz*omega[0]);
|
||||
vz = mvv2e*(dy*omega[0]-dx*omega[1]);
|
||||
if (rmass) massone = rmass[i];
|
||||
else massone = mass[type[i]];
|
||||
fx = massone * (dz*domegadt[1]-dy*domegadt[2] + vz*omega[1]-vy*omega[2]);
|
||||
fy = massone * (dx*domegadt[2]-dz*domegadt[0] + vx*omega[2]-vz*omega[0]);
|
||||
fz = massone * (dy*domegadt[0]-dx*domegadt[1] + vy*omega[0]-vx*omega[1]);
|
||||
|
||||
// potential energy = - x dot f
|
||||
foriginal[0] -= fx*x[i][0] + fy*x[i][1] + fz*x[i][2];
|
||||
foriginal[1] += dy*f[i][2] - dz*f[i][1];
|
||||
foriginal[2] += dz*f[i][0] - dx*f[i][2];
|
||||
foriginal[3] += dx*f[i][1] - dy*f[i][0];
|
||||
f[i][0] += fx;
|
||||
f[i][1] += fy;
|
||||
f[i][2] += fz;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixAddTorque::post_force_respa(int vflag, int ilevel, int iloop)
|
||||
{
|
||||
if (ilevel == nlevels_respa-1) post_force(vflag);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixAddTorque::min_post_force(int vflag)
|
||||
{
|
||||
post_force(vflag);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
potential energy of added torque
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
double FixAddTorque::compute_scalar()
|
||||
{
|
||||
// only sum across procs one time
|
||||
|
||||
if (force_flag == 0) {
|
||||
MPI_Allreduce(foriginal,foriginal_all,4,MPI_DOUBLE,MPI_SUM,world);
|
||||
force_flag = 1;
|
||||
}
|
||||
return foriginal_all[0];
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
return components of total torque on fix group before torque was changed
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
double FixAddTorque::compute_vector(int n)
|
||||
{
|
||||
// only sum across procs one time
|
||||
|
||||
if (force_flag == 0) {
|
||||
MPI_Allreduce(foriginal,foriginal_all,4,MPI_DOUBLE,MPI_SUM,world);
|
||||
force_flag = 1;
|
||||
}
|
||||
return foriginal_all[n+1];
|
||||
}
|
||||
54
src/USER-MISC/fix_addtorque.h
Normal file
54
src/USER-MISC/fix_addtorque.h
Normal file
@ -0,0 +1,54 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
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(addtorque,FixAddTorque)
|
||||
|
||||
#else
|
||||
|
||||
#ifndef LMP_FIX_ADDTORQUE_H
|
||||
#define LMP_FIX_ADDTORQUE_H
|
||||
|
||||
#include "fix.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
class FixAddTorque : public Fix {
|
||||
public:
|
||||
FixAddTorque(class LAMMPS *, int, char **);
|
||||
~FixAddTorque();
|
||||
int setmask();
|
||||
void init();
|
||||
void setup(int);
|
||||
void min_setup(int);
|
||||
void post_force(int);
|
||||
void post_force_respa(int, int, int);
|
||||
void min_post_force(int);
|
||||
double compute_scalar();
|
||||
double compute_vector(int);
|
||||
|
||||
private:
|
||||
double xvalue,yvalue,zvalue;
|
||||
int varflag;
|
||||
char *xstr,*ystr,*zstr;
|
||||
int xvar,yvar,zvar,xstyle,ystyle,zstyle;
|
||||
double foriginal[4],foriginal_all[4];
|
||||
int force_flag;
|
||||
int nlevels_respa;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user