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

This commit is contained in:
sjplimp 2010-06-01 15:06:14 +00:00
parent 0bf07db002
commit a9cdb2f856
2 changed files with 206 additions and 15 deletions

View File

@ -11,16 +11,22 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "stdlib.h"
#include "string.h"
#include "fix_wall_reflect.h"
#include "atom.h"
#include "comm.h"
#include "modify.h"
#include "domain.h"
#include "lattice.h"
#include "input.h"
#include "variable.h"
#include "error.h"
using namespace LAMMPS_NS;
enum{NONE,EDGE,CONSTANT,VARIABLE};
/* ---------------------------------------------------------------------- */
FixWallReflect::FixWallReflect(LAMMPS *lmp, int narg, char **arg) :
@ -28,17 +34,143 @@ FixWallReflect::FixWallReflect(LAMMPS *lmp, int narg, char **arg) :
{
if (narg < 4) error->all("Illegal fix wall/reflect command");
xloflag = xhiflag = yloflag = yhiflag = zloflag = zhiflag = 0;
for (int iarg = 3; iarg < narg; iarg++) {
if (strcmp(arg[iarg],"xlo") == 0) xloflag = 1;
else if (strcmp(arg[iarg],"xhi") == 0) xhiflag = 1;
else if (strcmp(arg[iarg],"ylo") == 0) yloflag = 1;
else if (strcmp(arg[iarg],"yhi") == 0) yhiflag = 1;
else if (strcmp(arg[iarg],"zlo") == 0) zloflag = 1;
else if (strcmp(arg[iarg],"zhi") == 0) zhiflag = 1;
else error->all("Illegal fix wall/reflect command");
xloflag = xhiflag = yloflag = yhiflag = zloflag = zhiflag = NONE;
xlostr = xhistr = ylostr = yhistr = zlostr = zhistr = NULL;
int scaleflag = 1;
int iarg = 3;
while (iarg < narg) {
if (strcmp(arg[iarg],"xlo") == 0) {
if (iarg+2 > narg) error->all("Illegal fix wall/reflect command");
if (strcmp(arg[iarg+1],"EDGE") == 0) {
xloflag = EDGE;
xlo = domain->boxlo[0];
} else if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) {
xloflag = VARIABLE;
int n = strlen(&arg[iarg+1][2]) + 1;
xlostr = new char[n];
strcpy(xlostr,&arg[iarg+1][2]);
} else {
xloflag = CONSTANT;
xlo = atof(arg[iarg+1]);
}
iarg += 2;
} else if (strcmp(arg[iarg],"xhi") == 0) {
if (iarg+2 > narg) error->all("Illegal fix wall/reflect command");
if (strcmp(arg[iarg+1],"EDGE") == 0) {
xhiflag = EDGE;
xhi = domain->boxhi[0];
} else if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) {
xhiflag = VARIABLE;
int n = strlen(&arg[iarg+1][2]) + 1;
xhistr = new char[n];
strcpy(xhistr,&arg[iarg+1][2]);
} else {
xhiflag = CONSTANT;
xhi = atof(arg[iarg+1]);
}
iarg += 2;
} else if (strcmp(arg[iarg],"ylo") == 0) {
if (iarg+2 > narg) error->all("Illegal fix wall/reflect command");
if (strcmp(arg[iarg+1],"EDGE") == 0) {
yloflag = EDGE;
ylo = domain->boxlo[0];
} else if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) {
yloflag = VARIABLE;
int n = strlen(&arg[iarg+1][2]) + 1;
ylostr = new char[n];
strcpy(ylostr,&arg[iarg+1][2]);
} else {
yloflag = CONSTANT;
ylo = atof(arg[iarg+1]);
}
iarg += 2;
} else if (strcmp(arg[iarg],"yhi") == 0) {
if (iarg+2 > narg) error->all("Illegal fix wall/reflect command");
if (strcmp(arg[iarg+1],"EDGE") == 0) {
yhiflag = EDGE;
yhi = domain->boxhi[0];
} else if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) {
yhiflag = VARIABLE;
int n = strlen(&arg[iarg+1][2]) + 1;
yhistr = new char[n];
strcpy(yhistr,&arg[iarg+1][2]);
} else {
yhiflag = CONSTANT;
yhi = atof(arg[iarg+1]);
}
iarg += 2;
} else if (strcmp(arg[iarg],"zlo") == 0) {
if (iarg+2 > narg) error->all("Illegal fix wall/reflect command");
if (strcmp(arg[iarg+1],"EDGE") == 0) {
zloflag = EDGE;
zlo = domain->boxlo[0];
} else if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) {
zloflag = VARIABLE;
int n = strlen(&arg[iarg+1][2]) + 1;
zlostr = new char[n];
strcpy(zlostr,&arg[iarg+1][2]);
} else {
zloflag = CONSTANT;
zlo = atof(arg[iarg+1]);
}
iarg += 2;
} else if (strcmp(arg[iarg],"zhi") == 0) {
if (iarg+2 > narg) error->all("Illegal fix wall/reflect command");
if (strcmp(arg[iarg+1],"EDGE") == 0) {
zhiflag = EDGE;
zhi = domain->boxhi[0];
} else if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) {
zhiflag = VARIABLE;
int n = strlen(&arg[iarg+1][2]) + 1;
zhistr = new char[n];
strcpy(zhistr,&arg[iarg+1][2]);
} else {
zhiflag = CONSTANT;
zhi = atof(arg[iarg+1]);
}
iarg += 2;
} else if (strcmp(arg[iarg],"units") == 0) {
if (iarg+2 > narg) error->all("Illegal wall/reflect command");
if (strcmp(arg[iarg+1],"box") == 0) scaleflag = 0;
else if (strcmp(arg[iarg+1],"lattice") == 0) scaleflag = 1;
else error->all("Illegal fix wall/reflect command");
iarg += 2;
} else error->all("Illegal fix wall/reflect command");
}
// setup scaling if any wall positions were set as CONSTANT
// apply scaling factors to wall positions
if (xloflag == CONSTANT || xhiflag == CONSTANT ||
yloflag == CONSTANT || yhiflag == CONSTANT ||
zloflag == CONSTANT || zhiflag == CONSTANT) {
if (scaleflag && domain->lattice == NULL)
error->all("Use of fix wall/reflect with undefined lattice");
double xscale,yscale,zscale;
if (scaleflag) {
xscale = domain->lattice->xlattice;
yscale = domain->lattice->ylattice;
zscale = domain->lattice->zlattice;
}
else xscale = yscale = zscale = 1.0;
if (xloflag == CONSTANT) xlo *= xscale;
if (xhiflag == CONSTANT) xhi *= xscale;
if (yloflag == CONSTANT) ylo *= xscale;
if (yhiflag == CONSTANT) yhi *= xscale;
if (zloflag == CONSTANT) zlo *= xscale;
if (zhiflag == CONSTANT) zhi *= xscale;
}
// error checks
if (!xloflag && !xhiflag && !yloflag && !yhiflag && !zloflag && !zhiflag)
error->all("Illegal fix wall/reflect command");
if ((xloflag || xhiflag) && domain->xperiodic)
error->all("Cannot use wall in periodic dimension");
if ((yloflag || yhiflag) && domain->yperiodic)
@ -49,6 +181,18 @@ FixWallReflect::FixWallReflect(LAMMPS *lmp, int narg, char **arg) :
/* ---------------------------------------------------------------------- */
FixWallReflect::~FixWallReflect()
{
delete [] xlostr;
delete [] xhistr;
delete [] ylostr;
delete [] yhistr;
delete [] zlostr;
delete [] zhistr;
}
/* ---------------------------------------------------------------------- */
int FixWallReflect::setmask()
{
int mask = 0;
@ -61,6 +205,49 @@ int FixWallReflect::setmask()
void FixWallReflect::init()
{
if (xlostr) {
xlovar = input->variable->find(xlostr);
if (xlovar < 0)
error->all("Variable name for fix wall/relect does not exist");
if (!input->variable->equalstyle(xlovar))
error->all("Variable for fix wall/reflect is not equal style");
}
if (xhistr) {
xhivar = input->variable->find(xhistr);
if (xhivar < 0)
error->all("Variable name for fix wall/relect does not exist");
if (!input->variable->equalstyle(xhivar))
error->all("Variable for fix wall/reflect is not equal style");
}
if (ylostr) {
ylovar = input->variable->find(ylostr);
if (ylovar < 0)
error->all("Variable name for fix wall/relect does not exist");
if (!input->variable->equalstyle(ylovar))
error->all("Variable for fix wall/reflect is not equal style");
}
if (yhistr) {
yhivar = input->variable->find(yhistr);
if (yhivar < 0)
error->all("Variable name for fix wall/relect does not exist");
if (!input->variable->equalstyle(yhivar))
error->all("Variable for fix wall/reflect is not equal style");
}
if (zlostr) {
zlovar = input->variable->find(zlostr);
if (zlovar < 0)
error->all("Variable name for fix wall/relect does not exist");
if (!input->variable->equalstyle(zlovar))
error->all("Variable for fix wall/reflect is not equal style");
}
if (zhistr) {
zhivar = input->variable->find(zhistr);
if (zhivar < 0)
error->all("Variable name for fix wall/relect does not exist");
if (!input->variable->equalstyle(zhivar))
error->all("Variable for fix wall/reflect is not equal style");
}
int nrigid = 0;
for (int i = 0; i < modify->nfix; i++)
if (modify->fix[i]->rigid_flag) nrigid++;
@ -74,12 +261,12 @@ void FixWallReflect::init()
void FixWallReflect::post_integrate()
{
double xlo = domain->boxlo[0];
double xhi = domain->boxhi[0];
double ylo = domain->boxlo[1];
double yhi = domain->boxhi[1];
double zlo = domain->boxlo[2];
double zhi = domain->boxhi[2];
if (xloflag == VARIABLE) xlo = input->variable->compute_equal(xlovar);
if (xhiflag == VARIABLE) xhi = input->variable->compute_equal(xhivar);
if (yloflag == VARIABLE) ylo = input->variable->compute_equal(ylovar);
if (yhiflag == VARIABLE) yhi = input->variable->compute_equal(yhivar);
if (zloflag == VARIABLE) zlo = input->variable->compute_equal(zlovar);
if (zhiflag == VARIABLE) zhi = input->variable->compute_equal(zhivar);
double **x = atom->x;
double **v = atom->v;

View File

@ -27,12 +27,16 @@ namespace LAMMPS_NS {
class FixWallReflect : public Fix {
public:
FixWallReflect(class LAMMPS *, int, char **);
~FixWallReflect();
int setmask();
void init();
void post_integrate();
private:
int xloflag,xhiflag,yloflag,yhiflag,zloflag,zhiflag;
char *xlostr,*xhistr,*ylostr,*yhistr,*zlostr,*zhistr;
int xlovar,xhivar,ylovar,yhivar,zlovar,zhivar;
double xlo,xhi,ylo,yhi,zlo,zhi;
};
}