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

This commit is contained in:
sjplimp
2009-11-18 00:59:12 +00:00
parent a66aa5e0f6
commit 5062206d36
8 changed files with 363 additions and 555 deletions

View File

@ -11,212 +11,57 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Mark Stevens (SNL)
------------------------------------------------------------------------- */
#include "math.h"
#include "stdlib.h"
#include "string.h"
#include "fix_wall_lj126.h"
#include "atom.h"
#include "domain.h"
#include "update.h"
#include "output.h"
#include "respa.h"
#include "error.h"
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
FixWallLJ126::FixWallLJ126(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg)
FixWallLJ126::FixWallLJ126(LAMMPS *lmp, int narg, char **arg) :
FixWall(lmp, narg, arg) {}
/* ---------------------------------------------------------------------- */
void FixWallLJ126::precompute(int m)
{
if (narg < 8) error->all("Illegal fix wall/lj126 command");
coeff1[m] = 48.0 * epsilon[m] * pow(sigma[m],12.0);
coeff2[m] = 24.0 * epsilon[m] * pow(sigma[m],6.0);
coeff3[m] = 4.0 * epsilon[m] * pow(sigma[m],12.0);
coeff4[m] = 4.0 * epsilon[m] * pow(sigma[m],6.0);
scalar_flag = 1;
vector_flag = 1;
size_vector = 3;
scalar_vector_freq = 1;
extscalar = 1;
extvector = 1;
// set defaults
if (strcmp(arg[3],"xlo") == 0) {
dim = 0;
side = -1;
} else if (strcmp(arg[3],"xhi") == 0) {
dim = 0;
side = 1;
} else if (strcmp(arg[3],"ylo") == 0) {
dim = 1;
side = -1;
} else if (strcmp(arg[3],"yhi") == 0) {
dim = 1;
side = 1;
} else if (strcmp(arg[3],"zlo") == 0) {
dim = 2;
side = -1;
} else if (strcmp(arg[3],"zhi") == 0) {
dim = 2;
side = 1;
} else error->all("Illegal fix wall/lj126 command");
coord0 = atof(arg[4]);
epsilon = atof(arg[5]);
sigma = atof(arg[6]);
cutoff = atof(arg[7]);
// read options
vel = 0.0;
int iarg = 8;
while (iarg < narg) {
if (strcmp(arg[iarg],"vel") == 0) {
if (iarg+2 > narg) error->all("Illegal fix wall/lj126 command");
vel = atof(arg[iarg+1]);
iarg += 2;
} else error->all("Illegal fix wall/lj126 command");
}
coeff1 = 48.0 * epsilon * pow(sigma,12.0);
coeff2 = 24.0 * epsilon * pow(sigma,6.0);
coeff3 = 4.0 * epsilon * pow(sigma,12.0);
coeff4 = 4.0 * epsilon * pow(sigma,6.0);
double r2inv = 1.0/(cutoff*cutoff);
double r2inv = 1.0/(cutoff[m]*cutoff[m]);
double r6inv = r2inv*r2inv*r2inv;
offset = r6inv*(coeff3*r6inv - coeff4);
if (dim == 0 && domain->xperiodic)
error->all("Cannot use wall in periodic dimension");
if (dim == 1 && domain->yperiodic)
error->all("Cannot use wall in periodic dimension");
if (dim == 2 && domain->zperiodic)
error->all("Cannot use wall in periodic dimension");
wall_flag = 0;
wall[0] = wall[1] = wall[2] = wall[3] = 0.0;
offset[m] = r6inv*(coeff3[m]*r6inv - coeff4[m]);
}
/* ---------------------------------------------------------------------- */
int FixWallLJ126::setmask()
void FixWallLJ126::wall_particle(int m, double coord)
{
int mask = 0;
mask |= POST_FORCE;
mask |= THERMO_ENERGY;
mask |= POST_FORCE_RESPA;
mask |= MIN_POST_FORCE;
return mask;
}
double delta,rinv,r2inv,r6inv,fwall;
/* ---------------------------------------------------------------------- */
void FixWallLJ126::init()
{
if (strcmp(update->integrate_style,"respa") == 0)
nlevels_respa = ((Respa *) update->integrate)->nlevels;
}
/* ---------------------------------------------------------------------- */
void FixWallLJ126::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 FixWallLJ126::min_setup(int vflag)
{
post_force(vflag);
}
/* ---------------------------------------------------------------------- */
void FixWallLJ126::post_force(int vflag)
{
double **x = atom->x;
double **f = atom->f;
int *mask = atom->mask;
int nlocal = atom->nlocal;
double delta,rinv,r2inv,r6inv,fwall;
wall[0] = wall[1] = wall[2] = wall[3] = 0.0;
wall_flag = 0;
// coord = current position of wall
// coord0 = initial position of wall
double delt = (update->ntimestep - update->beginstep) * update->dt;
double coord = coord0 + delt*vel;
int dim = m/2;
int side = m % 2;
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
if (side == -1) delta = x[i][dim] - coord;
if (side == 0) delta = x[i][dim] - coord;
else delta = coord - x[i][dim];
if (delta <= 0.0) continue;
if (delta > cutoff) continue;
if (delta > cutoff[m]) continue;
rinv = 1.0/delta;
r2inv = rinv*rinv;
r6inv = r2inv*r2inv*r2inv;
fwall = side * r6inv*(coeff1*r6inv - coeff2) * rinv;
fwall = side * r6inv*(coeff1[m]*r6inv - coeff2[m]) * rinv;
f[i][dim] -= fwall;
wall[0] += r6inv*(coeff3*r6inv - coeff4) - offset;
wall[dim+1] += fwall;
ewall[0] += r6inv*(coeff3[m]*r6inv - coeff4[m]) - offset[m];
ewall[m+1] += fwall;
}
}
/* ---------------------------------------------------------------------- */
void FixWallLJ126::post_force_respa(int vflag, int ilevel, int iloop)
{
if (ilevel == nlevels_respa-1) post_force(vflag);
}
/* ---------------------------------------------------------------------- */
void FixWallLJ126::min_post_force(int vflag)
{
post_force(vflag);
}
/* ----------------------------------------------------------------------
energy of wall interaction
------------------------------------------------------------------------- */
double FixWallLJ126::compute_scalar()
{
// only sum across procs one time
if (wall_flag == 0) {
MPI_Allreduce(wall,wall_all,4,MPI_DOUBLE,MPI_SUM,world);
wall_flag = 1;
}
return wall_all[0];
}
/* ----------------------------------------------------------------------
components of force on wall
------------------------------------------------------------------------- */
double FixWallLJ126::compute_vector(int n)
{
// only sum across procs one time
if (wall_flag == 0) {
MPI_Allreduce(wall,wall_all,4,MPI_DOUBLE,MPI_SUM,world);
wall_flag = 1;
}
return wall_all[n+1];
}