forked from lijiext/lammps
git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8210 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
parent
cb7dd67f25
commit
f8f88f1508
|
@ -20,6 +20,9 @@
|
|||
#include "update.h"
|
||||
#include "domain.h"
|
||||
#include "respa.h"
|
||||
#include "modify.h"
|
||||
#include "input.h"
|
||||
#include "variable.h"
|
||||
#include "math_const.h"
|
||||
#include "error.h"
|
||||
|
||||
|
@ -27,7 +30,8 @@ using namespace LAMMPS_NS;
|
|||
using namespace FixConst;
|
||||
using namespace MathConst;
|
||||
|
||||
enum{CHUTE,SPHERICAL,GRADIENT,VECTOR};
|
||||
enum{CHUTE,SPHERICAL,VECTOR};
|
||||
enum{CONSTANT,EQUAL};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
|
@ -36,64 +40,92 @@ FixGravity::FixGravity(LAMMPS *lmp, int narg, char **arg) :
|
|||
{
|
||||
if (narg < 5) error->all(FLERR,"Illegal fix gravity command");
|
||||
|
||||
time_depend = 1;
|
||||
scalar_flag = 1;
|
||||
global_freq = 1;
|
||||
extscalar = 1;
|
||||
|
||||
magnitude = atof(arg[3]);
|
||||
mstr = vstr = pstr = tstr = xstr = ystr = zstr = NULL;
|
||||
mstyle = vstyle = pstyle = tstyle = xstyle = ystyle = zstyle = CONSTANT;
|
||||
|
||||
if (strstr(arg[3],"v_") == arg[3]) {
|
||||
int n = strlen(&arg[3][2]) + 1;
|
||||
mstr = new char[n];
|
||||
strcpy(mstr,&arg[3][2]);
|
||||
mstyle = EQUAL;
|
||||
} else {
|
||||
magnitude = atof(arg[3]);
|
||||
mstyle = CONSTANT;
|
||||
}
|
||||
|
||||
if (strcmp(arg[4],"chute") == 0) {
|
||||
if (narg != 6) error->all(FLERR,"Illegal fix gravity command");
|
||||
style = CHUTE;
|
||||
phi = 0.0;
|
||||
theta = 180.0 - atof(arg[5]);
|
||||
if (strstr(arg[5],"v_") == arg[5]) {
|
||||
int n = strlen(&arg[5][2]) + 1;
|
||||
vstr = new char[n];
|
||||
strcpy(vstr,&arg[5][2]);
|
||||
vstyle = EQUAL;
|
||||
} else {
|
||||
vert = atof(arg[5]);
|
||||
vstyle = CONSTANT;
|
||||
}
|
||||
|
||||
} else if (strcmp(arg[4],"spherical") == 0) {
|
||||
if (narg != 7) error->all(FLERR,"Illegal fix gravity command");
|
||||
style = SPHERICAL;
|
||||
phi = atof(arg[5]);
|
||||
theta = atof(arg[6]);
|
||||
} else if (strcmp(arg[4],"gradient") == 0) {
|
||||
if (narg != 9) error->all(FLERR,"Illegal fix gravity command");
|
||||
style = GRADIENT;
|
||||
phi = atof(arg[5]);
|
||||
theta = atof(arg[6]);
|
||||
phigrad = atof(arg[7]);
|
||||
thetagrad = atof(arg[8]);
|
||||
if (strstr(arg[5],"v_") == arg[5]) {
|
||||
int n = strlen(&arg[5][2]) + 1;
|
||||
pstr = new char[n];
|
||||
strcpy(pstr,&arg[5][2]);
|
||||
pstyle = EQUAL;
|
||||
} else {
|
||||
phi = atof(arg[5]);
|
||||
pstyle = CONSTANT;
|
||||
}
|
||||
if (strstr(arg[6],"v_") == arg[6]) {
|
||||
int n = strlen(&arg[6][2]) + 1;
|
||||
tstr = new char[n];
|
||||
strcpy(tstr,&arg[6][2]);
|
||||
tstyle = EQUAL;
|
||||
} else {
|
||||
theta = atof(arg[6]);
|
||||
tstyle = CONSTANT;
|
||||
}
|
||||
|
||||
} else if (strcmp(arg[4],"vector") == 0) {
|
||||
if (narg != 8) error->all(FLERR,"Illegal fix gravity command");
|
||||
style = VECTOR;
|
||||
xdir = atof(arg[5]);
|
||||
ydir = atof(arg[6]);
|
||||
zdir = atof(arg[7]);
|
||||
if (strstr(arg[5],"v_") == arg[5]) {
|
||||
int n = strlen(&arg[5][2]) + 1;
|
||||
xstr = new char[n];
|
||||
strcpy(xstr,&arg[5][2]);
|
||||
xstyle = EQUAL;
|
||||
} else {
|
||||
xdir = atof(arg[5]);
|
||||
xstyle = CONSTANT;
|
||||
}
|
||||
if (strstr(arg[6],"v_") == arg[6]) {
|
||||
int n = strlen(&arg[6][2]) + 1;
|
||||
ystr = new char[n];
|
||||
strcpy(ystr,&arg[6][2]);
|
||||
ystyle = EQUAL;
|
||||
} else {
|
||||
ydir = atof(arg[6]);
|
||||
ystyle = CONSTANT;
|
||||
}
|
||||
if (strstr(arg[7],"v_") == arg[7]) {
|
||||
int n = strlen(&arg[7][2]) + 1;
|
||||
zstr = new char[n];
|
||||
strcpy(zstr,&arg[7][2]);
|
||||
zstyle = EQUAL;
|
||||
} else {
|
||||
zdir = atof(arg[7]);
|
||||
zstyle = CONSTANT;
|
||||
}
|
||||
|
||||
} else error->all(FLERR,"Illegal fix gravity command");
|
||||
|
||||
degree2rad = MY_PI/180.0;
|
||||
|
||||
if (style == CHUTE || style == SPHERICAL || style == GRADIENT) {
|
||||
if (domain->dimension == 3) {
|
||||
xgrav = sin(degree2rad * theta) * cos(degree2rad * phi);
|
||||
ygrav = sin(degree2rad * theta) * sin(degree2rad * phi);
|
||||
zgrav = cos(degree2rad * theta);
|
||||
} else {
|
||||
xgrav = sin(degree2rad * theta);
|
||||
ygrav = cos(degree2rad * theta);
|
||||
zgrav = 0.0;
|
||||
}
|
||||
} else if (style == VECTOR) {
|
||||
if (domain->dimension == 3) {
|
||||
double length = sqrt(xdir*xdir + ydir*ydir + zdir*zdir);
|
||||
xgrav = xdir/length;
|
||||
ygrav = ydir/length;
|
||||
zgrav = zdir/length;
|
||||
} else {
|
||||
double length = sqrt(xdir*xdir + ydir*ydir);
|
||||
xgrav = xdir/length;
|
||||
ygrav = ydir/length;
|
||||
zgrav = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
time_origin = update->ntimestep;
|
||||
|
||||
eflag = 0;
|
||||
|
@ -102,6 +134,19 @@ FixGravity::FixGravity(LAMMPS *lmp, int narg, char **arg) :
|
|||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixGravity::~FixGravity()
|
||||
{
|
||||
delete [] mstr;
|
||||
delete [] vstr;
|
||||
delete [] pstr;
|
||||
delete [] tstr;
|
||||
delete [] xstr;
|
||||
delete [] ystr;
|
||||
delete [] zstr;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
int FixGravity::setmask()
|
||||
{
|
||||
int mask = 0;
|
||||
|
@ -118,11 +163,66 @@ void FixGravity::init()
|
|||
if (strstr(update->integrate_style,"respa"))
|
||||
nlevels_respa = ((Respa *) update->integrate)->nlevels;
|
||||
|
||||
dt = update->dt;
|
||||
// check variables
|
||||
|
||||
xacc = magnitude*xgrav;
|
||||
yacc = magnitude*ygrav;
|
||||
zacc = magnitude*zgrav;
|
||||
if (mstr) {
|
||||
mvar = input->variable->find(mstr);
|
||||
if (mvar < 0)
|
||||
error->all(FLERR,"Variable name for fix gravity does not exist");
|
||||
if (!input->variable->equalstyle(mvar))
|
||||
error->all(FLERR,"Variable for fix gravity is invalid style");
|
||||
}
|
||||
if (vstr) {
|
||||
vvar = input->variable->find(vstr);
|
||||
if (vvar < 0)
|
||||
error->all(FLERR,"Variable name for fix gravity does not exist");
|
||||
if (!input->variable->equalstyle(vvar))
|
||||
error->all(FLERR,"Variable for fix gravity is invalid style");
|
||||
}
|
||||
if (pstr) {
|
||||
pvar = input->variable->find(pstr);
|
||||
if (pvar < 0)
|
||||
error->all(FLERR,"Variable name for fix gravity does not exist");
|
||||
if (!input->variable->equalstyle(pvar))
|
||||
error->all(FLERR,"Variable for fix gravity is invalid style");
|
||||
}
|
||||
if (tstr) {
|
||||
tvar = input->variable->find(tstr);
|
||||
if (tvar < 0)
|
||||
error->all(FLERR,"Variable name for fix gravity does not exist");
|
||||
if (!input->variable->equalstyle(tvar))
|
||||
error->all(FLERR,"Variable for fix gravity is invalid style");
|
||||
}
|
||||
if (xstr) {
|
||||
xvar = input->variable->find(xstr);
|
||||
if (xvar < 0)
|
||||
error->all(FLERR,"Variable name for fix gravity does not exist");
|
||||
if (!input->variable->equalstyle(xvar))
|
||||
error->all(FLERR,"Variable for fix gravity is invalid style");
|
||||
}
|
||||
if (ystr) {
|
||||
yvar = input->variable->find(ystr);
|
||||
if (yvar < 0)
|
||||
error->all(FLERR,"Variable name for fix gravity does not exist");
|
||||
if (!input->variable->equalstyle(yvar))
|
||||
error->all(FLERR,"Variable for fix gravity is invalid style");
|
||||
}
|
||||
if (zstr) {
|
||||
zvar = input->variable->find(zstr);
|
||||
if (zvar < 0)
|
||||
error->all(FLERR,"Variable name for fix gravity does not exist");
|
||||
if (!input->variable->equalstyle(zvar))
|
||||
error->all(FLERR,"Variable for fix gravity is invalid style");
|
||||
}
|
||||
|
||||
varflag = CONSTANT;
|
||||
if (mstyle != CONSTANT || vstyle != CONSTANT || pstyle != CONSTANT ||
|
||||
tstyle != CONSTANT || xstyle != CONSTANT || ystyle != CONSTANT ||
|
||||
zstyle != CONSTANT) varflag = EQUAL;
|
||||
|
||||
// set gravity components once and for all
|
||||
|
||||
if (varflag == CONSTANT) set_acceleration();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
@ -142,26 +242,20 @@ void FixGravity::setup(int vflag)
|
|||
|
||||
void FixGravity::post_force(int vflag)
|
||||
{
|
||||
// update direction of gravity vector if gradient style
|
||||
// update gravity due to variables
|
||||
|
||||
if (style == GRADIENT) {
|
||||
if (domain->dimension == 3) {
|
||||
double phi_current = degree2rad *
|
||||
(phi + (update->ntimestep - time_origin)*dt*phigrad*360.0);
|
||||
double theta_current = degree2rad *
|
||||
(theta + (update->ntimestep - time_origin)*dt*thetagrad*360.0);
|
||||
xgrav = sin(theta_current) * cos(phi_current);
|
||||
ygrav = sin(theta_current) * sin(phi_current);
|
||||
zgrav = cos(theta_current);
|
||||
} else {
|
||||
double theta_current = degree2rad *
|
||||
(theta + (update->ntimestep - time_origin)*dt*thetagrad*360.0);
|
||||
xgrav = sin(theta_current);
|
||||
ygrav = cos(theta_current);
|
||||
}
|
||||
xacc = magnitude*xgrav;
|
||||
yacc = magnitude*ygrav;
|
||||
zacc = magnitude*zgrav;
|
||||
if (varflag != CONSTANT) {
|
||||
modify->clearstep_compute();
|
||||
if (mstyle == EQUAL) magnitude = input->variable->compute_equal(mvar);
|
||||
if (vstyle == EQUAL) magnitude = input->variable->compute_equal(vvar);
|
||||
if (pstyle == EQUAL) magnitude = input->variable->compute_equal(pvar);
|
||||
if (tstyle == EQUAL) magnitude = input->variable->compute_equal(tvar);
|
||||
if (xstyle == EQUAL) magnitude = input->variable->compute_equal(xvar);
|
||||
if (ystyle == EQUAL) magnitude = input->variable->compute_equal(yvar);
|
||||
if (zstyle == EQUAL) magnitude = input->variable->compute_equal(zvar);
|
||||
modify->addstep_compute(update->ntimestep + 1);
|
||||
|
||||
set_acceleration();
|
||||
}
|
||||
|
||||
double **x = atom->x;
|
||||
|
@ -204,6 +298,43 @@ void FixGravity::post_force_respa(int vflag, int ilevel, int iloop)
|
|||
if (ilevel == nlevels_respa-1) post_force(vflag);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void FixGravity::set_acceleration()
|
||||
{
|
||||
if (style == CHUTE || style == SPHERICAL) {
|
||||
if (style == CHUTE) {
|
||||
phi = 0.0;
|
||||
theta = 180.0 - vert;
|
||||
}
|
||||
if (domain->dimension == 3) {
|
||||
xgrav = sin(degree2rad * theta) * cos(degree2rad * phi);
|
||||
ygrav = sin(degree2rad * theta) * sin(degree2rad * phi);
|
||||
zgrav = cos(degree2rad * theta);
|
||||
} else {
|
||||
xgrav = sin(degree2rad * theta);
|
||||
ygrav = cos(degree2rad * theta);
|
||||
zgrav = 0.0;
|
||||
}
|
||||
} else if (style == VECTOR) {
|
||||
if (domain->dimension == 3) {
|
||||
double length = sqrt(xdir*xdir + ydir*ydir + zdir*zdir);
|
||||
xgrav = xdir/length;
|
||||
ygrav = ydir/length;
|
||||
zgrav = zdir/length;
|
||||
} else {
|
||||
double length = sqrt(xdir*xdir + ydir*ydir);
|
||||
xgrav = xdir/length;
|
||||
ygrav = ydir/length;
|
||||
zgrav = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
xacc = magnitude*xgrav;
|
||||
yacc = magnitude*ygrav;
|
||||
zacc = magnitude*zgrav;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
potential energy in gravity field
|
||||
------------------------------------------------------------------------- */
|
||||
|
|
|
@ -29,6 +29,7 @@ class FixGravity : public Fix {
|
|||
|
||||
public:
|
||||
FixGravity(class LAMMPS *, int, char **);
|
||||
~FixGravity();
|
||||
int setmask();
|
||||
void init();
|
||||
void setup(int);
|
||||
|
@ -38,8 +39,8 @@ class FixGravity : public Fix {
|
|||
|
||||
protected:
|
||||
int style;
|
||||
double magnitude,dt;
|
||||
double phi,theta,phigrad,thetagrad;
|
||||
double magnitude;
|
||||
double vert,phi,theta;
|
||||
double xdir,ydir,zdir;
|
||||
double xgrav,ygrav,zgrav,xacc,yacc,zacc;
|
||||
double degree2rad;
|
||||
|
@ -47,6 +48,13 @@ class FixGravity : public Fix {
|
|||
int time_origin;
|
||||
int eflag;
|
||||
double egrav,egrav_all;
|
||||
|
||||
int varflag;
|
||||
int mstyle,vstyle,pstyle,tstyle,xstyle,ystyle,zstyle;
|
||||
int mvar,vvar,pvar,tvar,xvar,yvar,zvar;
|
||||
char *mstr,*vstr,*pstr,*tstr,*xstr,*ystr,*zstr;
|
||||
|
||||
void set_acceleration();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -50,7 +50,6 @@ FixMove::FixMove(LAMMPS *lmp, int narg, char **arg) :
|
|||
size_peratom_cols = 3;
|
||||
peratom_freq = 1;
|
||||
time_integrate = 1;
|
||||
time_depend = 1;
|
||||
create_attribute = 1;
|
||||
|
||||
// parse args
|
||||
|
@ -177,9 +176,11 @@ FixMove::FixMove(LAMMPS *lmp, int narg, char **arg) :
|
|||
if (mstyle == WIGGLE && azflag && az != 0.0)
|
||||
error->all(FLERR,"Fix move cannot set wiggle z motion for 2d problem");
|
||||
if (mstyle == ROTATE && (axis[0] != 0.0 || axis[1] != 0.0))
|
||||
error->all(FLERR,"Fix move cannot rotate aroung non z-axis for 2d problem");
|
||||
error->all(FLERR,
|
||||
"Fix move cannot rotate aroung non z-axis for 2d problem");
|
||||
if (mstyle == VARIABLE && (zvarstr || vzvarstr))
|
||||
error->all(FLERR,"Fix move cannot define z or vz variable for 2d problem");
|
||||
error->all(FLERR,
|
||||
"Fix move cannot define z or vz variable for 2d problem");
|
||||
}
|
||||
|
||||
if (atom->angmom_flag && comm->me == 0)
|
||||
|
@ -310,42 +311,48 @@ void FixMove::init()
|
|||
if (mstyle == VARIABLE) {
|
||||
if (xvarstr) {
|
||||
xvar = input->variable->find(xvarstr);
|
||||
if (xvar < 0) error->all(FLERR,"Variable name for fix move does not exist");
|
||||
if (xvar < 0) error->all(FLERR,
|
||||
"Variable name for fix move does not exist");
|
||||
if (input->variable->equalstyle(xvar)) xvarstyle = EQUAL;
|
||||
else if (input->variable->atomstyle(xvar)) xvarstyle = ATOM;
|
||||
else error->all(FLERR,"Variable for fix move is invalid style");
|
||||
}
|
||||
if (yvarstr) {
|
||||
yvar = input->variable->find(yvarstr);
|
||||
if (yvar < 0) error->all(FLERR,"Variable name for fix move does not exist");
|
||||
if (yvar < 0) error->all(FLERR,
|
||||
"Variable name for fix move does not exist");
|
||||
if (input->variable->equalstyle(yvar)) yvarstyle = EQUAL;
|
||||
else if (input->variable->atomstyle(yvar)) yvarstyle = ATOM;
|
||||
else error->all(FLERR,"Variable for fix move is invalid style");
|
||||
}
|
||||
if (zvarstr) {
|
||||
zvar = input->variable->find(zvarstr);
|
||||
if (zvar < 0) error->all(FLERR,"Variable name for fix move does not exist");
|
||||
if (zvar < 0) error->all(FLERR,
|
||||
"Variable name for fix move does not exist");
|
||||
if (input->variable->equalstyle(zvar)) zvarstyle = EQUAL;
|
||||
else if (input->variable->atomstyle(zvar)) zvarstyle = ATOM;
|
||||
else error->all(FLERR,"Variable for fix move is invalid style");
|
||||
}
|
||||
if (vxvarstr) {
|
||||
vxvar = input->variable->find(vxvarstr);
|
||||
if (vxvar < 0) error->all(FLERR,"Variable name for fix move does not exist");
|
||||
if (vxvar < 0) error->all(FLERR,
|
||||
"Variable name for fix move does not exist");
|
||||
if (input->variable->equalstyle(vxvar)) vxvarstyle = EQUAL;
|
||||
else if (input->variable->atomstyle(vxvar)) vxvarstyle = ATOM;
|
||||
else error->all(FLERR,"Variable for fix move is invalid style");
|
||||
}
|
||||
if (vyvarstr) {
|
||||
vyvar = input->variable->find(vyvarstr);
|
||||
if (vyvar < 0) error->all(FLERR,"Variable name for fix move does not exist");
|
||||
if (vyvar < 0) error->all(FLERR,
|
||||
"Variable name for fix move does not exist");
|
||||
if (input->variable->equalstyle(vyvar)) vyvarstyle = EQUAL;
|
||||
else if (input->variable->atomstyle(vyvar)) vyvarstyle = ATOM;
|
||||
else error->all(FLERR,"Variable for fix move is invalid style");
|
||||
}
|
||||
if (vzvarstr) {
|
||||
vzvar = input->variable->find(vzvarstr);
|
||||
if (vzvar < 0) error->all(FLERR,"Variable name for fix move does not exist");
|
||||
if (vzvar < 0) error->all(FLERR,
|
||||
"Variable name for fix move does not exist");
|
||||
if (input->variable->equalstyle(vzvar)) vzvarstyle = EQUAL;
|
||||
else if (input->variable->atomstyle(vzvar)) vzvarstyle = ATOM;
|
||||
else error->all(FLERR,"Variable for fix move is invalid style");
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
Contributing author: Timothy Sirk (U Vermont)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "lmptype.h"
|
||||
#include "mpi.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
|
|
Loading…
Reference in New Issue