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

This commit is contained in:
sjplimp 2013-01-18 20:46:51 +00:00
parent 2d6d2de507
commit 746deead15
3 changed files with 85 additions and 15 deletions

View File

@ -15,12 +15,16 @@
#include "stdlib.h"
#include "string.h"
#include "region_cylinder.h"
#include "update.h"
#include "domain.h"
#include "input.h"
#include "variable.h"
#include "error.h"
using namespace LAMMPS_NS;
#define BIG 1.0e20
enum{CONSTANT,VARIABLE};
/* ---------------------------------------------------------------------- */
@ -36,15 +40,29 @@ RegCylinder::RegCylinder(LAMMPS *lmp, int narg, char **arg) :
if (axis == 'x') {
c1 = yscale*atof(arg[3]);
c2 = zscale*atof(arg[4]);
radius = yscale*atof(arg[5]);
} else if (axis == 'y') {
c1 = xscale*atof(arg[3]);
c2 = zscale*atof(arg[4]);
radius = xscale*atof(arg[5]);
} else if (axis == 'z') {
c1 = xscale*atof(arg[3]);
c2 = yscale*atof(arg[4]);
radius = xscale*atof(arg[5]);
}
rstr = NULL;
if (strstr(arg[5],"v_") == arg[5]) {
int n = strlen(&arg[5][2]) + 1;
rstr = new char[n];
strcpy(rstr,&arg[5][2]);
radius = 0.0;
rstyle = VARIABLE;
varshape = 1;
variable_check();
shape_update();
} else {
radius = atof(arg[5]);
if (axis == 'x') radius *= xscale;
else radius *= xscale;
rstyle = CONSTANT;
}
if (strcmp(arg[6],"INF") == 0 || strcmp(arg[6],"EDGE") == 0) {
@ -100,6 +118,7 @@ RegCylinder::RegCylinder(LAMMPS *lmp, int narg, char **arg) :
if (radius <= 0.0) error->all(FLERR,"Illegal region cylinder command");
// extent of cylinder
// for variable radius, uses initial radius
if (interior) {
bboxflag = 1;
@ -139,9 +158,18 @@ RegCylinder::RegCylinder(LAMMPS *lmp, int narg, char **arg) :
RegCylinder::~RegCylinder()
{
delete [] rstr;
delete [] contact;
}
/* ---------------------------------------------------------------------- */
void RegCylinder::init()
{
Region::init();
if (rstr) variable_check();
}
/* ----------------------------------------------------------------------
inside = 1 if x,y,z is inside or on surface
inside = 0 if x,y,z is outside and not on surface
@ -400,3 +428,29 @@ int RegCylinder::surface_exterior(double *x, double cutoff)
return 0;
}
}
/* ----------------------------------------------------------------------
change region shape via variable evaluation
------------------------------------------------------------------------- */
void RegCylinder::shape_update()
{
radius = input->variable->compute_equal(rvar);
if (radius < 0.0)
error->one(FLERR,"Variable evaluation in region gave bad value");
if (axis == 'x') radius *= xscale;
else radius *= xscale;
}
/* ----------------------------------------------------------------------
error check on existence of variable
------------------------------------------------------------------------- */
void RegCylinder::variable_check()
{
rvar = input->variable->find(rstr);
if (rvar < 0)
error->all(FLERR,"Variable name for region cylinder does not exist");
if (!input->variable->equalstyle(rvar))
error->all(FLERR,"Variable for region cylinder is invalid style");
}

View File

@ -30,15 +30,22 @@ class RegCylinder : public Region {
public:
RegCylinder(class LAMMPS *, int, char **);
~RegCylinder();
void init();
int inside(double, double, double);
int surface_interior(double *, double);
int surface_exterior(double *, double);
void shape_update();
private:
char axis;
double c1,c2;
double radius;
double lo,hi;
int rstyle,rvar;
char *rstr;
void variable_check();
};
}

View File

@ -15,9 +15,9 @@
#include "stdlib.h"
#include "string.h"
#include "region_sphere.h"
#include "update.h"
#include "input.h"
#include "variable.h"
#include "update.h"
#include "error.h"
using namespace LAMMPS_NS;
@ -43,14 +43,19 @@ RegSphere::RegSphere(LAMMPS *lmp, int narg, char **arg) :
radius = 0.0;
rstyle = VARIABLE;
varshape = 1;
variable_check();
shape_update();
} else {
radius = xscale*atof(arg[5]);
rstyle = CONSTANT;
}
// error check
if (radius < 0.0) error->all(FLERR,"Illegal region sphere command");
// extent of sphere, will be 0.0 for variable radius
// extent of sphere
// for variable radius, uses initial radius
if (interior) {
bboxflag = 1;
@ -79,16 +84,7 @@ RegSphere::~RegSphere()
void RegSphere::init()
{
Region::init();
// check variable
if (rstr) {
rvar = input->variable->find(rstr);
if (rvar < 0)
error->all(FLERR,"Variable name for region sphere does not exist");
if (!input->variable->equalstyle(rvar))
error->all(FLERR,"Variable for region sphere is invalid style");
}
if (rstr) variable_check();
}
/* ----------------------------------------------------------------------
@ -168,3 +164,16 @@ void RegSphere::shape_update()
if (radius < 0.0)
error->one(FLERR,"Variable evaluation in region gave bad value");
}
/* ----------------------------------------------------------------------
error check on existence of variable
------------------------------------------------------------------------- */
void RegSphere::variable_check()
{
rvar = input->variable->find(rstr);
if (rvar < 0)
error->all(FLERR,"Variable name for region sphere does not exist");
if (!input->variable->equalstyle(rvar))
error->all(FLERR,"Variable for region sphere is invalid style");
}