diff --git a/src/compute_reduce.cpp b/src/compute_reduce.cpp index dcceb1ac5e..6b34f3c6dd 100644 --- a/src/compute_reduce.cpp +++ b/src/compute_reduce.cpp @@ -50,11 +50,16 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) : int iarg; if (strcmp(style,"reduce") == 0) { if (narg < 5) error->all("Illegal compute reduce command"); + idregion = NULL; iarg = 3; } else if (strcmp(style,"reduce/region") == 0) { if (narg < 6) error->all("Illegal compute reduce/region command"); iregion = domain->find_region(arg[3]); - if (iregion == -1) error->all("Compute reduce region ID does not exist"); + if (iregion == -1) + error->all("Region ID for compute reduce/region does not exist"); + int n = strlen(arg[3]) + 1; + idregion = new char[n]; + strcpy(idregion,arg[3]); iarg = 4; } @@ -281,6 +286,7 @@ ComputeReduce::~ComputeReduce() delete [] ids; delete [] value2index; delete [] replace; + delete [] idregion; delete [] vector; delete [] onevec; @@ -317,6 +323,12 @@ void ComputeReduce::init() } else value2index[m] = -1; } + + // set index and check validity of region + + iregion = domain->find_region(idregion); + if (iregion == -1) + error->all("Region ID for compute reduce/region does not exist"); } /* ---------------------------------------------------------------------- */ diff --git a/src/compute_reduce.h b/src/compute_reduce.h index 02f39748e6..49242c04bd 100644 --- a/src/compute_reduce.h +++ b/src/compute_reduce.h @@ -41,6 +41,7 @@ class ComputeReduce : public Compute { double *onevec; int *replace,*indices,*owner; int index; + char *idregion; int maxatom; double *varatom; diff --git a/src/compute_temp_region.cpp b/src/compute_temp_region.cpp index 03fabcda0f..f1d43f83e5 100644 --- a/src/compute_temp_region.cpp +++ b/src/compute_temp_region.cpp @@ -33,7 +33,11 @@ ComputeTempRegion::ComputeTempRegion(LAMMPS *lmp, int narg, char **arg) : if (narg != 4) error->all("Illegal compute temp/region command"); iregion = domain->find_region(arg[3]); - if (iregion == -1) error->all("Temperature region ID does not exist"); + if (iregion == -1) + error->all("Region ID for compute temp/region does not exist"); + int n = strlen(arg[3]) + 1; + idregion = new char[n]; + strcpy(idregion,arg[3]); scalar_flag = vector_flag = 1; size_vector = 6; @@ -51,6 +55,7 @@ ComputeTempRegion::ComputeTempRegion(LAMMPS *lmp, int narg, char **arg) : ComputeTempRegion::~ComputeTempRegion() { + delete [] idregion; memory->destroy_2d_double_array(vbiasall); delete [] vector; } @@ -59,6 +64,12 @@ ComputeTempRegion::~ComputeTempRegion() void ComputeTempRegion::init() { + // set index and check validity of region + + iregion = domain->find_region(idregion); + if (iregion == -1) + error->all("Region ID for temp reduce/region does not exist"); + dof = 0.0; } diff --git a/src/compute_temp_region.h b/src/compute_temp_region.h index 74b738db8e..7c2f7e9b43 100644 --- a/src/compute_temp_region.h +++ b/src/compute_temp_region.h @@ -41,6 +41,7 @@ class ComputeTempRegion : public Compute { private: int iregion; + char *idregion; }; } diff --git a/src/domain.cpp b/src/domain.cpp index cac94415d1..84464925fd 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -863,13 +863,18 @@ void Domain::set_lattice(int narg, char **arg) } /* ---------------------------------------------------------------------- - create a new region + create a new region ------------------------------------------------------------------------- */ void Domain::add_region(int narg, char **arg) { if (narg < 2) error->all("Illegal region command"); + if (strcmp(arg[1],"delete") == 0) { + delete_region(narg,arg); + return; + } + if (find_region(arg[0]) >= 0) error->all("Reuse of region ID"); // extend Region list if necessary @@ -896,6 +901,21 @@ void Domain::add_region(int narg, char **arg) nregion++; } +/* ---------------------------------------------------------------------- + delete a region +------------------------------------------------------------------------- */ + +void Domain::delete_region(int narg, char **arg) +{ + if (narg != 2) error->all("Illegal region command"); + + int iregion = find_region(arg[0]); + if (iregion == -1) error->all("Delete region ID does not exist"); + + regions[iregion] = regions[nregion-1]; + nregion--; +} + /* ---------------------------------------------------------------------- return region index if name matches existing region ID return -1 if no such region diff --git a/src/domain.h b/src/domain.h index 5a2b8eae8b..dd2c004a8a 100644 --- a/src/domain.h +++ b/src/domain.h @@ -101,6 +101,7 @@ class Domain : protected Pointers { void minimum_image(double *); void set_lattice(int, char **); void add_region(int, char **); + void delete_region(int, char **); int find_region(char *); void set_boundary(int, char **); void print_box(const char *); diff --git a/src/dump_cfg.cpp b/src/dump_cfg.cpp index ef217bae43..43548f364c 100755 --- a/src/dump_cfg.cpp +++ b/src/dump_cfg.cpp @@ -180,6 +180,13 @@ void DumpCFG::init() if (ivariable < 0) error->all("Could not find dump cfg variable name"); variable[i] = ivariable; } + + // set index and check validity of region + + if (iregion >= 0) { + iregion = domain->find_region(idregion); + if (iregion == -1) error->all("Region ID for dump cfg does not exist"); + } } /* ---------------------------------------------------------------------- */ diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index 1a75354af0..0ec1b1c94d 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -60,6 +60,7 @@ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) : vtype = new int[nfield]; iregion = -1; + idregion = NULL; nthresh = 0; thresh_array = NULL; thresh_op = NULL; @@ -127,6 +128,7 @@ DumpCustom::~DumpCustom() memory->sfree(field2index); memory->sfree(argindex); + delete [] idregion; memory->sfree(thresh_array); memory->sfree(thresh_op); memory->sfree(thresh_value); @@ -1143,6 +1145,9 @@ int DumpCustom::modify_param(int narg, char **arg) else { iregion = domain->find_region(arg[1]); if (iregion == -1) error->all("Dump_modify region ID does not exist"); + int n = strlen(arg[1]) + 1; + idregion = new char[n]; + strcpy(idregion,arg[1]); } return 2; diff --git a/src/dump_custom.h b/src/dump_custom.h index 505fa43ac9..4cdea81412 100644 --- a/src/dump_custom.h +++ b/src/dump_custom.h @@ -34,6 +34,7 @@ class DumpCustom : public Dump { protected: int nevery; // dump frequency to check Fix against int iregion; // -1 if no region, else which region + char *idregion; // region ID int nthresh; // # of defined threshholds int *thresh_array; // array to threshhhold on for each nthresh int *thresh_op; // threshhold operation for each nthresh