diff --git a/src/domain.cpp b/src/domain.cpp index 3f285fd8b0..ba2b5515fe 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -11,6 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + Contributing author (triclinic) : Pieter in 't Veld (SNL) +------------------------------------------------------------------------- */ + #include "mpi.h" #include "stdlib.h" #include "string.h" @@ -645,7 +649,7 @@ void Domain::unmap(double *x, int image) void Domain::set_lattice(int narg, char **arg) { - delete lattice; + if (lattice) delete lattice; lattice = new Lattice(lmp,narg,arg); if (lattice->style == 0) { delete lattice; @@ -661,11 +665,7 @@ void Domain::add_region(int narg, char **arg) { if (narg < 2) error->all("Illegal region command"); - // error checks - - for (int iregion = 0; iregion < nregion; iregion++) - if (strcmp(arg[0],regions[iregion]->id) == 0) - error->all("Reuse of region ID"); + if (find_region(arg[0]) >= 0) error->all("Reuse of region ID"); // extend Region list if necessary @@ -691,6 +691,18 @@ void Domain::add_region(int narg, char **arg) nregion++; } +/* ---------------------------------------------------------------------- + return region index if name matches existing region ID + return -1 if no such region +------------------------------------------------------------------------- */ + +int Domain::find_region(char *name) +{ + for (int iregion = 0; iregion < nregion; iregion++) + if (strcmp(name,regions[iregion]->id) == 0) return iregion; + return -1; +} + /* ---------------------------------------------------------------------- boundary settings from the input script ------------------------------------------------------------------------- */ diff --git a/src/domain.h b/src/domain.h index 0624242ca4..e3ac10c32b 100644 --- a/src/domain.h +++ b/src/domain.h @@ -91,6 +91,7 @@ class Domain : protected Pointers { void minimum_image(double *); void set_lattice(int, char **); void add_region(int, char **); + int find_region(char *); void set_boundary(int, char **); void print_box(char *); diff --git a/src/lattice.cpp b/src/lattice.cpp index 70abc11280..9be04bad73 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -33,6 +33,9 @@ enum{NONE,SC,BCC,FCC,DIAMOND,SQ,SQ2,HEX,CUSTOM}; Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) { + nbasis = 0; + basis = NULL; + // parse style arg if (narg < 1) error->all("Illegal lattice command"); @@ -76,9 +79,6 @@ Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) // x,y,z = fractional coords within unit cell // style CUSTOM will be defined by optional args - nbasis = 0; - basis = NULL; - if (style == SC) { add_basis(0.0,0.0,0.0); } else if (style == BCC) { @@ -158,9 +158,9 @@ Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) } else if (strcmp(arg[iarg],"spacings") == 0) { if (iarg+4 > narg) error->all("Illegal lattice command"); spaceflag = 1; - xlattice = atoi(arg[iarg+1]); - ylattice = atoi(arg[iarg+2]); - zlattice = atoi(arg[iarg+3]); + xlattice = atof(arg[iarg+1]); + ylattice = atof(arg[iarg+2]); + zlattice = atof(arg[iarg+3]); iarg += 4; } else if (strcmp(arg[iarg],"a1") == 0) { diff --git a/src/lattice.h b/src/lattice.h index f34e5474f3..798d41ee36 100644 --- a/src/lattice.h +++ b/src/lattice.h @@ -22,9 +22,11 @@ class Lattice : protected Pointers { public: int style; // enum list of NONE,SC,FCC,etc double xlattice,ylattice,zlattice; // lattice scale factors in 3 dims + double a1[3],a2[3],a3[3]; // vectors that bound unit cell int nbasis; // # of atoms in basis of unit cell double **basis; // fractional coords of each basis atom // within unit cell (0 <= coord < 1) + Lattice(class LAMMPS *, int, char **); ~Lattice(); void lattice2box(double &, double &, double &); @@ -38,7 +40,6 @@ private: int orientx[3]; // lattice orientation vecs int orienty[3]; // orientx = what lattice dir lies int orientz[3]; // along x dim in box - double a1[3],a2[3],a3[3]; // vectors that bound unit cell double primitive[3][3]; // lattice <-> box transform matrices double priminv[3][3];