diff --git a/src/compute_pair.cpp b/src/compute_pair.cpp index 2786af11fc8d048b9dac80d5defcf7014f92658c..951df069eeac98d430e5aa6e218c95651abe94e0 100644 --- a/src/compute_pair.cpp +++ b/src/compute_pair.cpp @@ -29,7 +29,11 @@ ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) : if (narg != 4) error->all("Illegal compute pair command"); if (igroup) error->all("Compute pair must use group all"); - pair = force->pair_match(arg[3],1); + int n = strlen(arg[3]) + 1; + pstyle = new char[n]; + strcpy(pstyle,arg[3]); + + pair = force->pair_match(pstyle,1); if (!pair) error->all("Unrecognized pair style in compute pair command"); npair = pair->nextra; if (!npair) @@ -51,12 +55,23 @@ ComputePair::ComputePair(LAMMPS *lmp, int narg, char **arg) : ComputePair::~ComputePair() { + delete [] pstyle; delete [] one; delete [] vector; } /* ---------------------------------------------------------------------- */ +void ComputePair::init() +{ + // recheck for pair style in case it has been deleted + + pair = force->pair_match(pstyle,1); + if (!pair) error->all("Unrecognized pair style in compute pair command"); +} + +/* ---------------------------------------------------------------------- */ + void ComputePair::compute_vector() { invoked_vector = update->ntimestep; diff --git a/src/compute_pair.h b/src/compute_pair.h index 4c90bfa9894b514b6c8d895cfafc2032f367165b..3d7d5dccfa99429c8c10bea8648f2031c61bc35c 100644 --- a/src/compute_pair.h +++ b/src/compute_pair.h @@ -28,11 +28,12 @@ class ComputePair : public Compute { public: ComputePair(class LAMMPS *, int, char **); ~ComputePair(); - void init() {} + void init(); void compute_vector(); private: int npair; + char *pstyle; class Pair *pair; double *one; };