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

This commit is contained in:
sjplimp 2015-10-23 17:00:52 +00:00
parent e53f61a869
commit 08157510b7
4 changed files with 65 additions and 24 deletions

View File

@ -26,6 +26,9 @@
#include "random_park.h" #include "random_park.h"
#include "error.h" #include "error.h"
#include "force.h" #include "force.h"
#include "input.h"
#include "variable.h"
#include "memory.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace MathConst; using namespace MathConst;
@ -34,7 +37,17 @@ enum{MOVE,RAMP,RANDOM,ROTATE};
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
DisplaceAtoms::DisplaceAtoms(LAMMPS *lmp) : Pointers(lmp) {} DisplaceAtoms::DisplaceAtoms(LAMMPS *lmp) : Pointers(lmp)
{
mvec = NULL;
}
/* ---------------------------------------------------------------------- */
DisplaceAtoms::~DisplaceAtoms()
{
memory->destroy(mvec);
}
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
@ -53,9 +66,9 @@ void DisplaceAtoms::command(int narg, char **arg)
// group and style // group and style
int igroup = group->find(arg[0]); igroup = group->find(arg[0]);
if (igroup == -1) error->all(FLERR,"Could not find displace_atoms group ID"); if (igroup == -1) error->all(FLERR,"Could not find displace_atoms group ID");
int groupbit = group->bitmask[igroup]; groupbit = group->bitmask[igroup];
int style = -1; int style = -1;
if (strcmp(arg[1],"move") == 0) style = MOVE; if (strcmp(arg[1],"move") == 0) style = MOVE;
@ -85,25 +98,12 @@ void DisplaceAtoms::command(int narg, char **arg)
} }
else xscale = yscale = zscale = 1.0; else xscale = yscale = zscale = 1.0;
// move atoms by 3-vector // move atoms by 3-vector or specified variable(s)
if (style == MOVE) { if (style == MOVE) {
move(0,arg[2],xscale);
double delx = xscale*force->numeric(FLERR,arg[2]); move(1,arg[3],yscale);
double dely = yscale*force->numeric(FLERR,arg[3]); move(2,arg[4],zscale);
double delz = zscale*force->numeric(FLERR,arg[4]);
double **x = atom->x;
int *mask = atom->mask;
int nlocal = atom->nlocal;
for (i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
x[i][0] += delx;
x[i][1] += dely;
x[i][2] += delz;
}
}
} }
// move atoms in ramped fashion // move atoms in ramped fashion
@ -286,6 +286,42 @@ void DisplaceAtoms::command(int narg, char **arg)
} }
} }
/* ----------------------------------------------------------------------
move atoms either by specified numeric displacement or variable evaluation
------------------------------------------------------------------------- */
void DisplaceAtoms::move(int idim, char *arg, double scale)
{
double **x = atom->x;
int *mask = atom->mask;
int nlocal = atom->nlocal;
if (strstr(arg,"v_") != arg) {
double delta = scale*force->numeric(FLERR,arg);
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) x[i][idim] += delta;
} else {
int n = strlen(&arg[2]) + 1;
char *vstr = new char[n];
strcpy(vstr,&arg[2]);
int ivar = input->variable->find(vstr);
if (ivar < 0)
error->all(FLERR,"Variable name for displace_atoms does not exist");
if (input->variable->equalstyle(ivar)) {
double delta = scale * input->variable->compute_equal(ivar);
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) x[i][idim] += delta;
} else if (input->variable->atomstyle(ivar)) {
if (mvec == NULL) memory->create(mvec,nlocal,"displace_atoms:mvec");
input->variable->compute_atom(ivar,igroup,mvec,1,0);
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit) x[i][idim] += scale*mvec[i];
} else error->all(FLERR,"Variable for displace_atoms is invalid style");
}
}
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
parse optional parameters at end of displace_atoms input line parse optional parameters at end of displace_atoms input line
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */

View File

@ -27,10 +27,15 @@ namespace LAMMPS_NS {
class DisplaceAtoms : protected Pointers { class DisplaceAtoms : protected Pointers {
public: public:
DisplaceAtoms(class LAMMPS *); DisplaceAtoms(class LAMMPS *);
~DisplaceAtoms();
void command(int, char **); void command(int, char **);
private: private:
int igroup,groupbit;
int scaleflag; int scaleflag;
double *mvec;
void move(int, char *, double);
void options(int, char **); void options(int, char **);
}; };

View File

@ -112,7 +112,7 @@ FixAddForce::FixAddForce(LAMMPS *lmp, int narg, char **arg) :
force_flag = 0; force_flag = 0;
foriginal[0] = foriginal[1] = foriginal[2] = foriginal[3] = 0.0; foriginal[0] = foriginal[1] = foriginal[2] = foriginal[3] = 0.0;
maxatom = atom->nmax; maxatom = 1;
memory->create(sforce,maxatom,4,"addforce:sforce"); memory->create(sforce,maxatom,4,"addforce:sforce");
} }
@ -371,6 +371,6 @@ double FixAddForce::compute_vector(int n)
double FixAddForce::memory_usage() double FixAddForce::memory_usage()
{ {
double bytes = 0.0; double bytes = 0.0;
if (varflag == ATOM) bytes = atom->nmax*4 * sizeof(double); if (varflag == ATOM) bytes = maxatom*4 * sizeof(double);
return bytes; return bytes;
} }

View File

@ -99,7 +99,7 @@ FixSetForce::FixSetForce(LAMMPS *lmp, int narg, char **arg) :
force_flag = 0; force_flag = 0;
foriginal[0] = foriginal[1] = foriginal[2] = 0.0; foriginal[0] = foriginal[1] = foriginal[2] = 0.0;
maxatom = atom->nmax; maxatom = 1;
memory->create(sforce,maxatom,3,"setforce:sforce"); memory->create(sforce,maxatom,3,"setforce:sforce");
} }
@ -342,6 +342,6 @@ double FixSetForce::compute_vector(int n)
double FixSetForce::memory_usage() double FixSetForce::memory_usage()
{ {
double bytes = 0.0; double bytes = 0.0;
if (varflag == ATOM) bytes = atom->nmax*3 * sizeof(double); if (varflag == ATOM) bytes = maxatom*3 * sizeof(double);
return bytes; return bytes;
} }