2006-11-11 07:52:37 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
2007-01-30 08:22:05 +08:00
|
|
|
http://lammps.sandia.gov, Sandia National Laboratories
|
|
|
|
Steve Plimpton, sjplimp@sandia.gov
|
2006-11-11 07:52:37 +08:00
|
|
|
|
|
|
|
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: Mark Stevens (SNL)
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#include "math.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "fix_wall_lj126.h"
|
|
|
|
#include "atom.h"
|
2007-03-08 08:54:02 +08:00
|
|
|
#include "domain.h"
|
2006-11-11 07:52:37 +08:00
|
|
|
#include "update.h"
|
|
|
|
#include "output.h"
|
|
|
|
#include "respa.h"
|
|
|
|
#include "error.h"
|
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
using namespace LAMMPS_NS;
|
|
|
|
|
2006-11-11 07:52:37 +08:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2007-01-30 08:22:05 +08:00
|
|
|
FixWallLJ126::FixWallLJ126(LAMMPS *lmp, int narg, char **arg) :
|
|
|
|
Fix(lmp, narg, arg)
|
2006-11-11 07:52:37 +08:00
|
|
|
{
|
2008-10-04 10:38:52 +08:00
|
|
|
if (narg < 8) error->all("Illegal fix wall/lj126 command");
|
2006-11-11 07:52:37 +08:00
|
|
|
|
2007-10-10 01:20:33 +08:00
|
|
|
scalar_flag = 1;
|
|
|
|
vector_flag = 1;
|
|
|
|
size_vector = 3;
|
|
|
|
scalar_vector_freq = 1;
|
2008-01-03 03:24:46 +08:00
|
|
|
extscalar = 1;
|
|
|
|
extvector = 1;
|
2007-10-10 01:20:33 +08:00
|
|
|
|
2008-10-04 10:38:52 +08:00
|
|
|
// set defaults
|
|
|
|
|
2008-10-06 22:22:34 +08:00
|
|
|
if (strcmp(arg[3],"xlo") == 0) {
|
2006-11-11 07:52:37 +08:00
|
|
|
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");
|
|
|
|
|
2008-10-04 10:38:52 +08:00
|
|
|
coord0 = atof(arg[4]);
|
2006-11-11 07:52:37 +08:00
|
|
|
epsilon = atof(arg[5]);
|
|
|
|
sigma = atof(arg[6]);
|
|
|
|
cutoff = atof(arg[7]);
|
|
|
|
|
2008-10-06 22:22:34 +08:00
|
|
|
// read options
|
|
|
|
|
|
|
|
vel = 0.0;
|
|
|
|
|
2008-10-04 10:38:52 +08:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2006-11-11 07:52:37 +08:00
|
|
|
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 r6inv = r2inv*r2inv*r2inv;
|
|
|
|
offset = r6inv*(coeff3*r6inv - coeff4);
|
2007-03-08 08:54:02 +08:00
|
|
|
|
|
|
|
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");
|
2008-01-03 03:24:46 +08:00
|
|
|
|
|
|
|
wall_flag = 0;
|
|
|
|
wall[0] = wall[1] = wall[2] = wall[3] = 0.0;
|
2006-11-11 07:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int FixWallLJ126::setmask()
|
|
|
|
{
|
|
|
|
int mask = 0;
|
|
|
|
mask |= POST_FORCE;
|
2007-01-30 08:22:05 +08:00
|
|
|
mask |= THERMO_ENERGY;
|
2006-11-11 07:52:37 +08:00
|
|
|
mask |= POST_FORCE_RESPA;
|
|
|
|
mask |= MIN_POST_FORCE;
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixWallLJ126::init()
|
|
|
|
{
|
|
|
|
if (strcmp(update->integrate_style,"respa") == 0)
|
|
|
|
nlevels_respa = ((Respa *) update->integrate)->nlevels;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2008-01-10 05:56:57 +08:00
|
|
|
void FixWallLJ126::setup(int vflag)
|
2006-11-11 07:52:37 +08:00
|
|
|
{
|
|
|
|
if (strcmp(update->integrate_style,"verlet") == 0)
|
2008-01-10 05:56:57 +08:00
|
|
|
post_force(vflag);
|
2006-11-11 07:52:37 +08:00
|
|
|
else {
|
|
|
|
((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1);
|
2008-01-10 05:56:57 +08:00
|
|
|
post_force_respa(vflag,nlevels_respa-1,0);
|
2006-11-11 07:52:37 +08:00
|
|
|
((Respa *) update->integrate)->copy_f_flevel(nlevels_respa-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2008-01-10 05:56:57 +08:00
|
|
|
void FixWallLJ126::min_setup(int vflag)
|
2006-11-11 07:52:37 +08:00
|
|
|
{
|
2008-01-10 05:56:57 +08:00
|
|
|
post_force(vflag);
|
2006-11-11 07:52:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void FixWallLJ126::post_force(int vflag)
|
|
|
|
{
|
|
|
|
double **x = atom->x;
|
|
|
|
double **f = atom->f;
|
|
|
|
int *mask = atom->mask;
|
|
|
|
int nlocal = atom->nlocal;
|
|
|
|
|
2007-10-10 01:20:33 +08:00
|
|
|
double delta,rinv,r2inv,r6inv,fwall;
|
|
|
|
wall[0] = wall[1] = wall[2] = wall[3] = 0.0;
|
|
|
|
wall_flag = 0;
|
2006-11-11 07:52:37 +08:00
|
|
|
|
2008-10-04 10:38:52 +08:00
|
|
|
// coord = current position of wall
|
|
|
|
// coord0 = initial position of wall
|
|
|
|
|
|
|
|
double delt = (update->ntimestep - update->beginstep) * update->dt;
|
|
|
|
double coord = coord0 + delt*vel;
|
|
|
|
|
2006-11-11 07:52:37 +08:00
|
|
|
for (int i = 0; i < nlocal; i++)
|
|
|
|
if (mask[i] & groupbit) {
|
|
|
|
if (side == -1) delta = x[i][dim] - coord;
|
|
|
|
else delta = coord - x[i][dim];
|
|
|
|
if (delta <= 0.0) continue;
|
|
|
|
if (delta > cutoff) continue;
|
|
|
|
rinv = 1.0/delta;
|
|
|
|
r2inv = rinv*rinv;
|
|
|
|
r6inv = r2inv*r2inv*r2inv;
|
2008-02-19 23:35:29 +08:00
|
|
|
fwall = side * r6inv*(coeff1*r6inv - coeff2) * rinv;
|
2007-10-10 01:20:33 +08:00
|
|
|
f[i][dim] -= fwall;
|
|
|
|
wall[0] += r6inv*(coeff3*r6inv - coeff4) - offset;
|
2007-11-14 06:39:12 +08:00
|
|
|
wall[dim+1] += fwall;
|
2006-11-11 07:52:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-10-10 01:20:33 +08:00
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
energy of wall interaction
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
double FixWallLJ126::compute_scalar()
|
|
|
|
{
|
|
|
|
// only sum across procs one time
|
2006-11-11 07:52:37 +08:00
|
|
|
|
2007-10-10 01:20:33 +08:00
|
|
|
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)
|
2006-11-11 07:52:37 +08:00
|
|
|
{
|
2007-10-10 01:20:33 +08:00
|
|
|
// only sum across procs one time
|
|
|
|
|
|
|
|
if (wall_flag == 0) {
|
|
|
|
MPI_Allreduce(wall,wall_all,4,MPI_DOUBLE,MPI_SUM,world);
|
|
|
|
wall_flag = 1;
|
|
|
|
}
|
2007-11-14 03:47:52 +08:00
|
|
|
return wall_all[n+1];
|
2006-11-11 07:52:37 +08:00
|
|
|
}
|