git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13618 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
@ -36,7 +36,7 @@ FixMomentum::FixMomentum(LAMMPS *lmp, int narg, char **arg) :
|
||||
nevery = force->inumeric(FLERR,arg[3]);
|
||||
if (nevery <= 0) error->all(FLERR,"Illegal fix momentum command");
|
||||
|
||||
linear = angular = 0;
|
||||
linear = angular = rescale = 0;
|
||||
|
||||
int iarg = 4;
|
||||
while (iarg < narg) {
|
||||
@ -50,6 +50,9 @@ FixMomentum::FixMomentum(LAMMPS *lmp, int narg, char **arg) :
|
||||
} else if (strcmp(arg[iarg],"angular") == 0) {
|
||||
angular = 1;
|
||||
iarg += 1;
|
||||
} else if (strcmp(arg[iarg],"rescale") == 0) {
|
||||
rescale = 1;
|
||||
iarg += 1;
|
||||
} else error->all(FLERR,"Illegal fix momentum command");
|
||||
}
|
||||
|
||||
@ -87,6 +90,35 @@ void FixMomentum::init()
|
||||
|
||||
void FixMomentum::end_of_step()
|
||||
{
|
||||
double **v = atom->v;
|
||||
int *mask = atom->mask;
|
||||
const int nlocal = atom->nlocal;
|
||||
double ekin_old,ekin_new;
|
||||
ekin_old = ekin_new = 0.0;
|
||||
|
||||
// compute kinetic energy before momentum removal, if needed
|
||||
|
||||
if (rescale) {
|
||||
|
||||
double *rmass = atom->rmass;
|
||||
double *mass = atom->mass;
|
||||
int *type = atom->type;
|
||||
double ke=0.0;
|
||||
|
||||
if (rmass) {
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit)
|
||||
ke += rmass[i] *
|
||||
(v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2]);
|
||||
} else {
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit)
|
||||
ke += mass[type[i]] *
|
||||
(v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2]);
|
||||
}
|
||||
MPI_Allreduce(&ke,&ekin_old,1,MPI_DOUBLE,MPI_SUM,world);
|
||||
}
|
||||
|
||||
if (linear) {
|
||||
double vcm[3];
|
||||
group->vcm(igroup,masstotal,vcm);
|
||||
@ -94,10 +126,6 @@ void FixMomentum::end_of_step()
|
||||
// adjust velocities by vcm to zero linear momentum
|
||||
// only adjust a component if flag is set
|
||||
|
||||
double **v = atom->v;
|
||||
int *mask = atom->mask;
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) {
|
||||
if (xflag) v[i][0] -= vcm[0];
|
||||
@ -137,4 +165,36 @@ void FixMomentum::end_of_step()
|
||||
v[i][2] -= omega[0]*dy - omega[1]*dx;
|
||||
}
|
||||
}
|
||||
|
||||
// compute kinetic energy after momentum removal, if needed
|
||||
|
||||
if (rescale) {
|
||||
|
||||
double ke=0.0, factor=1.0;
|
||||
double *rmass = atom->rmass;
|
||||
double *mass = atom->mass;
|
||||
int *type = atom->type;
|
||||
|
||||
if (rmass) {
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit)
|
||||
ke += rmass[i] *
|
||||
(v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2]);
|
||||
} else {
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit)
|
||||
ke += mass[type[i]] *
|
||||
(v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2]);
|
||||
}
|
||||
MPI_Allreduce(&ke,&ekin_new,1,MPI_DOUBLE,MPI_SUM,world);
|
||||
|
||||
if (ekin_new != 0.0) factor = sqrt(ekin_old/ekin_new);
|
||||
for (int i = 0; i < nlocal; i++) {
|
||||
if (mask[i] & groupbit) {
|
||||
v[i][0] *= factor;
|
||||
v[i][1] *= factor;
|
||||
v[i][2] *= factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user